Practical No 3a (NC)
Practical No 3a (NC)
11 MEMOONA ARSHAD
OBJECT:
Write a program to find the root of the given equation using false position
method (using fixed iteration).
Page | 26
PRACTICAL NO# 3(A)
GR.NO.11 MEMOONA ARSHAD
ALGORITHM
STEP NO. 01: Start the program.
STEP NO. 02: Declare variables x0,x1,x2,x3,f0,f1,f2,n,c.
Page | 27
PRACTICAL NO# 3(A)
GR.NO.11 MEMOONA ARSHAD
FLOW CHART
Start A
Declare variables No
x0,x1,x2,x3,f0,f1,f2,n,c. (f0*f2)<00 X0=x1
Yes
Declare function ‘f’
X1=x2
N=1
B N=n+1
Read x0,x1
Write x2
No
B N<=10
Stop
Yes
Call function f for x0 and assign its value to f0.
Call function f for x1 and assign its value to f1. Function f(x:real):real;
x2 =x1-(f(x1)*((x0-x1)/f(x0)-f(x1))))
f:= 3x+sin(x)- e x
write n,x0,x1,x2,f2.
Page | 28
PRACTICAL NO# 3(A)
GR.NO.11 MEMOONA ARSHAD
SOURCE CODE
program regula_falsi;
uses crt;
var x0,x1,x2,f0,f1,f2:real;
n:integer;
c:char;
function f(x:real):real;
begin
f:=(3*x)+sin(X)-exp(x);
end;
begin
clrscr();
n:=1;
write('x0 = ');
readln(x0);
write('x1 = ');
readln(x1);
writeln;
writeln;
writeln(' -----FALSE POSITION METHOD----- ');
writeln;
writeln('n x0 x1 x2 f2');
writeln;
while n<=10 do
begin
f0:=f(x0);
f1:=f(x1);
x2:=x1-(f1*((x0-x1)/(f0-f1)));
f2:=f(x2);
writeln(n,' ',x0:7:6,' ',x1:7:6,' ',x2:7:6,' ',f2:7:6);
if(f0*f2)<0 then
x1:=x2
else
x0:=x2;
n:=n+1;
end;
writeln;
writeln('The root of the given equation is : ',x2:7:6);
readln(c);
end.
Page | 29
PRACTICAL NO# 3(A)
GR.NO.11 MEMOONA ARSHAD
OUTPUT
Page | 30
PRACTICAL NO# 3(A)