Question: Write a MATLAB script 1 0 find all the roots of the following equation using the Secant Method. f ( x ) = x 3

Write a MATLAB script 10 find all the roots of the following equation using the Secant Method.
f(x)=x3-3x2+3
This equation has three roots. Use the initial guess solutions in a 32 array as shown below:
Root 1:-1 and 0
Root 2:1 and 2
Root 3:2.2 and 3
The initial guess values should be stored in an array as instruted in the template.
Use a tolerance of 10-5, and 500 maximum iterations.
You will use a for-loop. The number of steps in the for-loop should be equal to the number of roots.
Hint: A while-loop will be nested inside the for-loop to compute all the roots. After each root is computed, its value will be stored in an element of an array called Eqn Roo.
You should define a total of tive anonymous functions.
For reference about finding roots of equations using the Secant Method, refer to slides 22-29 of Module_02. Note: We are not making a function file in this exercise.
The intormation about for-loop and while-loop were covered in Module_01A.
Script o.
% Here, write your script for the problem statemenet above. Your script MUST be properly and completely commented to receive full credit.
% Define variables and functions as instructed below.
% NOTE: The complete instructions for this assignment was explained during the lecture in class.
% The anonymous function for f(x) must be named: F
% Define an' anonymous function for the first derivative of f(x), called dF. This anonymous function takes two inputs x0, and x1 to perform numerical
differentiation, df/dx, as explained in class.
% The anonymous function for g(x) must be named G. This function takes two inputs x0 and x1, and is used in the script to compute a new value based
% on our initial guesses. x0 and x1 are the guess solutions that the function uses to calculate a possible solution within the loop.
% The anonymous function for dg/dx must be called dG. This takes three inputs x0, x1, x2, and is used for convergence test. The equation for this
% anonymous function is the numerical differentiation of g
% Store the initial solution in an array variable named ini_sol.
% The variable for the maximum number of iterations must be called max_itr.
% You will have to store the roots of the equation in an array called Eqn_Roo.
% Use a variable called iter to count your iterations inside the loop.
% Use a variable called Tol to determine the tolerance for the calculations.
% Inside the loop, you can use variables r0 and r1 to extract the first and second guesses for each root.
% You can use a variable called r2 to store the output of the function g
%s After the solution is completed, print out the roots using the fprintf command in the following format:
% Root 1.0:{tab}12.3456{next line}
& Note that MATLAB is case-sensitive. Variables MUST be defined as instructed above, or points will be deducted.
$8 For this exercise, you need a for-loop and a while-loop nested in each other.
Write a MATLAB script 1 0 find all the roots of

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 Programming Questions!