Question

4. (20 pts) In this problem, we combine the Steepest Descent method with Newtons method for solving the following nonlinear
0 0
Add a comment Improve this question Transcribed image text
Answer #1


SMatlab code for Gradient Descent method and Newton method clear all close all n-0; eps-1; a-0.06 initialize iteration countef1 xl(xl, x2, x3)-diff(f1, x1); f1 x2(xl, x2, x3)-diff (fl, x2); f1 x3(xl, x2, x3)-diff(E1, x3); f2_x1(x1,x2, x3 )-diff (f2,For initial condition x1=0.000000, Displaying the functions x2=0 .000000, x3=0.000000 C(x1,x2, x3)x1. *3+x1.*2. *x2-x1. *x3+6

%%Matlab code for Gradient Descent method and Newton method
clear all
close all
n=0;            %initialize iteration counter
eps=1;          %initialize error
a=0.06;         %set iteration parameter
xx=[0;0;0];     %set starting value
fprintf('For Gradient Descent method.\n')
fprintf('\tFor initial condition x1=%f, x2=%f, x3=%f \n',xx(1),xx(2),xx(3))
%functions for which root have to find

syms x1 x2 x3
f_x1=@(x1,x2,x3) x1.^3+x1.^2.*x2-x1.*x3+6;
f_x2=@(x1,x2,x3) exp(x1)+exp(x2)-x3;
f_x3=@(x1,x2,x3) x2-2.*x1.*x3-4;

%displaying the function

fprintf('Displaying the functions\n')
disp(f_x1)
disp(f_x2)
disp(f_x3)

fprintf('First three iterations using Steepest Descent\n')
%Computation loop
for i=1:3
    gradf=double([f_x1(xx(1),xx(2),xx(3));f_x2(xx(1),xx(2),xx(3));f_x3(xx(1),xx(2),xx(3))]); %gradf(x)
    yy=double(xx-a*gradf);                             %iterate
    n=n+1;
    eps=norm(xx-yy);                                   %counter+1
    error(n)=eps;
    xx=yy;                                             %update x
    fprintf('\tAfter %d iterations x1=%f; x2=%f x3=%f.\n',n,xx(1),xx(2),xx(3))
end

fprintf('The solution for nonlinear equation using Steepest Descent is\n\t x1= %f\n\t x2= %f\n\t x3= %f\n',xx(1),xx(2),xx(3));

fprintf('\n\nFor Newton method.\n')

%Matlab code for Newton method
%nonlinear function to be solved

syms x1 x2 x3
f1(x1,x2,x3)=x1.^3+x1.^2.*x2-x1.*x3+6;
f2(x1,x2,x3)=exp(x1)+exp(x2)-x3;
f3(x1,x2,x3)=x2-2.*x1.*x3-4;

%finding the Jacobian matrix
f1_x1(x1,x2,x3)=diff(f1,x1);
f1_x2(x1,x2,x3)=diff(f1,x2);
f1_x3(x1,x2,x3)=diff(f1,x3);

f2_x1(x1,x2,x3)=diff(f2,x1);
f2_x2(x1,x2,x3)=diff(f2,x2);
f2_x3(x1,x2,x3)=diff(f2,x3);

f3_x1(x1,x2,x3)=diff(f3,x1);
f3_x2(x1,x2,x3)=diff(f3,x2);
f3_x3(x1,x2,x3)=diff(f3,x3);

jac1=[f1_x1 f1_x2 f1_x3 ;...
            f2_x1 f2_x2 f2_x3 ;...
            f3_x1 f3_x2 f3_x3 ];
fprintf('The Jacobian matrix is\n')          
disp(jac1)

%All initial guess for x y z  
x11=1;x22=1;x33=1;

    fprintf('For initial condition x1=%f, x2=%f, x3=%f \n',x11,x22,x33)
    kmax=500; %maximum number of iterations
    %loop for Newton method
  
    fprintf('All iterations using Newton method\n')
    fprintf('\t\tx1\tx2\tx3\n')
    for i=1:kmax

        jac=jac1(x11,x22,x33);
        ijac=inv(jac);
        xx=double([x11;x22;x33]-ijac*[f1(x11,x22,x33);f2(x11,x22,x33);f3(x11,x22,x33)]);
        err=norm(xx-[x11;x22;x33]);
        x11=double(xx(1));
        x22=double(xx(2));
        x33=double(xx(3));

        if err<10^-9
            break
        end
        fprintf('\t %f; %f %f.\n',xx(1),xx(2),xx(3))
    end

fprintf('\nThe solution for nonlinear equation using Newton method is\n\t x1= %f\n\t x2= %f\n\t x3= %f\n',x11,x22,x33)


%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
4. (20 pts) In this problem, we combine the Steepest Descent method with Newton's method for solv...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Steepest descent for unconstrained quadratic function minimization The steepest descent method for minimize f(x) is...

    2. Steepest descent for unconstrained quadratic function minimization The steepest descent method for minimize f(x) is the gradient descent method using exact line search, that is, the step size of the kth iteration is chosen as Ok = argmin f(x“ – av f(x)). a20 (a) (3 points) Consider the objective function f(x):= *xAx- Ax - c^x + d. where A e RrXnCER”, d E R are given. Assume that A is symmetric positive definite and, at xk, f(x) = 0....

  • 2. Steepest descent for unconstrained quadratic function minimization The steepest descent method for minimize f(x) is...

    2. Steepest descent for unconstrained quadratic function minimization The steepest descent method for minimize f(x) is the gradient descent method using exact line search, that is, the step size of the kth iteration is chosen as Ok = argmin f(x“ – av f(x)). a20 (a) (3 points) Consider the objective function f(x):= *xAx- Ax - c^x + d. where A e RrXnCER”, d E R are given. Assume that A is symmetric positive definite and, at xk, f(x) = 0....

  • 2. Steepest descent for unconstrained quadratic function minimization The steepest descent method for minimize f(x) is...

    2. Steepest descent for unconstrained quadratic function minimization The steepest descent method for minimize f(x) is the gradient descent method using exact line search, that is, the step size of the kth iteration is chosen as Ok = argmin f(x“ – av f(x)). a20 (a) (3 points) Consider the objective function f(x):= *xAx- Ax - c^x + d. where A e RrXnCER”, d E R are given. Assume that A is symmetric positive definite and, at xk, f(x) = 0....

  • Compute the error of each approximation, and then determine which form fits the data the best 3. ...

    Compute the error of each approximation, and then determine which form fits the data the best 3. (20 pts) Consider the nonlinear system 6x1 2 cos(3)-1-0 9r2 + Vr| + sin(za) + 1.06 + 0.9 = 0, Solve this system by i) Newton's method, (ii) Broyden's method. For both methods, use the initial approximation x() = [0,0,0], and the stopping criteria llx(k) X(k 1) I < tol = 10-9. Here 1-1 is the Euclidian 2-norm Display the results for each...

  • The steepest descent method for minimize f(x) is the gradient descent method using exact line search,...

    The steepest descent method for minimize f(x) is the gradient descent method using exact line search, that is, the step size of the kth iteration is chosen as ak = argmin f(xk – aVf(xk)). a>0 (a) (3 points) Consider the objective function f(x): = *Ax – cx+d, where A e Rnxn, CER”, d E R are given. Assume that A is symmetric positive definite and, at xk, Vf(xk) + 0. Give a formula of ak in terms xk, A, c,...

  • Using the "Newton's Method" Write a MATLAB script to solve for the following nonlinear system of...

    Using the "Newton's Method" Write a MATLAB script to solve for the following nonlinear system of equations: x2 + y2 + z2 = 3 x2 + y2 - z = 1 x + y + z =3 using the initial guess (x,y,z) = (1,0,1), tolerance tol = 1e-7, and maximum number of iterations maxiter = 20.

  • Newton's Method in MATLAB During this module, we are going to use Newton's method to compute...

    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...

  • Consider Newton's method for solving the scalar nonlinear equation f(x) = 0. Suppose we replace the...

    Consider Newton's method for solving the scalar nonlinear equation f(x) = 0. Suppose we replace the derivative f'(xx) with a constant value d and use the iteration (a) Under what condition for d will this iteration be locally convergent? (b) What is the convergence rate in general? (c) Is there a value for d that would lead to quadratic convergence?

  • Problem 1 (Matlab): One of the most fundamental root finding algorithms is Newton's Method. Given a real-valued, di...

    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,...

  • This is Matlab Problem and I'll attach problem1 and its answer for reference. We were unable...

    This is Matlab Problem and I'll attach problem1 and its answer for reference. We were unable to transcribe this imageNewton's Method We have already seen the bisection method, which is an iterative root-finding method. The Newton Rhapson method (Newton's method) is another iterative root-finding method. The method is geometrically motivated and uses the derivative to find roots. It has the advantage that it is very fast (generally faster than bisection) and works on problems with double (repeated) roots, where the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT