作业帮 > 综合 > 作业

matlab编程运行后出错

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/03 10:50:54
matlab编程运行后出错
M文件如下:
function f=myfun0022(p,xdata)
x1=xdata(:,:,1)
x2=xdata(:,:,2)
f=1-(p(1)+p(2)*x2).*cos(x2).*exp(p(3)*x1)
命令窗口:
x1=[0.25 0.5 0.75 1 2 3 4 5 7.5];
x=[1 5 10 20 30 50 60 70 85];
x2=x.*pi/180;
Y=[0.619 0.694 0.601 0.541 0.526 0.504 0.497 0.513 0.547
0.620 0.642 0.577 0.538 0.506 0.509 0.519 0.532 0.570
0.579 0.553 0.519 0.498 0.498 0.509 0.521 0.532 0.568
0.289 0.446 0.482 0.490 0.523 0.540 0.556 0.567 0.614
0.655 0.497 0.524 0.537 0.582 0.603 0.621 0.640 0.684
0.945 0.837 0.831 0.834 0.853 0.869 0.881 0.886 0.912
0.976 0.906 0.907 0.912 0.931 0.942 0.960 0.964 0.974
0.981 0.929 0.954 0.964 0.989 1.001 1.008 1.004 1.011
1.007 0.973 0.960 0.982 0.998 1.030 1.041 1.036 1.043];
[xx1,xx2]=meshgrid(x1,x2);
X=cat(3,xx1,xx2);
[p,res,c]=lsqcurvefit(@myfun0022,ones(1,3),X,Y);
surf(myfun0022(p,X))
hold on
surf(Y)
p
运行后出现:
Error using ==> feval
Undefined function or method 'myfun0022' for input arguments of type 'double'.
Error in ==> lsqcurvefit at 209
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation.LSQCURVEFIT
cannot continue.
感激不尽·········
我运行了一下,没有错误提示啊?
你的myfun0022函数是不是名字不是myfun0022.m?
或者是myfun0022.m的位置不是当前的路径啊,把myfun0022.m存放到当前的工具栏中“current directory”后的框中所显示的文件夹中.