Need help please with this program for Newton Raphson method

Hi, i've got this program. For some equations it works well, for others not. It gives me this:
??? Error using ==> inline.subsref at 17
Too many inputs to inline function.
and
Error in ==> Untitled8b at 18
fpxo=jf(xo(1),xo(2));
I know maybe it's for the use of inline, pheraps i should have used anonymous function but i couldn't do it.
this is the code(with an example working equations):
clear all
xo=[5;5] ;
syms x1 x2
fname=[(10*x1^2+2*x1-14*x1*x2-3*x2-2+x2)*0+x1;
3*(x1^3)*x2+5*x1^2-x2^3+7*x2-220];
fprima=jacobian(fname);
epsilon=1.e-10;
maxiter = 30;
iter = 1;
f=inline(fname,'x1','x2');
jf=inline(fprima);
error=norm(f(xo(1),xo(2)),2);
fprintf('error=%12.8f\n', error);
while error >= epsilon
fxo=f(xo(1),xo(2));
fpxo=jf(xo(1),xo(2));
x1=xo-inv(fpxo)*fxo;
fx1=f(x1(1),x1(2));
error =norm((fx1),2);%abs(x1-xo);
fprintf(' Iter %2d raiz x=(%14.9f,%14.9f) f(x)=(%14.9f,%14.9f)\n',....
iter,x1(1),x1(2),fx1(1),fx1(2));
if iter > maxiter
fprintf(' Numero di iterazioni massime superato \n');
return;
end
xo=x1;
iter=iter+1;
end
if for example i put an equation like : 0.1+0.45*sin(x1) or x1+x2 doesn't work. Why?

댓글 수: 2

Are you sure that in your
(10*x1^2+2*x1-14*x1*x2-3*x2-2+x2)*0+x1;
that you want to be multiplying the long initial expression by 0 ?
sorry just ignore that, i was only trying some equations. it isn't that the problem.

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

답변 (1개)

Walter Roberson
Walter Roberson 2013년 11월 14일

0 개 추천

inline() is going to be going away in a future release. Recode using anonymous functions.
You might want to look at matlabFunction()

댓글 수: 1

can you make an example for this code? sorry but i'am new to matlab.

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

카테고리

도움말 센터File Exchange에서 Function Creation에 대해 자세히 알아보기

질문:

2013년 11월 14일

댓글:

2013년 11월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by