Matrix Dimensions Must Agree Error, Error using +
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
the cyclist
el 22 de Sept. de 2015
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 comentarios
David Young
el 22 de Sept. de 2015
See my answer below for why this didn't happen, and how to fix it.
David Young
el 22 de Sept. de 2015
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 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!