非线性多元拟合-多参数。

5 vues (au cours des 30 derniers jours)
果搏东方在线【gb2032 .com】
求解的是多元非线性拟合参数的问题。问题是,两个自变量,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

果博厅注册网址【gb9905 .com】
你这个模型将核心抽出来,实际上就是a*sin(X1)*cos(X2-b),所以我认为你的模型是有问题的。
即便按照你的逻辑,你的函数也应该写成
function f=cf(x,xdata);
    X1=xdata(:,1);
    X2=xdata(:,2);
    f=x(1)/x(2)*((1-x(2)/6)*sin(X1).*cos(X2-x(3)))
end

Plus de réponses (0)

Catégories

En savoir plus sur Legend dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!