[Matlab Code] Consider the following function: We wish to find the minimum of th
ID: 3922222 • Letter: #
Question
[Matlab Code]
Consider the following function:
We wish to find the minimum of the above function in the given range of x.
1. Write a MATLAB code for the Newton-Raphson method. Use an appropriate stopping criterion.
2. Verify your results using fmincon. Make sure your code gives you the same solution as that given by fmincon. You might have to change your stopping criterion.
3. How many function evaluations does your code need? How many function evaluations does fmincon need? Use the same starting point for your code and fmincon.
Explanation / Answer
1.The program is as mentioned below: clear all close all clc f=(-3)*x^3 + 12/(x^2)+2*e^(x^2); df=diff(f); a=0; b=1; x=a; for i=1:1:100 d=x-(f(x)/df(x)); x=d; end sol=x; fprintf('Approximate Root is %.15f',sol) a=0;b=1; x=a; er(5)=0; for i=1:1:5 d=x-(f(x)/df(x)); x=d; er(i)=d-sol; end plot(er) title('Error Vs. Number of iterations') xlabel('Number of iterations') ylabel('Error')
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.