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 find all the roots of the following equation using the Secant Method.
This equation has three roots. Use the initial guess solutions in a array as shown below:
Root : and
Root : and
Root : and
The initial guess values should be stored in an array as instruted in the template.
Use a tolerance of and maximum iterations.
You will use a forloop. The number of steps in the forloop should be equal to the number of roots.
Hint: A whileloop will be nested inside the forloop 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 of Module Note: We are not making a function file in this exercise.
The intormation about forloop and whileloop were covered in ModuleA
Script
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 fx must be named: F
Define an anonymous function for the first derivative of fx called dF This anonymous function takes two inputs x and x to perform numerical
differentiation, dfdx as explained in class.
The anonymous function for gx must be named G This function takes two inputs x and x and is used in the script to compute a new value based
on our initial guesses. x and x are the guess solutions that the function uses to calculate a possible solution within the loop.
The anonymous function for dgdx must be called dG This takes three inputs x x x 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 inisol.
The variable for the maximum number of iterations must be called maxitr.
You will have to store the roots of the equation in an array called EqnRoo.
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 r and r to extract the first and second guesses for each root.
You can use a variable called r 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 :tabnext line
& Note that MATLAB is casesensitive Variables MUST be defined as instructed above, or points will be deducted.
$ For this exercise, you need a forloop and a whileloop nested in each other.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
