New Reply

Need help with matlab code for newton-raphson (need help really bad)

 
Share Thread Thread Tools
Jul1-12, 04:50 PM   #1
 

Need help with matlab code for newton-raphson (need help really bad)


The code runs but I get the wrong answers can you take a look at the code for this .

ANSWERS
******************
x(1) = 1.035
x(2) = 1.086
x(3) = 0.927
******************

clc
clear


F = @(x) [15*x(1)+(x(2)^2)-4*x(3)-13;...
(x(1)^2)+10*x(2)^2-x(3)-11;...
x(2)^2-25*x(3)+22];
J = @(x) [15+2*x(2)-4;2*x(1)+10-1;0+2*x(2)-25];

xo = [1 1 1];
n = 4;


es = .5*10^(2-n);

[xn,cnt] = newton_raphson(es,xo,J,F);


fprintf('******************\n')
for i = 1:length(xo)
fprintf(' x(%d) = %.3f\n',i',xn(i)')
end
fprintf('******************\n')
fprintf('It took %d iterations to converge!\n',cnt')

FUNCTION PROGRAM


function [xn, cnt] = newton_raphson(es,xo,J,F)

cnt = 0;
ea = 1;

while ea > es
delx = J(xo)\-F(xo);
xn = xo + delx;

ea = 100*max(abs((xn - xo) ./ xn));
xo = xn;
cnt = cnt + 1;

end
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> King Richard III found in 'untidy lozenge-shaped grave'
>> Google Drive sports new view and scan enhancements
>> Researcher admits mistakes in stem cell study
Jul1-12, 06:09 PM   #2

Math 2012
 
Recognitions:
Science Advisor Science Advisor
J should be a 3 x 3 matrix of derivatives with ##J_{ij} = \partial F_i / \partial x_j##, not a vector.
Jul1-12, 07:54 PM   #3
 
Ok then after now I get answers like inf inf and nan
New Reply
Thread Tools


Similar Threads for: Need help with matlab code for newton-raphson (need help really bad)
Thread Forum Replies
Newton-Raphson on Matlab Math & Science Software 0
I need help writing a program on MATLAB to implement Newton Raphson method Programming & Comp Sci 2
Newton-Raphson help! Engineering, Comp Sci, & Technology Homework 7
Setting up Newton Raphson integral with matlab General Math 2
Newton Raphson's General Math 1