%Matlab code for Multivariate Newton Raphson method
clear all
close all
syms x y
%steady state equation
f(x,y)=x^3-y;
g(x,y)=y^3-x;
%Newton Raphson algorithm
f_x(x,y)=diff(f,x);
f_y(x,y)=diff(f,y);
g_x(x,y)=diff(g,x);
g_y(x,y)=diff(g,y);
%initial guess for Newton Raphson
x0=-2;y0=-2;
fprintf('For initial guess x=%f and y=%f.\n',x0,y0)
err=1; c=0;
%loop for Newton Raphson Algorithm
while err>10^-12
c=c+1;
%Jacobian of equation of
2 variable
jac=[f_x(x0,y0)
f_y(x0,y0);g_x(x0,y0) g_y(x0,y0)];
ijac=inv(jac);
xx=double([x0;y0]-ijac*[f(x0,y0);g(x0,y0)]);
%error in each
loop
err(c)=norm(xx-[x0;y0]);
%iteration count
it(c)=c;
x0=double(xx(1));
y0=double(xx(2));
fprintf('After %d
iteration\n',c)
fprintf('\t
x=%.12f\ty=%.12f\n',x0,y0)
end
fprintf('\nNR solution for solution of equation is x=%.12f
y=%.12f.\n',xx(1),xx(2))
fprintf('------------------------------------------------------------\n\n')
%initial guess for Newton Raphson
x0=2;y0=2;
fprintf('For initial guess x=%f and y=%f.\n',x0,y0)
err=1; c=0;
%loop for Newton Raphson Algorithm
while err>10^-12
c=c+1;
%Jacobian of equation of
2 variable
jac=[f_x(x0,y0)
f_y(x0,y0);g_x(x0,y0) g_y(x0,y0)];
ijac=inv(jac);
xx=double([x0;y0]-ijac*[f(x0,y0);g(x0,y0)]);
%error in each
loop
err(c)=norm(xx-[x0;y0]);
%iteration count
it(c)=c;
x0=double(xx(1));
y0=double(xx(2));
fprintf('After %d
iteration\n',c)
fprintf('\t
x=%.12f\ty=%.12f\n',x0,y0)
end
fprintf('\nNR solution for solution of equation is x=%.12f
y=%.12f.\n',xx(1),xx(2))
fprintf('------------------------------------------------------------\n\n')
%initial guess for Newton Raphson
x0=0.5;y0=-0.5;
fprintf('For initial guess x=%f and y=%f.\n',x0,y0)
err=1; c=0;
%loop for Newton Raphson Algorithm
while err>10^-12
c=c+1;
%Jacobian of equation of
2 variable
jac=[f_x(x0,y0)
f_y(x0,y0);g_x(x0,y0) g_y(x0,y0)];
ijac=inv(jac);
xx=double([x0;y0]-ijac*[f(x0,y0);g(x0,y0)]);
%error in each
loop
err(c)=norm(xx-[x0;y0]);
%iteration count
it(c)=c;
x0=double(xx(1));
y0=double(xx(2));
fprintf('After %d
iteration\n',c)
fprintf('\t
x=%.12f\ty=%.12f\n',x0,y0)
end
fprintf('\nNR solution for solution of equation is x=%.12f
y=%.12f.\n',xx(1),xx(2))
fprintf('------------------------------------------------------------\n\n')
%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%
Show it in Matlab. thx! 5. Formulate Newton's method for the system x = y v...
Problem 1 (Matlab): One of the most fundamental root finding algorithms is Newton's Method. Given a real-valued, differentiable function f, Newton's method is given by 1. Initialization: Pick a point xo which is near the root of f Iteratively define points rn+1 for n = 0,1,2,..., by 2. Iteration: f(xn) nt1 In 3. Termination: Stop when some stopping criterion occurs said in the literature). For the purposes of this problem, the stopping criterion will be 100 iterations (This sounds vague,...
Newton's Method in MATLAB During this module, we are going to use Newton's method to compute the root(s) of the function f(x) = x° + 3x² – 2x – 4 Since we need an initial approximation ('guess') of each root to use in Newton's method, let's plot the function f(x) to see many roots there are, and approximately where they lie. Exercise 1 Use MATLAB to create a plot of the function f(x) that clearly shows the locations of its...
Matlab code: Task 5 As an engineer you are asked to calculate the approximate surface area of a lake in your local community. In order to do that, you decide to use a GPS to measure the x and y coordinates at various points around the lake. You pick a starting point and calibrate your GPS position at that point to be (0,0). You begin to walk around the lake collecting the following data below and eventually return to your...
By 5. (a) Verify that y = {24 sin x is a solution to the differential equation dx2 dy + 5y = 0. dc [10 marks) (b) Differentiate the following functions with respect to c: (i) In(1 + sin? 2) (ii) * 2x3 - 4 - 8 dc. (c) Evaluate the integral / 272 * +432 – 4.7" [15 marks] [25 marks] 6. (a) let f: R+R be a function defined by f(x) 3 + 4 if : 51 ax+b...