clear
clc
x=[50 100 150 200 250 300 350 400 450 500];
y=[40 80 120 160 200];
z=[0.05 0.05 0.05 0.05 0.05
0.25 0.15 0.11 0.05 0.05
0.5 0.2 0.2 0.04 0.04
1.6 1 0.5 0.11 0.07
2.5 2.4 1.14 0.34 0.12
3.2 2.7 1.54 0.7 0.21
3.4 3.1 2.1 1.15 0.3
3.75 3.5 2.56 1.4 0.6
4 3.8 2.95 2 0.9
4.2 4 3.2 2.2 1.1];
[y,x]=meshgrid(y,x);
p=[x(:),y(:),ones(numel(z),1)]\z(:)%p=[a;b;c]
plot3(x(:),y(:),z(:),'ro');
hold on;grid on
mesh(x,y,p(1)*x+p(2)*y+p(3))
clear;
clc;
x = [50 100 150 200 250 300 350 400 450 500];
y = [40 80 120 160 200];
[myx,myy] = meshgrid(x,y);
z = [0.05 0.05 0.05 0.05 0.05
0.25 0.15 0.11 0.05 0.05
0.5 0.2 0.2 0.04 0.04
1.6 1 0.5 0.11 0.07
2.5 2.4 1.14 0.34 0.12
3.2 2.7 1.54 0.7 0.21
3.4 3.1 2.1 1.15 0.3
3.75 3.5 2.56 1.4 0.6
4 3.8 2.95 2 0.9
4.2 4 3.2 2.2 1.1];
cxd_1 = reshape(myx',50,1);
cxd_2 = reshape(myy',50,1);
cxd_3 = ones(50,1);
cxd_X = [cxd_1 cxd_2 cxd_3];
cxd_Y = z(:);
myb = regress(cxd_Y,cxd_X);
a = myb(1)
b = myb(2)
c = myb(3)
结果:
a =
0.0072
b =
-0.0132
c =
1.0057
copyright (c) by cxd1301