0% found this document useful (0 votes)
16 views14 pages

Setab

The wxMaxima document contains multiple questions involving numerical methods, including the bisection method for finding roots of functions and matrix operations for solving systems of equations. It presents various functions and their plots, along with iterative calculations to approximate roots and solve linear equations. The results of the calculations, including approximations of roots and matrix decompositions, are displayed throughout the document.

Uploaded by

sarweshkumar7004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views14 pages

Setab

The wxMaxima document contains multiple questions involving numerical methods, including the bisection method for finding roots of functions and matrix operations for solving systems of equations. It presents various functions and their plots, along with iterative calculations to approximate roots and solve linear equations. The results of the calculations, including approximations of roots and matrix decompositions, are displayed throughout the document.

Uploaded by

sarweshkumar7004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

wxMaxima document 1 / 14

SET A
question 1
func(x):=x^3+x^2−3·x−3.0$
wxplot2d(func(x),[x,1,2]);
bisec(func, a, b, eps,N) :=
block([eps,x0:a,x1:b ,x2, ss, jj:0, jjmax:N ],
/*if length(oa) > 0 then eps : oa[1],*/
x0 : float(a),
x1 : float(b),
do (jj : jj + 1,
if jj > jjmax then print(" exceeded jjmax limit ",return(x2)),
if abs(x0−x1) <= eps then print(jj,"Approximation is :", x2,return (x2)),
if abs(func(x0)−func(x1))<= eps then print(jj,"Approximation is :", x2,return (x2)),
ss : func(x1)· func(x0),
x2: x0+(x1−x0)/2,
if ss > 0 then (print ("zero/root does not lies in the interval, Change the variables"))
else( print(jj, "root is :", x2)),
if func(x0).func(x2)<0 then (x1:x2) else (x0:x2)))$
bisec(func(x), 1.0, 2.0,0.00005,1);
wxMaxima document 2 / 14

1 root is 1.5
: 1.5
wxMaxima document 3 / 14

kill(all);
done

question 2
func(x):=37·x−1$
wxplot2d(func(x),[x,0,0.1]);
bisec(func, a, b, eps,N) :=
block([eps,x0:a,x1:b ,x2, ss, jj:0, jjmax:N ],
/*if length(oa) > 0 then eps : oa[1],*/
x0 : float(a),
x1 : float(b),
do (jj : jj + 1,
if jj > jjmax then print(" exceeded jjmax limit ",return(x2)),
if abs(x0−x1) <= eps then print(jj,"Approximation is :", x2,return (x2)),
if abs(func(x0)−func(x1))<= eps then print(jj,"Approximation is :", x2,return (x2)),
ss : func(x1)· func(x0),
x2: x0+(x1−x0)/2,
if ss > 0 then (print ("zero/root does not lies in the interval, Change the variables"))
else( print(jj, "root is :", x2)),
if func(x0).func(x2)<0 then (x1:x2) else (x0:x2)))$
bisec(func(x), 0, 0.1,0.000005,15);
wxMaxima document 4 / 14

1 root is 0.05
:
wxMaxima document 5 / 14

2 root is 0.025
:
3 root is 0.037500000000000006
:
4 root is 0.03125
:
5 root is 0.028125
:
6 root is 0.026562500000000003
:
7 root is 0.02734375
:
8 root is 0.026953125
:
9 root is 0.0271484375
:
10 root is 0.027050781250000003
:
11 root is 0.027001953125000002
:
12 root is 0.027026367187500004
:
13 root is 0.027038574218750003
:
14 root is 0.027032470703125006
:
15 root is 0.027029418945312505
: 0.027029418945312505

kill(all);
done

question 3
wxMaxima document 6 / 14

