Question

In: Advanced Math

Please use python or matlab. The function e^x −100x^2 =0 has three true solutions.Use secant method...

Please use python or matlab. The function e^x −100x^2 =0 has three true solutions.Use secant method to locate the solutions with tolerance 10^(−10).

Solutions

Expert Solution


%Matlab code for Secant method
clear all
close all
%Function for which root have to find
f=@(x) exp(x)-100.*x.^2;
fprintf('For the function f(x)= ')
disp(f)

%finding root using Secant Method
e=10^-10;   %error convergence
max=50000;   %Maximum iterations

a=[-10 -5];    %initial guess
%Root using Secant method
[root]=secant_method(f, a, e, max);
fprintf('Finding root using Secant method\n')
fprintf('\tThe root for this function for initial guess [%d %d] is %f\n\n',a(1),a(2),root)

a=[2 10];    %initial guess
%Root using Secant method
[root]=secant_method(f, a, e, max);

fprintf('\tThe root for this function for initial guess [%d %d] is %f\n\n',a(1),a(2),root)

a=[1 2];    %initial guess
%Root using Secant method
[root]=secant_method(f, a, e, max);

fprintf('\tThe root for this function for initial guess [%d %d] is %f\n\n',a(1),a(2),root)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Matlab function for Secant Method
function [root]=secant_method(f, a, e, max)

    %a= vector of two initial guess
    %e= error tollerence
    %max= maximum number of iterations

    %x0 and x1 values for two initial guess
    x0=a(1); x1=a(2);
    %checking wheather function values for two initial guesses are same
    if f(x0)==f(x1)
        msg = 'Function values are identical at initial guesses.';
        error(msg);
    end
    %loop for Secant iterations
    k=0;
    for i=1:max
        k=k+1;
        xx=double(x1-(f(x1)*abs((x1-x0)/(f(x1)-f(x0)))));
        x0=x1;
        x1=xx;
        if(abs(xx-x0)<=e)
            break
        end

    end
    root=xx;
    %If maximum iteration reached
    if i==max
        fprintf('Has reached maximum iteration steps allowed.\n')
    end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Related Solutions

In MATLAB write a function secant.m to apply the secant method. function [x,i] = secant(f, x0,...
In MATLAB write a function secant.m to apply the secant method. function [x,i] = secant(f, x0, x1, tol, maxiters) [x,i] = secant(f, x0, x1, tol, maxiters) performs the secant method with f(x), starting at x_0 = x0 and x_1 = x1, and continuing until either |x_i+1 - x_i| <= tol, or maxiters iterations have been taken. The number of iterations, i, is also returned. An error is raised if the first input is not a function handle. A warning is...
Use the secant Method to find a root for the function: f(x) = x^3 + 2x^2...
Use the secant Method to find a root for the function: f(x) = x^3 + 2x^2 + 10x -20, with x_0 = 2, and x_1 = 1.
Write one a MATLAB function that implements the Bisection method, Newton’s method and Secant Method (all...
Write one a MATLAB function that implements the Bisection method, Newton’s method and Secant Method (all in one function). Your function must have the following signature function output = solve(f,options) % your code here end where the input is • f: the function in f(x) =0. options: is a struct type with the following fields o method: bisection, newton or secant tol: the tolerance for stopping the iterations. maximum_iterations: the maximum number of iterations allowed. initial_guess: that is P_0; if...
script for Secant Method. Using Matlab or Octave. The data: y = x.^2 - 1.2 x_lower...
script for Secant Method. Using Matlab or Octave. The data: y = x.^2 - 1.2 x_lower = 0.4 x_upper = 0.6 Es = 0.5*10^(2-n) n = 5
Use ten iterations of the appropriate MATLAB function, with x^(0)=[0,...,0]', to solve Ax=b (approximately). A)use Jacobi...
Use ten iterations of the appropriate MATLAB function, with x^(0)=[0,...,0]', to solve Ax=b (approximately). A)use Jacobi iteration. B) use Gauss-siedel iteration. 1) make sure to use SOR with w=1.25, w=1.5, w=1.75,w=1.9, and optimal value if given. * A=[1,-2,0,0;-2,5,-1,0;0,-1,2,-0.5;0,0,-0.5,1.25]] , B=[-3;5;2;3.5]. , (optimal w is 1.5431.)
Use ten iterations of the appropriate MATLAB function, with x^(0)=[0,...,0]', to solve Ax=b (approximately). B) use...
Use ten iterations of the appropriate MATLAB function, with x^(0)=[0,...,0]', to solve Ax=b (approximately). B) use Gauss-siedel iteration. C)use SOR with w=1.25, w=1.5, w=1.75,w=1.9, and optimal value if given. * A=[4,8,0,0;8,18,2,0;0,2,5,1.5;0,0,1.5,1.75] , B=[8;18;0.5;-1.75]. , (optimal w is 1.634.)
On Matlab use BFGS Method to find the minimum of the following function: f(x) = x13...
On Matlab use BFGS Method to find the minimum of the following function: f(x) = x13 - 2x2x12 + x12 - x1using initial point (x0, y0) = (1, 2)T to start, and stop when f changes less than 0.0001
use a matlab built-in function to numerically solve: dy/dx= -x^2+((x^3*e^-y)/4) for 1<=x<=5 with y(1)=1 plot the...
use a matlab built-in function to numerically solve: dy/dx= -x^2+((x^3*e^-y)/4) for 1<=x<=5 with y(1)=1 plot the solution
what is the absolute maximum of the function f(x)=(e^x)/x, x>0?
what is the absolute maximum of the function f(x)=(e^x)/x, x>0?
PLEASE USE PYTHON CODE Compute the zero of the function y(x) from the following data: x...
PLEASE USE PYTHON CODE Compute the zero of the function y(x) from the following data: x = 0.2, 0.4, 0.6, 0.8, 1.0 y = 1.150, 0.855, 0.377, -0.266, -1.049 Use inverse interpolation with the natural cubic spline
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT