-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFixed_Point_Iteration_Method.m
More file actions
executable file
·35 lines (29 loc) · 1.05 KB
/
Fixed_Point_Iteration_Method.m
File metadata and controls
executable file
·35 lines (29 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%SCRIPT FILE: algorithm_code.m %
%AUTHOR: Damodar Rajbhandari %
%PROGRAM: Fixed Point Iteration Method %
%AIM: To find the root by numerical approximation%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc; clear; format long ;
fprintf(['',...
' ----------------------------------------------------------\n ',...
'|WELCOME TO THE PROGRAM OF \"FIXED POINT ITERATION METHOD\"|\n', ...
' ----------------------------------------------------------\n'])
a = input('The equivalent equation is: ','s');
disp('"The initial approximation should lies on the root''s interval"')
x0 = input('The initial approximation is: ');
n = input('No. of iterations: ');
c = input('Decimal upto: ');
syms 'x'
y(x) = eval(a);
df = diff(y);
z = eval(subs(df,x0));
if abs(z)<1
x = x0;
for i = 1:n
x = y(x);
end
fprintf('The approximate root of an equation is %.*f.\n',c,x)
else
disp('Choose another equivalent equation!')
end