Afficher commentaires plus anciens
求解的是多元非线性拟合参数的问题。问题是,两个自变量,1个因变量(3组数据),以及3个参数x(1),x(2),x(3).
函数表达式已知:f(i)=x(1)/x(2)*((1-x(2)/6)*sin(X1(i)).*cos(X2(i)-x(3)))
我建立的.mfunction f=cf(x,xdata);
xdata=[X1,X2];
n=length(xdata);
for i=1:n;
f(i)=x(1)/x(2)*((1-x(2)/6)*sin(X1(i)).*cos(X2(i)-x(3)))
end
主程序:
clear all;close all;
X1=[60,78,75,80,45,56,77]';
X2=[92,88,130,276,108,320,256]';
xdata=[X1,X2];
ydata=[3,4.4,5.9,8.0,6.5,3.7,4.8]
x0=[90,3.5,100]';
[x,resnorm]=lsqcurvefit('cf',x0,[5,1,0],[200,6,360],xdata,ydata)
options=optimset('lsqcurvefit')
x0=x;%以计算出的a值为初值进行迭代
plot(xdata,ydata,'ro');
xi=0:0.01:1;
y=cf(x,[X1(i),X2(i)]);
r=cf(x,[X1(i),X2(i)])-Y;%维度需要一致
e=r*r'
grid on;hold on;
plot(xi,y)
xlabel('x')
ylabel('y')
title('lsqcurvefit函数曲线拟合')
legend('原始数据点','拟合曲线')
大家帮我看下,为啥老提示出不了结果,以及如何出三维图啊。
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Legend dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!