展开全部
已知x1={104020 104040 102900 103310 95855 98998 104174 99824 97708 100133 96785}
x2={31.206 31.213 30.87 30.994 28.757 29.699 31.251 29.947 29.312 30.04 29.035}
x3={83.216 83.234 82.319 82.651 76.684 79.198 83.335 79.859 78.166 80.105 77.428}
Y={26.676 26.953 26.103 26.152 28.318 26.879 27.413 27.886 27.736 26.452 27.957}
怎么用matlab拟合出f(x1,x2,x3)来
模型选为:y=b0+b1*x1+b2*x2+b3*x3。代码:
X0=ones(11,1);
X1=[104020 104040 102900 103310 95855 98998 104174 99824 97708 100133 96785]';
X2=[31.206 31.213 30.87 30.994 28.757 29.699 31.251 29.947 29.312 30.04 29.035]';
X3=[83.216 83.234 82.319 82.651 76.684 79.198 83.335 79.859 78.166 80.105 77.428]';
X=[X0 X1 X2 X3];
Y=[26.676 26.953 26.103 26.152 28.318 26.879 27.413 27.886 27.736 26.452 27.957];
[b,bint,r,rint,stats]=regress(Y,X)
其中,b输出一个向量,分别是b0 b1 b2 b3的值。代入模型即可。M文件:
function f= fun(c,x)
f= ((c(1)+c(2)*x+x.^2)-((c(1)+c(2)*x.^2).^2-4*x.^2).^0.5)/(2*x.^2)
在窗口中输入的文件:
b=[3.5026 4.2031 4.9035 5.604 6.3045 7.005 2.2378 2.6852 3.1328 3.5803 4.0278 4.4753;0.07331 0.0523 0.03932 0.0306 0.02446 0.01982 0.18063 0.12797 0.0954 0.07374 0.05875 0.04788];
a=b';
x=a(:,1);
y=a(:,2);
c0=[1,1]';
[c,resnorm]=lsqcurvefit(@fun,c0,x,y)
运行后:
??? Error using ==> d:/matlab6p5/toolbox/optim/private/lsqncommon
Function value and YDATA sizes are incommensurate.
Error in ==> D:\MATLAB6p5\toolbox\optim\lsqcurvefit.m
On line 129 ==> [x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...xdata=[14.9,0.8;13.6,0.62;13.6,0.98;16.2,0.98;16.2,0.62];
ydata=[111729.4346 111742.47 111742.4947 111738.3368 111738.2256];
x0=[1:5];
F=@(x,xdata)x(1)+x(2)*xdata(:,1)+x(3)*xdata(:,1).^2+x(4)*xdata(:,2)+x(5)*xdata(:,2).^2;
[x,resnorm]=lsqcurvefit(F,x0,xdata,ydata')
Solver stopped prematurely.
lsqcurvefit stopped because it exceeded the function evaluation limit,
options.MaxFunEvals = 500 (the default value).
x =
1.0e+004 *
0.9826 1.4089 -0.0473 -0.6467 0.4078
resnorm =
3.6801e+005
x2={31.206 31.213 30.87 30.994 28.757 29.699 31.251 29.947 29.312 30.04 29.035}
x3={83.216 83.234 82.319 82.651 76.684 79.198 83.335 79.859 78.166 80.105 77.428}
Y={26.676 26.953 26.103 26.152 28.318 26.879 27.413 27.886 27.736 26.452 27.957}
怎么用matlab拟合出f(x1,x2,x3)来
模型选为:y=b0+b1*x1+b2*x2+b3*x3。代码:
X0=ones(11,1);
X1=[104020 104040 102900 103310 95855 98998 104174 99824 97708 100133 96785]';
X2=[31.206 31.213 30.87 30.994 28.757 29.699 31.251 29.947 29.312 30.04 29.035]';
X3=[83.216 83.234 82.319 82.651 76.684 79.198 83.335 79.859 78.166 80.105 77.428]';
X=[X0 X1 X2 X3];
Y=[26.676 26.953 26.103 26.152 28.318 26.879 27.413 27.886 27.736 26.452 27.957];
[b,bint,r,rint,stats]=regress(Y,X)
其中,b输出一个向量,分别是b0 b1 b2 b3的值。代入模型即可。M文件:
function f= fun(c,x)
f= ((c(1)+c(2)*x+x.^2)-((c(1)+c(2)*x.^2).^2-4*x.^2).^0.5)/(2*x.^2)
在窗口中输入的文件:
b=[3.5026 4.2031 4.9035 5.604 6.3045 7.005 2.2378 2.6852 3.1328 3.5803 4.0278 4.4753;0.07331 0.0523 0.03932 0.0306 0.02446 0.01982 0.18063 0.12797 0.0954 0.07374 0.05875 0.04788];
a=b';
x=a(:,1);
y=a(:,2);
c0=[1,1]';
[c,resnorm]=lsqcurvefit(@fun,c0,x,y)
运行后:
??? Error using ==> d:/matlab6p5/toolbox/optim/private/lsqncommon
Function value and YDATA sizes are incommensurate.
Error in ==> D:\MATLAB6p5\toolbox\optim\lsqcurvefit.m
On line 129 ==> [x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...xdata=[14.9,0.8;13.6,0.62;13.6,0.98;16.2,0.98;16.2,0.62];
ydata=[111729.4346 111742.47 111742.4947 111738.3368 111738.2256];
x0=[1:5];
F=@(x,xdata)x(1)+x(2)*xdata(:,1)+x(3)*xdata(:,1).^2+x(4)*xdata(:,2)+x(5)*xdata(:,2).^2;
[x,resnorm]=lsqcurvefit(F,x0,xdata,ydata')
Solver stopped prematurely.
lsqcurvefit stopped because it exceeded the function evaluation limit,
options.MaxFunEvals = 500 (the default value).
x =
1.0e+004 *
0.9826 1.4089 -0.0473 -0.6467 0.4078
resnorm =
3.6801e+005
展开全部
1、因为这个函数的形式比较特殊对其两边取对数后得到 log(y)=log(a)+b*log(x1)+c*log(x2)
2、于是立即就转换为了线性拟合 [1 log(x1) log(x2)]*[log(a) b c]'=log(y)
3、于是[log(a) b c]'=[1 log(x1) log(x2)]\log(y) 这样就可以得到a,b,c了。不需要进行非线性拟合。
4、我想拟合出一个公式 y=F(t1,t2),当有任意t1、t2值时,可计算出纵坐标。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询