Error using inlineeval, Error in inline/subsref, Newton method HELP!

6 views (last 30 days)
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

Answers (2)

Sean de Wolski
Sean de Wolski on 27 Feb 2013

Dylan
Dylan on 27 Feb 2013
Edited: Sean de Wolski on 27 Feb 2013
Thanks for the quick reply, so would the idea be to end up with something like where we are now
format long
options = optimset('Jacobian','on');
n=12 % no of iterations
f = @(x1,x2,x3) ('[x1^2-1191.770*x1+x2^2-287.428*x2+x3^2-11.996*x3+406526.4166 ; x1^2-913.486*x1+x2^2-34.136*x2+x3^2-21.492*x3+231968.6664 ; x1^2-562.932*x1+x2^2-123.848*x2+x3^2-17.6742*x3+113459.6014]');
Df = @(x1,x2,x3) ('[2*x1-1191.770, 2*x2-287.428, 2*x3-11.996, 0 ; 2*x1-913.486, 2*x2-34.136, 2*x3-21.492, 0 ; 2*x1-562.932, 2*x2-123.848, 2*x3-14.6742, 0]');
x = [100;100]
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
the new erors being
Error using + Matrix dimensions must agree.
Error in gpstrial (line 12) x = x + Dx; %add on for new guess
there is ofcourse the chance we didnt understand the original advice thanks again
  2 Comments
Dylan
Dylan on 27 Feb 2013
since realised x1 instead of x(1) will not work, however, when x(1) is put inplace of x1 where f = @ (x1...) the error code is
Error: File: gpstrial.m Line: 7 Column: 8 Unbalanced or unexpected parenthesis or bracket.
Sean de Wolski
Sean de Wolski on 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.

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!