In: Computer Science
6) Solving for method Newton-Rapson starting from (1,1,1) in matlab (with algorithm)
1) sin(x) + y^2 + ln(z) – 7 = 0
2) 3x + 2^y – z^3 + 1 = 0
3) x + y + z – 5 = 0
Answer : Given data
* Method Newton-Rapson starting from (1,1,1) in matlab .
1) sin(x) + y^2 + ln(z) – 7 = 0
2) 3x + 2^y – z^3 + 1 = 0
3) x + y + z – 5 = 0
clear
clc
%function
f=@(x)[sin(x(1))+x(2)^2+log(x(3))-7;3*x(1)+2^(x(2))-x(3)^3+1;x(1)+x(2)+x(3)-5];
%Jacobian
J=@(x)[cos(x(1)) 2*x(2) 1/x(3);3 x(2)*2^(x(2)-1) -3*x(3)^2;1 1
1];
%initial guess:
t=[1;1;1];
tol = 10e-8;%edit tolerance accordingly
error=1;
while (error>tol)
xold = t;
t = t - J(t)\f(t);%equation of newton method for a system of
equation
error = norm(t-xold)/norm(t);
end
fprintf('x = %f\ny = %f\nz = %f\n',t)
_____________THE END___________________