MATLAB多变量拟合
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/10 16:28:48
MATLAB多变量拟合
y=[-1.553 -1.06 -0.879 -1.032 -1.081 -1.066 -0.893 -0.928 -1.222],
X =
-1.0000 -9.0000 4.8120
-0.8240 -2.6990 4.6680
-0.6990 -2.5230 4.4680
-0.6990 -9.0000 4.6920
-1.0000 -2.6990 4.5830
-0.8240 -2.5230 4.8360
-0.8240 -9.0000 4.6270
-0.6990 -2.6990 4.8700
-1.0000 -2.5230 4.7260
拟合方程为y=a0+a1*x1+a2*x2+a3*x3,其中,a0、a1、a2、a3为参数.
运用regress函数进行拟合,[b,bint,r,rint,stats]=regress (y,X),但是运行出现以下错误,希望指点下,matlab新手.
Error using ==> or
Matrix dimensions must agree.
Error in ==> regress at 70
wasnan = (isnan(y) | any(isnan(X),2));
y=[-1.553 -1.06 -0.879 -1.032 -1.081 -1.066 -0.893 -0.928 -1.222],
X =
-1.0000 -9.0000 4.8120
-0.8240 -2.6990 4.6680
-0.6990 -2.5230 4.4680
-0.6990 -9.0000 4.6920
-1.0000 -2.6990 4.5830
-0.8240 -2.5230 4.8360
-0.8240 -9.0000 4.6270
-0.6990 -2.6990 4.8700
-1.0000 -2.5230 4.7260
拟合方程为y=a0+a1*x1+a2*x2+a3*x3,其中,a0、a1、a2、a3为参数.
运用regress函数进行拟合,[b,bint,r,rint,stats]=regress (y,X),但是运行出现以下错误,希望指点下,matlab新手.
Error using ==> or
Matrix dimensions must agree.
Error in ==> regress at 70
wasnan = (isnan(y) | any(isnan(X),2));
程序改成如下:
y=[-1.553 -1.06 -0.879 -1.032 -1.081 -1.066 -0.893 -0.928 -1.222]';
x= [ 1 -1.0000 -9.0000 4.8120 ; 1 -0.8240 -2.6990 4.6680 ; 1 -0.6990 -2.5230 4.4680 ; 1 -0.6990 -9.0000 4.6920; 1 -1.0000 -2.6990 4.5830 ; 1 -0.8240 -2.5230 4.8360 ; 1 -0.8240 -9.0000 4.6270 ;1 -0.6990 -2.6990 4.8700 ; 1 -1.0000 -2.5230 4.726];
[b,bint,r,rint,stats]=regress (y,x,0.05)
disp(['y =' num2str(b(4)) '+' num2str(b(3)) 'x1+' num2str(b(2)) 'x2+' num2str(b(1)) 'x3'])%输出
结果
y =-0.53393+0.017069x1+1.1066x2+2.4407x3
y=[-1.553 -1.06 -0.879 -1.032 -1.081 -1.066 -0.893 -0.928 -1.222]';
x= [ 1 -1.0000 -9.0000 4.8120 ; 1 -0.8240 -2.6990 4.6680 ; 1 -0.6990 -2.5230 4.4680 ; 1 -0.6990 -9.0000 4.6920; 1 -1.0000 -2.6990 4.5830 ; 1 -0.8240 -2.5230 4.8360 ; 1 -0.8240 -9.0000 4.6270 ;1 -0.6990 -2.6990 4.8700 ; 1 -1.0000 -2.5230 4.726];
[b,bint,r,rint,stats]=regress (y,x,0.05)
disp(['y =' num2str(b(4)) '+' num2str(b(3)) 'x1+' num2str(b(2)) 'x2+' num2str(b(1)) 'x3'])%输出
结果
y =-0.53393+0.017069x1+1.1066x2+2.4407x3