MATLAB Use your NewtonRaphson function to solve the followin

MATLAB

Use your Newton-Raphson function to solve the following system of nonlinear equations: f(x, y) = 0 {x^2 + y^2 - 4 = 0 y + 2.1/x - 0.3 = 0 and an initial point of [3 -1.5] f(x, y) = 0 {sin(x) + y^2 + ln(z) - 7 = 0 3x + 2^y - z^3 + 1 = 0 x + y + z - 5 and an intial point of [0 2 2]

Solution

(a)

clc,clear
% Newton Raphson solution of two nonlinear algebraic equations
% set up the iteration
error1 = 1.e8;
xx(1) = 3; % initial guesses
xx(2) = -1.5;
iter=0;
maxiter=40
% begin iteration
while error1>1.e-12
iter=iter+1;
x = xx(1);
y = xx(2);
% calculate the functions
f(1) = x^2+y^2-4;
f(2) = y+(2.1/x)-.3;
% calculate the Jacobian
J(1,1) = 2*x;
J(1,2) = 2*y;
J(2,1) = -2.1/(x^2);
J(2,2) = 1;
% solve the linear equations
y = -J\\f\';
% move the solution, xx(k+1) - xx(k), to xx(k+1)
xx = xx + y\';
% calculate norms
error1=sqrt(y(1)^2+y(2)^2);
error(iter)=sqrt(f(1)^2+f(2)^2);
ii(iter)=iter;
if (iter > maxiter)
error1 = 0;
s=sprintf(\'****Did not converge within %3.0f iterations.****\',maxiter);
disp(s)
end
% check if error1 < 1.e-12
end
x = xx(1);
y = xx(2);
f(1) = x^2+y^2-4;
f(2) = y+(2.1/x)-.3;
% print results
f
xx
iter

RESULT:

xx =

1.8036 -0.8644


iter =

7

(b)

clc,clear
% Newton Raphson solution of two nonlinear algebraic equations
% set up the iteration
error1 = 1.e8;
xx(1) = 0; % initial guesses
xx(2) = 2;
xx(3)=2;
iter=0;
maxiter=40
% begin iteration
while error1>1.e-12
iter=iter+1;
x = xx(1);
y = xx(2);
z=xx(3);
% calculate the functions
f(1) = sin(x)+y^2+log(z)-7;
f(2) = 3*x+2^y-z^3+1;
f(3) =x+y+z-5;
% calculate the Jacobian
J(1,1) = cos(x);
J(1,2) = 2*y;
J(1,3) = 1/z;
J(2,1) = 3;
J(2,2) = (2^y)*log(y);
J(2,3) = -3*z^2;
J(3,1) = 1;
J(3,2) = 1;
J(3,3) = 1;
% solve the linear equations
y = -J\\f\';
% move the solution, xx(k+1) - xx(k), to xx(k+1)
xx = xx + y\';
% calculate norms
error1=sqrt(y(1)^2+y(2)^2++y(3)^2);
error(iter)=sqrt(f(1)^2+f(2)^2+f(3)^2);
ii(iter)=iter;
if (iter > maxiter)
error1 = 0;
s=sprintf(\'****Did not converge within %3.0f iterations.****\',maxiter);
disp(s)
end
% check if error1 < 1.e-12
end
x = xx(1);
y = xx(2);
z = xx(3);
f(1) = sin(x)+y^2+log(z)-7;
f(2) = 3*x+2^y-z^3+1;
f(3) =x+y+z-5;
% print results
f
xx
iter

RESULT:

xx =

0.5991 2.3959 2.0050


iter =

8

MATLAB Use your Newton-Raphson function to solve the following system of nonlinear equations: f(x, y) = 0 {x^2 + y^2 - 4 = 0 y + 2.1/x - 0.3 = 0 and an initial
MATLAB Use your Newton-Raphson function to solve the following system of nonlinear equations: f(x, y) = 0 {x^2 + y^2 - 4 = 0 y + 2.1/x - 0.3 = 0 and an initial
MATLAB Use your Newton-Raphson function to solve the following system of nonlinear equations: f(x, y) = 0 {x^2 + y^2 - 4 = 0 y + 2.1/x - 0.3 = 0 and an initial

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site