Idk why this is sideways Need help with number 1 and 2 pleas

Idk why this is sideways. Need help with number 1 and 2 please. Also I am currently using Matlab so only MATLAB code please.

Root finding using Steffensen\'s Method The secant method does not achieve quadratic convergence, but it has the advantage that only function evaluations (and no derivative evaluations) are needed. A method closely related to the secant method is Steffensen\'s method. This method only requires two function evaluations at each iteration, it only needs one initial guess, and it has quadratic convergence Consider the general problem of finding a root off, that is, find a solution to the equation f (x) 0. The Steffensen\'s iteration is f(xn) x, f (x, g (xn) with xo as an initial guess of the root n+ g (xn) f(x1) The project has the following parts: 1) Write a computer program that will implement Steffensen\'s method. 2) Consider the problem of finding a solution to the equation x cos(x). Use your computer implementation of Steffensen\'s method with initial guess xo 1 to compute at least the first 12 iterations. Calculate the error at each iteration 3) Implement the Newton\'s method for solving the problem described in 2) and use xo as initial conditions. Calculate the error at each iteration e 3xn a where a is the exact solution. Use a -0.7390851332151607 4) Implement the secant method for solving the problem described in 2) and use as initial conditions x 1, and for x use the value of xi computed using Steffensen\'s method in 2). Calculate the error at each iteration e x a, where Note: Here you may just use the secant method program provided by Atkinson. 5) Compare the results of 2), 3) and 4)

Solution

Following is the required matlab code

syms x
f = symfun( x - cos(x), [x]);
g = symfun( (f(x + f(x)) - f(x))/f(x), [x] );

errorAllowed = 0.00000000000000001;
actualValue = 0.7390851332151607;
xn = 1;

iteration = 0;
while(1)
   x = xn;
   error = eval( char(f) );
   x = actualValue;
   error = error - eval( char(f) )
   if error <= errorAllowed
       break;
   end
   iteration = iteration + 1;
   x = xn;
   val1 = eval( char(f) );
   val2 = eval( char(g) );
   xn = xn - val1/val2;
end

Idk why this is sideways. Need help with number 1 and 2 please. Also I am currently using Matlab so only MATLAB code please. Root finding using Steffensen\'s Me

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site