Scilabs Tutorial Maths
Scilabs Tutorial Maths
INPUT
clc
clear
deff('[y]=f(x)','y=2*(x^3)-2.5*x-5');
a=1;b=2;c=0;c1=1;
i=0;
eps=0.0001;
disp('Regula Falsi Method')
disp('Roots')
while(abs(c-c1)>eps)
c=(a*f(b)-b*f(a))/(f(b)-f(a));
if(f(a)*f(c)<0)
b=c;
end
if(f(b)*f(c)<0)
a=c;
end
c1=(a*f(b)-b*f(a))/(f(b)-f(a));
i=i+1
disp(c);
end
disp('No.of iterations:');
disp(i);
OUTPUT
"No. of iterations:"
6
Jacobi method
Solve 20x+y-2z=17,3x=20y-z=-18,2x-3y+ 20z=25, by Jacobi method
INPUT
clc
A=[20 1 -2 17;
3 20 -1 -18;
2 -3 20 25]
x(1)=0;
y(1)=0;
z(1)=0;
for j=2:5
x(j)=(17-y(j-1)+2*z(j-1))/20;
y(j)=(-18.3*x(j-1)+z(j-1))/20;
z(j)=(25-2*x(j-1)+3*y(j-1))/20;
disp(x(j));
disp(y(j));
disp(z(j));
disp('A')
end
OUTPUT
0.85
0.
1.25
"A"
0.975
-0.7152500
1.165
"A"
1.0022625
-0.8338750
1.0452125
"A"
0.996215
-0.8648096
1.0246925
"A"
GAUSS SEIDEL ITERATIVE METHOD
SOLVE
10X-5Y-2Z=3
4X-10Y+3Z=-3
X+6Y+1 0Z=-3
INPUT
clc
clear
A=[10 -5 -2;4 -10 3;1 6 10]
B=[3 -3 -3]'
disp('(A B)=')
disp([A B])
n=9
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('x=');
disp(xold)
disp('y=');
disp(yold)
disp('z=')
disp(zold)
OUTPUT
"(A B)="
10. -5. -2. 3.
4. -10. 3. -3.
1. 6. 10. -3.
"x="
0.3414864
"y="
0.2850423
"z="
-0.5051740
Newton-Raphson Method
INPUT
clc;
deff('[y]=f(x)','y=x*sin(x)+cos(x)');
deff('[y]=fd(x)','y=x*cos(x)');
x=3.1416;
xx=0;
i=0;
eps=0.0001;
disp('By using Newton Raphson Method');
disp('x:');
while(abs(x-xx)>=eps)
y=x-(f(x)/fd(x));
disp(y);
xx=x;
x=y;
i=i+1;
end
disp('No of iteration;');
disp(i);
OUTPUT
"No of iteration;"
4.