A:matrix([2,7,5],[6,20,10],[4,3,0]);
B:matrix([14],[36],[7]);
n:3;
for i:1 thru n do(
for j:1 thru n do(if(i=j) then u[i,j]:1,if (i>j) then u[i,j]:0));
for i:1 thru n do(
for j:1 thru n do(if (j>i) then l[i,j]:0));
for i:1 thru n do(l[i,1]: A[i,1]);
for j:1 thru n do(u[1,j]:A[1,j]/l[1,1]);
for k:2 thru n do(
for i: k thru n do(
l[i,k]: A[i,k]−sum(l[i,j]·u[j,k], j, j:1,j:k−1),
for j: k+1 thru n do(
u[k,j]:(A[k,j]−sum(l[k,m]·u[m,j],m,m:1,m:k−1))/l[k,k])));
l[n,n]: (A[n,n]−sum(l[n,k]·u[k,n],k,k:1, k:n−1));
L:genmatrix(l,n,n);
U:genmatrix(u,n,n);
S:L.U−A;
2 7 5 14

6 20 10 36 3 done done done done done


4 3 0 7

7 5
2 0 0 1 0 0 0
2 2
45 6 −1 0 0 0 0
0 1 5
4 − 11 45 0 0 0
0 0 1

kill(all);
wxMaxima document 7 / 14

done

