0% found this document useful (0 votes)
7 views3 pages

Ad Prac

The document contains a wxMaxima script for solving equations using numerical methods. It demonstrates the process of finding roots of a cubic function and solving a system of linear equations through iterative methods. The results show the convergence of the root and the values of the variables after several iterations.

Uploaded by

0268manoj
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)
7 views3 pages

Ad Prac

The document contains a wxMaxima script for solving equations using numerical methods. It demonstrates the process of finding roots of a cubic function and solving a system of linear equations through iterative methods. The results show the convergence of the root and the values of the variables after several iterations.

Uploaded by

0268manoj
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/ 3

wxMaxima document 1 / 3

kill( all);
done
f ( x):=x^3+2·x^2−3·x−1;
3 2
f ( x ) := x + 2 x + − 3 x − 1
'x0=x0:1.0;
'x1=x1:2.0;
'n=n:8;
x0 = 1.0 x1 = 2.0 n=8
'err =err :0.0000001;
−7
err = 1.0 10
print( "itr","","root");
itr root root
'j =j :0;
j =0
for i:1 thru n do ( x2:( x1−( ( x1−x0)/ ( f ( x1)−f ( x0)))·f ( x1)),j :j +1,print( i,"",x2),
if ( abs( x2−x1)<err ) then ( print( "root cgs in",i,"iteration"), return( ))
else ( x0:x1,x1:x2));
print( "after root cgs in",j ,"root is",x2);
1 1.1
2 1.1517436380772856
3 1.203449860925807
4 1.1984799140986921
5 1.1986903248478271
6 1.1986912436939725
7 1.1986912435159969
root cgs in 7 iteration false
after root cgs in 7 root is 1.1986912435159969
1.1986912435159969
kill( all);
done
'x10=x10:0.0;
x10 = 0.0
'x20=x20:0.0;
x20 = 0.0
'x30=x30:0.0;
x30 = 0.0
wxMaxima document 2 / 3

for i:1 thru 8 do(


x1:( 10−x20−2·x30)/ 5,
x2:( −14+3·x10−4·x30)/ 9,
x3:( 33+x10+2·x20)/ 7,
print( i,"it gives","x1=",x1,"x2=",x2,"x3=",x3),
x10=x1,
x20=x2,
x30=x3);
print( "x1=",x1);
print( "x2=",x2);
print( "x3=",x3);
1 it gives x1= 2.0 x2= − 1.5555555555555556 x3=
4.714285714285714
2 it gives x1= 2.0 x2= − 1.5555555555555556 x3=
4.714285714285714
3 it gives x1= 2.0 x2= − 1.5555555555555556 x3=
4.714285714285714
4 it gives x1= 2.0 x2= − 1.5555555555555556 x3=
4.714285714285714
5 it gives x1= 2.0 x2= − 1.5555555555555556 x3=
4.714285714285714
6 it gives x1= 2.0 x2= − 1.5555555555555556 x3=
4.714285714285714
7 it gives x1= 2.0 x2= − 1.5555555555555556 x3=
4.714285714285714
8 it gives x1= 2.0 x2= − 1.5555555555555556 x3=
4.714285714285714 done
x1= 2.0 2.0
x2= − 1.5555555555555556 − 1.5555555555555556
x3= 4.714285714285714 4.714285714285714
kill( all);
done
'n=n:3;
n=3
'a=a:matrix( [ 5,1,2] ,[ 3,−9,−4] ,[ 1,2,−7] );
5 1 2

a= 3 −9 −4
1 2 −7

'b=b:matrix( [ 10] ,[ 14] ,[ −33] );


10

b = 14
− 33

'x=x:matrix( [ 0] ,[ 0] ,[ 0] );
wxMaxima document 3 / 3

x= 0
0

print( "itr","","","","","x1","","","","","x3","","","","","x3");
itr x1 x3 x3 x3
for k:1 thru 10 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] );
1 [ 2.0 ] [ − 1.5555555555555556 ] [ 4.714285714285714 ]
2 [ 0.42539682539682533 ] [ − 2.984126984126984 ]
[ 4.555555555555555 ]
3 [ 0.7746031746031747 ] [ − 3.438447971781305 ]
[ 3.9224489795918362 ]
4 [ 1.1187100025195265 ] [ − 3.040665154950869 ]
[ 3.842529604434366 ]
5 [ 1.0711211892164276 ] [ − 2.8904431566865423 ]
[ 4.005339956088256 ]
6 [ 0.9759526489020062 ] [ − 2.9786662507448596 ]
[ 4.041462125120478 ]
7 [ 0.979148400100781 ] [ − 3.026443394863988 ]
[ 4.002660021058897 ]
8 [ 1.0042246705492388 ] [ − 3.0081327648814717 ]
[ 3.989465944338972 ]
9 [ 1.0058401752407056 ] [ − 2.9939099739675745 ]
[ 3.9982798772551846 ]
10 [ 0.9994700438914411 ] [ − 2.9972887759220694 ]
[ 4.002574318186507 ] done
[ 0.9994700438914411 ]
[ − 2.9972887759220694 ]
[ 4.002574318186507 ] done

You might also like