Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

Fixed-point iteration Method for Solving non-linear equations in MATLAB(mfile)



% Fixed-point Algorithm 
 % Find the fixed point of y = cos(x).

 g = @(x) cos(x);
 p0 = input('Please enter initial approximation, p0:  ');
 n = input('Please enter no. of ierations, n: ');
 tol = input('Please enter tolerance, tol: ');

 i = 1;
 while i <= n
     p = g(p0);
     if abs(p-p0) < tol
        fprintf('\nApproximate solution p = %11.8f \n\n', p)
        break;
     else
        i = i+1;
        p0 = p;
     end
 end


Output:

>> Fixed_point_method_m
Please enter initial approximation, p0:  1
Please enter no. of ierations, n: 30
Please enter tolerance, tol: 0.001

Approximate solution p =  0.73876032 

>> 




No comments

Popular Posts

Followers