Matrix Dimensions Must Agree Error, Error using +
2 ビュー (過去 30 日間)
古いコメントを表示
This is Newton Raphsons Method for systems. Row 1 and 2 in f= [x1 etc is 2 equations for 2 circles, and I want to find 2 intersections between these circles. I have already plotted and got guess 1 = [51 28] and 2 [41 47]. I need to find 2 x1, and x2 values who solves the system.
if true
format short e, format compact
disp(' x f(x) h=J\f(x)');
x=[51 28]'; %Startvektor
h=x;
iter=1;
while ( (norm(h,inf) > 1.0e-10*norm(x,inf)) & (iter < 20)),
f =[x(1).^2 + x(2).^2 -2*93*x(1) -2*63*x(2)+ 9.5820e+03
x(1).^2 + x(2).^2 -12*x(1) -32*x(2)- 1.8332e+03 ];
%Jacobian
J=[2*x(1)-2*93 2*x(2)-2*63
2*x(1)-12 2*x(2)-32];
h =-J\f;
disp(iter)
disp([x f h])
x=x+h; iter=iter+1;
end
format long
x
% code
end
Error using + Matrix dimensions must agree. Error in uppg6aNRAP (line 20) x=x+h; iter=iter+1;
PLS HELP! I'm a beginner
0 件のコメント
回答 (2 件)
the cyclist
2015 年 9 月 22 日
If you put a breakpoint at line 18, temporarily halting execution there, you will see that x is a 2x1 vector, and h is a 2x3 array. (Is that what you expect?) Arrays have to be the same shape to add them.
2 件のコメント
David Young
2015 年 9 月 22 日
It's necessary to put spaces in the expression for f so that + and - are interpreted as binary operators rather than unary signs. Like this:
f =[x(1).^2 + x(2).^2 - 2*93*x(1) - 2*63*x(2) + 9.5820e+03
x(1).^2 + x(2).^2 - 12*x(1) - 32*x(2) - 1.8332e+03 ];
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!