clear
x=[1,1;2,2;-1,-2;0,-1;3,6]
y=[10;23;-8;-3;19]
a=[0.5 0.5 0.5 0.5 0.5]
f=@(x,y)a(1)+a(2)*x(:,1)+a(3)*x(:,2)+a(4)*x(:,1)*x(:,2)+a(5)*x(:,1)^2;
nlinfit(x,y,f,[0.5 0.5 0.5 0.5 0.5])
结果
??? Error using ==> nlinfit at 127
MODELFUN should return a vector of fitted values the same length
as Y.
我想控制误差在10^(-4),请问这个用循环语句还是有误差函数可以用?
还有请问如果想学好MATLAB做数据处理有没有什么资料可以推荐的?谢谢了
nlinfit是可以控制误差的
在使用nlinfit之前,用statset设置好参数,再调用nlinfit就好了
options = statset('TolFun',1e-4);
nlinfit(x,y,f,[0.5 0.5 0.5 0.5 0.5],options);
除了误差,其实还有很多拟合参数可以设置,具体要看statset的帮助
资料肯定是有的,不过我没有找,我基本上是看matlab自带的帮助文件的
所以不能给你推荐了