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!