Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

3540416641, 978-3540416647

More Books

Students also viewed these Databases questions

Question

7-16 Compare Web 2.0 and Web 3.0.

Answered: 1 week ago