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#
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:
function NLregression(x,y,beta0)
[beta,r ,J]=nlinfit(x,y,@exponen,beta0);
[YY,delta]=nlpredci(@exponen,x,beta,r ,J);
plot(x,y,
end
function yhat=exponen(beta,x)
yhat=beta(1)*exp(beta(2)./x);
end
so is there some kind person who can help me ?