question 4
'n=n:3;
'a=a:matrix([2,−1,0],[−1,4,2],[0,2,6]);
'x=x:matrix([0],[0],[0]);
'b=b:matrix([−1],[3],[5]);
print("itr","","","","","x1","","","","","x2","","","","","x3")$
for k:1 thru 2 do(for i : 1 thru n do(
y[i]:float((b[i]−sum(a[i,j]·x[j],j,1,i−1)−sum(a[i,j]·x[j],j,i+1,n))/a[i,i])),
for i:1 thru n do(x[i]:y[i]),
print(k," "," "," ",x[1]," "," "," ",x[2]," "," "," ",x[3]))$
for p:1 thru n do print('x[p]=x[p])$
2 −1 0 0 −1

n=3 a= −1 4 2 x= 0 b= 3
0 2 6 0 5

itr x1 x2 x3
1 [ − 0.5 ] [ 0.75 ] [ 0.8333333333333334 ]
2 [ − 0.125 ] [ 0.20833333333333331 ] [ 0.5833333333333333 ]
x = [ − 0.125 ]
1
x = [ 0.20833333333333331 ]
2
x = [ 0.5833333333333333 ]
3
kill(all);
done
wxMaxima document 8 / 14

SET B

question 1

func(x):=float((3·x)/2−6−(1/2)·sin(2·x))$
wxplot2d(func(x),[x,0,6]);
bisec(func, a, b, eps,N) :=
block([eps,x0:a,x1:b ,x2, ss, jj:0, jjmax:N ],
/*if length(oa) > 0 then eps : oa[1],*/
x0 : float(a),
x1 : float(b),
do (jj : jj + 1,
if jj > jjmax then print(" exceeded jjmax limit ",return(x2)),
if abs(x0−x1) <= eps then print(jj,"Approximation is :", x2,return (x2)),
if abs(func(x0)−func(x1))<= eps then print(jj,"Approximation is :", x2,return (x2)),
ss : func(x1)· func(x0),
x2: x0+(x1−x0)/2,
if ss > 0 then (print ("zero/root does not lies in the interval, Change the variables"))
else( print(jj, "root is :", x2)),
if func(x0).func(x2)<0 then (x1:x2) else (x0:x2)))$
bisec(func(x), 0, 6,0.0000001,20);
wxMaxima document 9 / 14

1 root is 3.0
:
wxMaxima document 10 / 14

2 root is 4.5
:
3 root is 3.75
:
4 root is 4.125
:
5 root is 4.3125
:
6 root is 4.21875
:
7 root is 4.265625
:
8 root is 4.2421875
:
9 root is 4.25390625
:
10 root is 4.259765625
:
11 root is 4.2626953125
:
12 root is 4.26123046875
:
13 root is 4.261962890625
:
14 root is 4.2615966796875
:
15 root is 4.26141357421875
:
16 root is 4.261505126953125
:
17 root is 4.2614593505859375
:
18 root is 4.261482238769531
:
19 root is 4.261493682861328
:
20 root is 4.26148796081543
: 4.26148796081543

kill(all);
done

question 2
wxMaxima document 11 / 14

func(x):=float(tan(%pi·x)−x−6)$
wxplot2d(func(x),[x,1,2]);
bisec(func, a, b, eps,N) :=
block([eps,x0:a,x1:b ,x2, ss, jj:0, jjmax:N ],
/*if length(oa) > 0 then eps : oa[1],*/
x0 : float(a),
x1 : float(b),
do (jj : jj + 1,
if jj > jjmax then print(" exceeded jjmax limit ",return(x2)),
if abs(x0−x1) <= eps then print(jj,"Approximation is :", x2,return (x2)),
if abs(func(x0)−func(x1))<= eps then print(jj,"Approximation is :", x2,return (x2)),
ss : func(x1)· func(x0),
x2: x0+(x1−x0)/2,
if ss > 0 then (print ("zero/root does not lies in the interval, Change the variables"))
else( print(jj, "root is :", x2)),
if func(x0).func(x2)<0 then (x1:x2) else (x0:x2)))$
bisec(func(x), 1.4, 1.45,0.00005,10);
wxMaxima document 12 / 14

kill(all);
done

question 3
A:matrix([2,7,5],[6,20,10],[4,3,0]);
B:matrix([−4],[−16],[−7]);
n:3;
/*for i:1 thru n do(
for j:1 thru n do(if(i=j) then u[i,j]:1,if (i>j) then u[i,j]:0));
for i:1 thru n do(
for j:1 thru n do(if (j>i) then l[i,j]:0));*/
for i:1 thru n do(l[i,1]: A[i,1]);
for j:1 thru n do(u[1,j]:A[1,j]/l[1,1]);
for k:2 thru n do(
for i: k thru n do(
l[i,k]: A[i,k]−sum(l[i,j]·u[j,k], j, j:1,j:k−1),
for j: k+1 thru n do(
u[k,j]:(A[k,j]−sum(l[k,m]·u[m,j],m,m:1,m:k−1))/l[k,k])));
l[n,n]: (A[n,n]−sum(l[n,k]·u[k,n],k,k:1, k:n−1));
L:genmatrix(l,n,n);
U:genmatrix(u,n,n);
S:L.U−A;
2 7 5 −4 2 0 0

6 20 10 − 16 3 done done done 45 6 −1 0

4 3 0 −7 4 − 11 45
wxMaxima document 13 / 14

7 5
1 0 0 0
2 2
0 0 0
0 1 5
0 0 0
0 0 1

kill(all);
done

question 4
'n=n:3;
'a=a:matrix([2,−1,0],[−1,4,2],[0,2,6]);
'x=x:matrix([1],[1],[1]);
'b=b:matrix([−1],[3],[5]);
print("itr","","","","","x1","","","","","x2","","","","","x3")$
for k:1 thru 2 do(
for i : 1 thru n do(y[i]:float(
(b[i]−sum(a[i,j]·x[j],j,1,i−1)−sum(a[i,j]·x[j],j,i+1,n))/a[i,i])),
for i:1 thru n do(x[i]:y[i]),
print(k," "," "," ",x[1]," "," "," ",x[2]," "," "," ",x[3]))$
for p:1 thru n do print('x[p]=x[p])$
2 −1 0 1 −1

n=3 a= −1 4 2 x= 1 b= 3
0 2 6 1 5

itr x1 x2 x3
1 [ 0.0 ] [ 0.5 ] [ 0.5 ]
2 [ − 0.25 ] [ 0.5 ] [ 0.6666666666666666 ]
wxMaxima document 14 / 14

x = [ − 0.25 ]
1
x = [ 0.5 ]
2
x = [ 0.6666666666666666 ]
3
kill(all);
done

You might also like