Matlab Script To Find Root Using Secant Method
Matlab Script To Find Root Using Secant Method
% Initialize variables
validFunction = false;
while ~validFunction
% Step 0: Input the function
user_func = input('Enter the function in terms of x: ', 's');
syms x; % Define symbolic variable
try
func_sym = str2sym(user_func); % Convert string to symbolic expression
func = matlabFunction(func_sym); % Convert symbolic expression to function handle
iter = 1;
ea = Inf; % Initial approximation error (set to infinity)
logTable = [];
if ea < tolerance
break;
end
xi_minus_1 = xi;
xi = xi_plus_1; % Prepare for next iteration
iter = iter + 1;
end
root = xi;
end
1. Use the MATLAB implementation of the Secant method to find a root of the function 𝑓(𝑥) = 𝑥3 − 2𝑥2 − 6𝑥 + 4 = 0 with the
using the initial guesses x0 = -4.0 and x-1 = -3.0. Perform the computations until percentage approximate relative error is
less than 2%. You are required to fill the following table.
2. Repeat step 1 until percentage approximate relative error is less than 0.2%.
Matlab Script to Find root using Secant Method
3. Repeat step 3 using the initial guesses x0 = 2.0 and x-1 = 3.0