Matlab Error (Matrix dimensions must agree)
2015-10-06 08:10
489 查看
xOld =input('Enter initial guess: ');
errortmp =2;
counter =0;
while (errortmp>10^-10)
xNew =xOld - Jf3(xOld)\f3(xOld)
counter=counter+1
error=norm(xNew-xOld,inf)+4*eps*norm(xNew,inf)
if(error>=errortmp)
error('shit!');
else
errortmp=error;
end
xOld = xNew;
pause
end
function J=Jf3(x)
J=[0 0 1 1;
x(3) x(4) x(1) x(2);
2*x(3)*x(1) 2*x(4)*(x(2)) x(1)^2 x(2)^2;
3*x(3)*x(1)^2 3*x(4)*(x(2))^2 x(1)^3 x(2)^3];
function y=f3(x)
y=[x(3)+x(4)-2;
x(3)*x(1) + x(4)*x(2);
x(3)*x(1)^2 + x(4)*x(2)^2 - (2/3);
x(3)*x(1)^3 + x(4)*x(2)^3];
end
//当用户输入数值时。一定要输入一个matrix,不能仅仅输入一个数值,否则会显示:Matrix dimensions must agree
输入 1; //这时我们输入的仅仅是一个数字
输入 1 2 2 3; //这时我们输入的并非matrix
输入 [1 2 3 4 ] //这时我们输入的也不是matrix
输入 [1;2;3;4] //正确
这是由至,输入值表格和表格处理功能是不一样的,因此错误代码将被显示
errortmp =2;
counter =0;
while (errortmp>10^-10)
xNew =xOld - Jf3(xOld)\f3(xOld)
counter=counter+1
error=norm(xNew-xOld,inf)+4*eps*norm(xNew,inf)
if(error>=errortmp)
error('shit!');
else
errortmp=error;
end
xOld = xNew;
pause
end
function J=Jf3(x)
J=[0 0 1 1;
x(3) x(4) x(1) x(2);
2*x(3)*x(1) 2*x(4)*(x(2)) x(1)^2 x(2)^2;
3*x(3)*x(1)^2 3*x(4)*(x(2))^2 x(1)^3 x(2)^3];
function y=f3(x)
y=[x(3)+x(4)-2;
x(3)*x(1) + x(4)*x(2);
x(3)*x(1)^2 + x(4)*x(2)^2 - (2/3);
x(3)*x(1)^3 + x(4)*x(2)^3];
end
//当用户输入数值时。一定要输入一个matrix,不能仅仅输入一个数值,否则会显示:Matrix dimensions must agree
输入 1; //这时我们输入的仅仅是一个数字
输入 1 2 2 3; //这时我们输入的并非matrix
输入 [1 2 3 4 ] //这时我们输入的也不是matrix
输入 [1;2;3;4] //正确
这是由至,输入值表格和表格处理功能是不一样的,因此错误代码将被显示
相关文章推荐
- matlab中的subplot函数
- Matlab-vision包学习-Tracking and Motion Estimation-创建Kalman滤波器
- matlab远程调试
- Writing Fast Matlab code 2
- Writing Fast Matlab code 1
- matlab和C语言的break及continue测试
- matlab 向量法建数组(推荐)
- matlab for循环应用(阶乘及the day of year)
- Matlab-vision包学习-Image Registration and Geometric Transformation
- matlab for循环的三种类型
- Matlab - 产生高斯噪声
- Matlab-vision包学习-Feature Detection,Extraction and Matching-显示匹配结果的函数
- Matlab-vision包学习-Feature Detection,Extraction and Matching-匹配
- matlab中plot画图参数的设置
- Matlab-vision包学习-Feature Detection,Extraction and Matching-提取HOG描述子
- 《数字图像处理原理与实践(MATLAB文本)》书代码Part7
- Matlab-vision包学习-Feature Detection,Extraction and Matching-提取描述子
- 谱聚类(NJW算法 Matlab代码)
- Matlab-vision包学习-Feature Detection,Extraction and Matching-SURF检测blob
- matlab 利用while循环计算平均值和方差(第二版)