Question: Please need help with Write MATLAB Code each in Newton Method, and Line Search Newton Method to solve the following: (a) Solve the systems of

Please need help with

Write MATLAB Code each in Newton Method, and Line Search Newton Method to solve the following:

(a) Solve the systems of equations:

x(1)= 0 => equation 1

x(1)^2+x(2)= 0 => equation 2

exp(x(3)-1)= 0 => equation 3

(b) Find the minimum of value of

(x(1)-2)^4 + (x(1)-2)^2 *x(2) + (x(2) + 1)^2

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

NOTE: The following code works well for 2 variables but gives me errors messages in 3 variables:

1. (Error using \

2.Matrix dimensions must agree.

3. Error in newton (line 20)

4. Deltax = -J(x)\F(x);

5. Error in newton (f,df,x,tol, Max_iter,flag);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function newton(F, J,x, tol,maxiter, flag)

% Output: x = the soluton

% iter = number of iterations to reach the solution

error = [];

% X = [];

if length(x)==2

disp(' ')

disp( ' X(1) X(2) Error Iteration')

end

if length(x) ==3 disp(' ') %#ok

disp(' X(1) X(2) X(3) Error Iteration')

end

for i = 1: maxiter

if norm(F(x)) < tol

break

end

Deltax = -J(x)\F(x);

x = x + Deltax ;

X = x';

if flag == 0

for j = 0:4

alph(j+1) = (1/4)^j; %#ok

if norm(F(x + alph(j+1))*Deltax') < sqrt(1-2*10^(-4)*alph(j+1))*norm(F(x))

x = x + alph(j+1)*Deltax';

end

end

X = x';

end

error(i) = norm(F(x)); %#ok

if length(x) ==2

fprintf(' %12.8f %12.8f %12.8f %12.0f ' ,X(1,1),X(1,2),error(i), i)

end

if length(x)==3

fprintf(' %12.8f %12.8f %12.8f %12.8f %12.0f ' ,X(1,1),X(1,2),X(1,3),error(i), i)

end

end

% iter = i;

end

function F=F4(X)

F(1,1) = X(1);

F(2,1) = X(1)^2+X(2);

F(3,1) = exp(X(3)-1);

end

f = @(x) F4(x);

df = @(x) J4(x);

x = [0;0;1];

tol = 1e-12;

Max_iter = 100;

flag = 1;

newton(f,df,x,tol, Max_iter,flag);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!