SciLab Practicals

Ordinary Differential Equation Example 1

x0=0
xinc=0.001
xf=1
x=x0:xinc:xf
y=sqrt(x^2+2*x+0.001)
disp("The Value is", y)
plot2d(x,y)
title ('Diffrentiation')
xlabel("X")
ylabel("Y")

Ordinary Differential Equation Example 2

x0=0
xinc=0.001
xf=1
x=x0:xinc:xf
y=%e^-x
disp("The value is",y)
plot2d(x,y)
title("Diffrentiation")
xlabel("x")
ylabel("y")

Linear Equation

A=[1,1,1; 3,1,2; 1,1,-1]
B=[10;5;1] 
[x0, kerA]=linsolve(A,B)
disp("The answer is", x0)

Least Square Method

x=[-8.3, -4.8, -4.1, -0.9, 2.9, 4.7, 6.5, 8.7] 
y=[-2.3, -3.3, -0.8, -1.7, 0.6, -1.2, 2.2, 5]
n=length(x)
sx=sum(x)
sy=sum(y)
sx2=sum(x.*x)
sxy=sum(x.*y)
A=[sx n; sx2 sx]
B=[sy; sxy]
sol=A\B
m=sol(1)
c=sol(2)
xn=[-10:0.1:10]
yfit=[xn.*m + c]
plot2d(x,y,-4)
title ('Least square fitting Linear Regression', 'color', 'blue') 
xlabel"x"fontsize 2
ylabel("y")
plot(xn, yfit, "b") 
legends(['points'; 'Least Square Fit'], [-4,2])

Eigen Value Example 1

clc
k=(0.7205)
a=[2,0,0;0,4,5;0,4,3]
evals=spec(a)
disp("Eigen value are", evals)

Eigen Vector Example 1

a=[2,0,0;0,4,5; 0,4,3] 
[R,diagevals]=spec(a)
disp("The eigen vectors", diagevals)

Eigen Value Example 2

clc
k=(0.7205)
a=[-6,3;4,5]
evals=spec(a)
disp("Eigen value are", evals)

Eigen Vector Example 2

a=[-6,3;4,5]
[R,diagevals]=spec(a)
disp("The eigen vectors", diagevals)

Eigen Value Example 3

clc
k=[(8)/3*(3.14)]^2
a=[1,0,0;0,1,k;0,k,1]
evals=spec(a) 
disp("Eigen value are", evals)

Eigen Vector Example 3

a=(8/3*(3.14)^2)
[R,diagevals]=spec(a)
disp("The eigen vectors", diagevals)

Curve Fitting Method

x= [1:0.5:3.5]';
y= [97; 150; 219; 250; 278; 263];
subplot(2,2,1);
plot2d(x,y,-3);

X=[x.^2 x ones(x)];
a=X\y;
xx=[0:0.1:3.5];
yy=[a(1)*xx.^2 + a(2)*xx + a(3)];
subplot(2,2,2);
plot2d(x,y,-3);
plot(xx, yy);

Bisection Method

function y=f(x)
    y=3*x+sin(x)-%e^x
endfunction

x=linspace(0,2,100);
plot(x,f,"r")
title ("Bisection-Method")
xlabel "x"
ylabel "y"
//xgrid (1,1,7)

function bisection(a, b, TOL, n)
    i=1
    final_output=[i, a, b, (a+b)/2, f((a+b)/2)]
    disp("n a b c f(c)") 
    while(i<n),
        c=(a+b)/2
        if (f(c) == 0 | (b-a)/2 < TOL) then
            break
        else final_output=[final_output;i,a,b,c,f(c)]
    end
i=i+1
if(f(a)*f(c)>0) then 
    a=c
else
    b=c
end
end
disp(final_output)
endfunction

bisection(1,2,-10^-4,50)

Download the Source Code:

Download