matlab的fsolve函数
我在vc中通过matcom调用fsolve函数,可是屡试不爽,望高人赐教!
//c++程序如下
{
initM(MATCOM_VERSION);
Mm f;
Mm x0;
Mm fun;
x0=zeros(2,1);
x0.r(1,1)=0.5;
x0.r(2,1)=0.5;
f=zeros(2,1);
double x,y;
fun=zeros(2,1);
fun.r(1,1)=x-0.6*sin(x)-0.3*cos(y);
fun.r(2,1)=y-0.6*cos(x)+0.3*sin(y);
f=fsolve(fun,x0);
display(f);
exitM();
}
运行结果是error: feval was not link with the program
另试一个例子如下
initM(MATCOM_VERSION);
Mm x;
Mm x0;
Mm fun;
fun=sin(3*x);
x0.r(1,1)=1;
x0.r(2,1)=4;
x=fsolve(fun,x0);
int n;
n=x.cols();
double data[10];
for(int i=0;i<n;i++)
{
data[i]=x.r(i+1,1);
printf("x(%d)=%f\n",i+1,data[i]);
}
exitM();
运行结果 row=1 or cols=1 out of matrix
我是最近刚接触matlab,不明白的请大家多多指教。