You are on page 1of 6

Numerical Solutions using SCILAB

Tutorial -7
1 Find the approximate root of by Regula-Falsi method using Scilab.
Input: clc;
clear;
disp("Regular Falsi Method")
deff('y=f(x)','y=x^3-2*x-5')
a=1; b=2;
for i=1:10
c=(a*f(b)-b*f(a))/(f(b)-f(a))
if f(a)*f(c)<0
then b=c
else a=c
disp([i,c])
end
end
disp('Root of the equation after 10 iterations by Regula Fasi Method is',c)
Output: "Regula Falsi Method"

2. 1.9933775

3. 2.0885613

4. 2.0942097

5. 2.094532

6. 2.0945504

7. 2.0945514

8. 2.0945515

9. 2.0945515

10. 2.0945515

"Root of the equation after 10 iterations by Regula Fasi Method is"

2.0945515
1. Tutorial-8
Find the approximate root of by Newton Raphson method using Scilab
programming.
Input: clc;
clear;
disp("Newton Raphson Method")
deff('y=f(x)','y=x^3-2*x-5')
deff('z=g(x)','z=3*x^2-2')
x0=1.5
for i=1:10
c=x0-f(x0)/g(x0);
Numerical Solutions using SCILAB

x0=c
disp([i,c])
end
disp('Root of the equation after 10 iterations by Newton Raphson Method is',c)
Output: "Newton Raphson Method"

1. 2.4736842

2. 2.156433

3. 2.0966046

4. 2.0945539

5. 2.0945515

6. 2.0945515

7. 2.0945515

8. 2.0945515

9. 2.0945515

10. 2.0945515

"Root of the equation after 10 iterations by Newton Raphson Method is"

2.0945515
1 Tutorial-9
Solve the system of equations by Gauss Jacobi method using Scilab.

Input: clc;
clear;
A=[6 1 1;4 8 3;5 4 -10]//coefficient matrix//
B=[105 155 65]'
disp('[A B]=')
disp([A B])
n=15//no. of iterations//
xold=0
yold=0
zold=0
for i=0:n
x(i+1)=((B(1)-A(4)*yold-A(7)*zold))/A(1)
y(i+1)=((B(2)-A(2)*xold-A(8)*zold))/A(5)
z(i+1)= ((B(3)-A(3)*xold-A(6)*yold))/A(9)
xold=x(i+1)
yold=y(i+1)
zold=z(i+1)
end
disp('The values of x, y z after 15 iterations are')
Numerical Solutions using SCILAB

disp('x=');
disp(x)
disp('y=');
disp(y)
disp('z=');
disp(z)
Output : "[A B]="

6. 1. 1. 105.
4. 8. 3. 155.
5. 4. -10. 65.

"The values of x, y z after 15 iterations are"

"x="

17.5
15.354167
13.65625
15.108333
15.224436
14.896966
14.973331
15.029950
14.997346
14.993785
15.002332
15.000761
14.999249
15.000037
15.000162
14.999946

"y="

19.375
13.0625
7.9479167
10.146094
10.505599
9.8455556
9.9335954
10.055820
9.9999862
9.9873384
10.003607
10.001898
9.9986412
9.9999482
10.000326
9.9999200
Numerical Solutions using SCILAB

"z="

-6.5
10.
6.4020833
3.5072917
5.1126042
5.3144575
4.8867053
4.9601037
5.0373029
4.9986675
4.9918279
5.0026090
5.0011398
4.9990809
4.9999975
5.0002115
1 Tutorial-10
Solve the system of equations by Gauss Seidal method using Scilab .
Input: clc;
clear;
A=[6 1 1;4 8 3;5 4 -10]//coefficient matrix//
B=[105 155 65]'
disp('[A B]=')
disp([A B])
n=15//no. of iterations//
xold=0
yold=0
zold=0
for i=0:n
x(i+1)=((B(1)-A(4)*yold-A(7)*zold))/A(1)
y(i+1)=((B(2)-A(2)*x(i+1)-A(8)*zold))/A(5)
z(i+1)= ((B(3)-A(3)*x(i+1)-A(6)*y(i+1)))/A(9)
xold=x(i+1)
yold=y(i+1)
zold=z(i+1)
end
disp('The values of x, y z after 15 iterations are')
disp('x=');
disp(x)
disp('y=');
disp(y)
disp('z=');
disp(z)
Output: "[A B]="

6. 1. 1. 105.
4. 8. 3. 155.
5. 4. -10. 65.
Numerical Solutions using SCILAB

"The values of x, y z after 15 iterations are"

"x="

17.5
14.645833
15.119444
14.974997
15.006650
14.998443
15.000389
14.999906
15.000023
14.999994
15.000001
15.000000
15.000000
15.000000
15.000000
15.000000

"y="

10.625
9.6145833
10.064497
9.9804311
10.004299
9.9988870
10.000264
9.9999344
10.000016
9.9999961
10.000001
9.9999998
10.000000
10.000000
10.000000
10.000000

"z="

6.5
4.66875
5.0855208
4.9796710
5.0050442
4.9987762
5.0003004
4.9999267
Numerical Solutions using SCILAB

5.0000179
4.9999956
5.0000011
4.9999997
5.0000001
5.0000000
5.0000000
5.0000000

You might also like