I need two MATLAB scripts.
Problem: Find the root greater than zero for the following equation using the Secant Method and compare the result with MATLAB's fzero function. 0.5x = 5 - 4x^3.
Write a main program and a function program (see requirements).
Requirements:
Main Program:
- Define a function handle for the equation you are finding the root for, b.
- Define es based on 4 significant figures.
- Use input statements to have the user enter two initial guesses.
- Enter first guess for the root:
- Enter second guess for the root:
- Call the function program to estimate the root using the Secant Method.
- Calculate the root using MATLAB's fzero function r = fzero(fxl), where f is the function handle, and xl is the first initial guess of the root.
- Output results as follows:
- Using fzero, the root of the equation is: #.#####
- Using the Secant Method, the root of the equation is: #.#####
- It took iterations for the Secant Method to converge.
Function Program (algorithm for Secant Method):
- Name your function program sec_method.
- Inputs to your function will be es, xl, x2, and your function handle (where xl and x2 are the initial guesses).
- Outputs will be the root and the number of iterations.
Example:
Enter first guess for the root:
Enter second guess for the root:
Using fzero, the root of the equation is: 0.94677
Using the Secant Method, the root of the equation is: 0.94677
It took iterations for the Secant Method to converge.