You are on page 1of 3

Mock file:///home/d33/Desktop/Roll no 698 (NM)/Mock...

Mock Practical
698
02/11/18

Ques 2. f(x)=x^3-5*x+1, [a,b]=[0,1], Perfom 6 iterations to find the root of


f(x)=0 using bisection method.

(%i5) kill(all)$
f(x):=x^3-5*x+1;
x0:0;
x1:1;

if (float(f(x0)*f(x1))>0)
then
print ("Change the value of x0 and x1, as root of f(x)=0 does not lie
between 0 and 1 (by IVT).")
else
for i:1 thru 6 do
(
a:float((x0+x1)/2),
if(f(a)*f(x1)>0) then
x1:a
else
x0:a
)$
print("a=",a)$
print("After performing 6 iterations, the root of f(x)=0 is",a)$
print("The functional value is", f(a))$

Ques 3. Solve by Gauss Jacobi,


5x+y+2z=0
-3x+9y+4z=-14

1 of 3 02/11/18, 9:58 AM
Mock file:///home/d33/Desktop/Roll no 698 (NM)/Mock...

x+2y-7z=-33
Initial approximation is [0,0,0]
Perform 10 iterations.

(%i8) kill(all)$
'A=A:matrix([5,1,2],[-3,9,4],[1,2,-7]);
'b=b:matrix([0],[-14],[-33]);
'X=X:matrix([0],[0],[0]);
'Y=Y:matrix([0],[0],[0]);

(%i5) block(
n:read("Enter the number of iterations"),
for itr:1 thru n
do
(
for i:1 thru 3
do(
sum:0,
for j:1 thru 3
do(
if(i#j) then
sum:sum+A[i][j]*X[j]
),
Y[i]:float((b[i]-sum)/A[i][i])
),
for k:1 thru 3
do(

2 of 3 02/11/18, 9:58 AM
Mock file:///home/d33/Desktop/Roll no 698 (NM)/Mock...

X[k]:Y[k]
)
),
print("After ", n , "th iteration value of ", 'Y , "is", Y));

Created with wxMaxima.

3 of 3 02/11/18, 9:58 AM

You might also like