怎样使用matlab,利用最小二乘法得到回归方程影响结果的变量分别为x1,x2,x3,结果变量为y.x1=[0.4,0.4,0.4,0.4,0.2,0.2,0.2,0.2,0.4,0.4,0.4,0.4,0.2,0.2,0.2,0.2,0.3,0.3,0.1,0.5,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3];x2=[0.0
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/18 04:29:00
怎样使用matlab,利用最小二乘法得到回归方程影响结果的变量分别为x1,x2,x3,结果变量为y.x1=[0.4,0.4,0.4,0.4,0.2,0.2,0.2,0.2,0.4,0.4,0.4,0.4,0.2,0.2,0.2,0.2,0.3,0.3,0.1,0.5,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3];x2=[0.0
怎样使用matlab,利用最小二乘法得到回归方程
影响结果的变量分别为x1,x2,x3,结果变量为y.
x1=[0.4,0.4,0.4,0.4,0.2,0.2,0.2,0.2,0.4,0.4,0.4,0.4,0.2,0.2,0.2,0.2,0.3,0.3,0.1,0.5,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3];
x2=[0.08,0.08,0.04,0.04,0.08,0.08,0.04,0.04,0.08,0.08,0.04,0.04,0.08,0.08,0.04,0.04,0.06,0.06,0.06,0.06,0.02,0.1,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.06];
x3=[350,250,350,250,350,250,350,250,350,250,350,250,350,250,350,250,300,300,300,300,300,300,200,400,300,300,300,300,300,300,300];
y=[0.99539,1.0313,0.88595,0.92168,0.30154,0.32745,0.21272,0.24863,0.94551,0.96347,0.95656,0.97452,0.20773,0.21549,0.20928,0.23716,0.48393,0.53528,0.18166,1.56209,0.48072,0.54849,0.54154,0.48767,0.50432,0.52464,0.52637,0.51482,0.50425,0.50603,0.51446];
最后求的回归方程为
matlab的代码怎么写啊?
怎样使用matlab,利用最小二乘法得到回归方程影响结果的变量分别为x1,x2,x3,结果变量为y.x1=[0.4,0.4,0.4,0.4,0.2,0.2,0.2,0.2,0.4,0.4,0.4,0.4,0.2,0.2,0.2,0.2,0.3,0.3,0.1,0.5,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3];x2=[0.0
定义函数文件myfun.m
function yhat = myfun(beta,x)
b1 = beta(1);
b2 = beta(2);
b3 = beta(3);
b4 = beta(4);
b5 = beta(5);
b6 = beta(6);
b7 = beta(7);
b8 = beta(8);
b9 = beta(9);
b10 = beta(10);
x1 = x(:,1);
x2 = x(:,2);
x3 = x(:,3);
yhat = b1+b2*x1+b3*x2+b4*x3+b5*x1.*x2+b6*x2.*x3+b7*x1.*x3+b8*x1.^2+b9*x2.^2+b10*x3.^2;
在命令窗口输入
x1=[0.4,0.4,0.4,0.4,0.2,0.2,0.2,0.2,0.4,0.4,0.4,0.4,0.2,0.2,0.2,0.2,0.3,0.3,0.1,0.5,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3];
x2=[0.08,0.08,0.04,0.04,0.08,0.08,0.04,0.04,0.08,0.08,0.04,0.04,0.08,0.08,0.04,0.04,0.06,0.06,0.06,0.06,0.02,0.1,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.06,0.06];
x3=[350,250,350,250,350,250,350,250,350,250,350,250,350,250,350,250,300,300,300,300,300,300,200,400,300,300,300,300,300,300,300];
y=[0.99539,1.0313,0.88595,0.92168,0.30154,0.32745,0.21272,0.24863,0.94551,0.96347,0.95656,0.97452,0.20773,0.21549,0.20928,0.23716,0.48393,0.53528,0.18166,1.56209,0.48072,0.54849,0.54154,0.48767,0.50432,0.52464,0.52637,0.51482,0.50425,0.50603,0.51446];
x=[x1' x2' x3'];
y=y';
beta = nlinfit(x,y,@myfun,ones(1,10))