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

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

답변 (2개)

Dylan
Dylan 2013년 2월 27일
편집: Sean de Wolski 2013년 2월 27일
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

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.
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Scope Variables and Generate Names에 대해 자세히 알아보기

질문:

2013년 2월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by