如何利用matlab拟合?
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/11/06 04:54:34
如何利用matlab拟合?
x=[503808.4 503793.6 503793.7 503793.7 503793.7 503793.8 503779.2 503779.2 503779.2 503779.2];
>> y=[647086.5 647093.0 647107.9 647122.7 647137.1 647152.5 647160.6 647146.1 647145.3 647136.1];
>> z=[150.786 150.99 151.136 151.655 151.444 151.053 150.241 150.59 150.36 150.363];
>> z=a0+a1*x+a2*y+a3*x^2+a4*x*y+a5*y^2
如何求a0,a1,a2,a3,a4,a5
x=[503808.4 503793.6 503793.7 503793.7 503793.7 503793.8 503779.2 503779.2 503779.2 503779.2];
>> y=[647086.5 647093.0 647107.9 647122.7 647137.1 647152.5 647160.6 647146.1 647145.3 647136.1];
>> z=[150.786 150.99 151.136 151.655 151.444 151.053 150.241 150.59 150.36 150.363];
>> z=a0+a1*x+a2*y+a3*x^2+a4*x*y+a5*y^2
如何求a0,a1,a2,a3,a4,a5
clear;clc;
x=[503808.4 503793.6 503793.7 503793.7 503793.7 503793.8 503779.2 503779.2 503779.2 503779.2];
y=[647086.5 647093.0 647107.9 647122.7 647137.1 647152.5 647160.6 647146.1 647145.3 647136.1];
z=[150.786 150.99 151.136 151.655 151.444 151.053 150.241 150.59 150.36 150.363];
f1=@(x,y,p)(p(1)+p(2)*x+p(3)*y+p(4)*x.^2+p(5)*x.*y+p(6)*y.^2);
f2=@(p)(sum((f1(x,y,p)-z).^2));
fun=f2(sym('[p1 p2 p3 p4 p5 p6]'));
[p1 p2 p3 p4 p5 p6]=solve(diff(fun,'p1'),diff(fun,'p2'),diff(fun,'p3'),diff(fun,'p4'),diff(fun,'p5'),diff(fun,'p6'));
a=vpa([p1 p2 p3 p4 p5 p6],5)%这就是你要求的a0到a5
p=double([p1 p2 p3 p4 p5 p6]);
f=@(x,y)(f1(x,y,p));
plot3(x,y,z,'o');hold on;
ezsurf(f,[503770,503810,647080,647170])
shading interp;alpha(.5);hold off;
x=[503808.4 503793.6 503793.7 503793.7 503793.7 503793.8 503779.2 503779.2 503779.2 503779.2];
y=[647086.5 647093.0 647107.9 647122.7 647137.1 647152.5 647160.6 647146.1 647145.3 647136.1];
z=[150.786 150.99 151.136 151.655 151.444 151.053 150.241 150.59 150.36 150.363];
f1=@(x,y,p)(p(1)+p(2)*x+p(3)*y+p(4)*x.^2+p(5)*x.*y+p(6)*y.^2);
f2=@(p)(sum((f1(x,y,p)-z).^2));
fun=f2(sym('[p1 p2 p3 p4 p5 p6]'));
[p1 p2 p3 p4 p5 p6]=solve(diff(fun,'p1'),diff(fun,'p2'),diff(fun,'p3'),diff(fun,'p4'),diff(fun,'p5'),diff(fun,'p6'));
a=vpa([p1 p2 p3 p4 p5 p6],5)%这就是你要求的a0到a5
p=double([p1 p2 p3 p4 p5 p6]);
f=@(x,y)(f1(x,y,p));
plot3(x,y,z,'o');hold on;
ezsurf(f,[503770,503810,647080,647170])
shading interp;alpha(.5);hold off;