Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Rencently I compiled C# program to call the matlab COM called NLregression1 which compiled by myself to solve the problem of nolinear regression of data.I used the matlab function as follow:nlinfit,nlpredci and exponen which is used in the nlinfit, when the program to run ,there always is errors:nlinfit at 120 ; error evaluating model function'exponen'; error in =>NLregressionP1.m at 25.
But I run the matlab program NLregression only ,it run well in matlab. the code as below:
c#
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NLregression1;

namespace nlreg2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double[] y = { -0.5, -0.1, -0.2, 0, 0.1, 0.4, 1, 0.2, 0.1 };
            int[] x = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            int[] beta0 = { 2, 8 };
           NLregression1Class nl = new NLregression1Class ();
            object obj_x = (object)x;
            object obj_y = (object)y;
            object obj_beta0 = (object)beta0;
            try
            {
                nl.NLregression(obj_x, obj_y, obj_beta0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

matlab:
VB
function NLregression(x,y,beta0)
[beta,r ,J]=nlinfit(x,y,@exponen,beta0);
[YY,delta]=nlpredci(@exponen,x,beta,r ,J);
plot(x,y,'k+',x,YY,'r')
end

 function yhat=exponen(beta,x)
      yhat=beta(1)*exp(beta(2)./x);
 end

so is there some kind person who can help me ?
Posted
Updated 22-May-10 19:35pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900