Error using inlineeval, Error in inline/subsref, Newton method HELP!
Ältere Kommentare anzeigen
ok so, As part of a group project, we have collected data that should allow us to 'triangulate' via newtons method the position of a fourth point. we are new to matlab, but the code used is from online instruction and we cannot see how to fix the issue, the number arent great, all were really looking for is a solution and an explanation of where we went wrong
% newton
format long
options = optimset('Jacobian','on');
n=12 % no of iterations
f = inline('[x(1)^2-1191.770*x(1)+x(2)^2-287.428*x(2)+x(3)^2-11.996*x(3)+406526.4166 ; x(1)^2-913.486*x(1)+x(2)^2-34.136*x(2)+x(3)^2-21.492*x(3)+231968.6664 ; x(1)^2-562.932*x(1)+x(2)^2-123.848*x(2)+x(3)^2-17.6742*x(3)+113459.6014]'); % original equations
Df = inline('[2*x(1)-1191.770, 2*x(2)-287.428, 2*x(3)-11.996 ; 2*x(1)-913.486, 2*x(2)-34.136, 2*x(3)-21.492 ; 2*x(1)-562.932, 2*x(2)-123.848, 2*x(3)-14.6742]'); % partial differentials
x = [1200;1200]
for i = 1:n
Dx = -Df(x)\f(x); %solve for increment
x = x + Dx; %add on for new guess
f(x) %see if f(x) is zero
end
there are comments so you can hoipefully follow our logic, thanks in advance for any help
these are the error codes
Error using inlineeval (line 15) Error in inline expression ==> [2*x(1)-1191.770, 2*x(2)-287.428, 2*x(3)-11.996 ; 2*x(1)-913.486, 2*x(2)-34.136, 2*x(3)-21.492 ; 2*x(1)-562.932, 2*x(2)-123.848, 2*x(3)-14.6742] Index exceeds matrix dimensions.
Error in inline/subsref (line 24) INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);
Error in gps (line 9) Dx = -Df(x)\f(x); %solve for increment
Antworten (2)
Sean de Wolski
am 27 Feb. 2013
0 Stimmen
Don't use inline. Use anonymous functions:
Dylan
am 27 Feb. 2013
Bearbeitet: Sean de Wolski
am 27 Feb. 2013
2 Kommentare
Dylan
am 27 Feb. 2013
Sean de Wolski
am 27 Feb. 2013
The matrix dimensions not agreeing means that you have two matrices that aren't the sizes you expect. Run:
dbstop if error
and then run your code. MATLAB will stop with the debugger and you will be able to identify the two variables that don't agree.
The other error indicates you're missing a parenthesis, bracket or brace.
Kategorien
Mehr zu Scope Variables and Generate Names finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!