Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following function f(x) = 3 cos (x) - 5x find x such that f(x) = -5

ID: 673182 • Letter: C

Question

Consider the following function

f(x) = 3 cos (x) - 5x

find x such that f(x) = -5 (in the form f(x) - b = 0, b = -5).

In MATLAB create a function that uses the modified secant method of the form

Hints:

This Matlab function approximates the root of f(x)-b = 0 where both f(x) and b are inputs.

Approximate error is calculated using root approximations that arise from two adjacent iterations. x_R(current iteration) is the root approximation that is found as the result of the current iteration, x_R(previous iteration) is the root approximation that is found as the result of the previous iteration.

Explanation / Answer

% Find the roots of using Secant Method
% func --> 3 cos (x) - 5x

def x;
    flag = 1;
    func = input('Enter Function in terms of x: ');
    a = input('Ener Lower Limit: ');
    b = input('Ener Upper Limit: ');
    maxerr = input('Enter Maximum Error: ');

    f = inline(func);
  
        c = (a*f(b) - b*f(a))/(f(b) - f(a));

        disp('   Xn-1      f(Xn-1)      Xn      f(Xn)      Xn+1      f(Xn+1)');
        disp([a f(a) b f(b) c f(c)]);

        while abs(f(c)) > maxerr
            a = b;
            b = c;
            c = (a*f(b) - b*f(a))/(f(b) - f(a));
            disp([a f(a) b f(b) c f(c)]);
          
            flag = flag + 1;
          
            if(flag == 100)
                break;
            end
        end
      
        display(['Root is x = ' num2str(c)]);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote