Scilab Codes
Scilab Codes
INPUT:
clc;
funcprot(0)
function ydot=f(x, y)
ydot= exp(-x)
endfunction
x=0:0.1:5;
y0=0;
x0=0;
y = ode(y0,x0,x,f);
disp(y);
plot2d(x,y)
OUTPUT:
INPUT:
clc;
funcprot(0)
function ydot=f(x,y)
ydot=x^2 - (exp(-x)*y);
endfunction
x=0:0.1:5;
y0=0;
x0=0;
y = ode(y0,x0,x,f);
disp(y);
plot2d(x,y)
OUTPUT:
0. 0.0003258 0.0025568 0.0084933 0.0198705 0.0383977 0.0657843 0.1037567 0.15407
0.2185141 0.298918 0.3971507 0.5151208 0.6547756 0.8180982 1.0071048 1.2238418
1.4703819 1.748821 2.0612743 2.4098734 2.7967628 3.2240965 3.6940361 4.208747
4.770397 5.3811537 6.0431829 6.7586466 7.5297022 8.3585007 9.2471864 10.197896
11.212756 12.293888 13.4434 14.663395 15.955964 17.32319 18.767147 20.2899 21.893506
23.580014 25.351466 27.209894 29.157327 31.195785 33.327282 35.553829 37.87743
40.300083
+ +y=0
INPUT:
clc;
funcprot(0)
function dx=f(t,x)
dx(1)= x(2);
dx(2)=-x(1) - (exp(-t)*x(2));
endfunction
t=4:0.1:10;
x= ode([0;1],0,t,f);
disp(x(1,:));
plot2d(t,x(1,:))
OUTPUT:
INPUT:
clc;
funcprot(0)
function dx=f(t,x)
dx(1)= x(2);
dx(2)=-x(1) - (2*x(2));
endfunction
t=4:0.1:10;
x= ode([0;1],0,t,f);
disp(x(1,:));
plot2d(t,x(1,:))
OUTPUT:
1. dx
INPUT:
clc;
x0=0;
x1=0:0.1:10;
X=integrate('exp(x)','x',x0,x1);
plot(X)
OUTPUT:
2. dx
INPUT:
clc;
x0=-10;
x1=0:0.1:10;
X=integrate('exp(-x)','x',x0,x1);
plot(X)
OUTPUT:
3. dx
INPUT:
clc;
x0=0;
x1=0:0.1:10;
X=integrate('x*exp(x)','x',x0,x1);
plot(X)
OUTPUT:
4. dx
INPUT:
clc;
x0=0;
x1=0:0.1:10;
X=integrate('x*exp(-x)','x',x0,x1);
plot(X)
OUTPUT:
5. dx
INPUT:
clc;
x0=0;
x1=0:0.1:10;
X=integrate('x*sin(x)','x',x0,x1);
plot(X)
OUTPUT:
σ =1
INPUT:
clc;
x0=0;
x1=0:0.1:10;
Y=1/((2*%pi*((1)^2))^0.5);
X=integrate('exp(-((x-2)^2)/(2*(1)^2))*(x+3)','x',x0,x1);
Z=Y*X
plot(Z)
disp(Z)
OUTPUT:
OUTPUT:
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 2.605D-15 5.486D-12 4.325D-09 0.0000013 0.000145
0.0063063 0.1083516 0.7690792 2.4601058 4.1825267 4.8808502 4.9928073 4.9998283
4.9999984 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5.
5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5.
5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. tends to 5
σ =0.01
INPUT:
clc;
x0=0;
x1=0:0.1:10;
Y=1/((2*%pi*((.01)^2))^0.5);
X=integrate('exp(-((x-2)^2)/(2*(.01)^2))*(x+3)','x',x0,x1);
Z=Y*X
plot(Z)
disp(Z)
OUTPUT:
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 2.4960106 5. 5. 5. 5.
5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5.
5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5.
5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. 5. tends to 5
Fourier series
1) Program to sum
INPUT:
clc;
s=0;
for n=1:100000
s=s+(0.2)^n
end
disp(s,"sum=");
OUTPUT:
0.25
–
f(x) =
INPUT:
clc;
clf;
funcprot(0);
m=input("no. of Fourier coefficients you need")
l=1/%pi
function z=f1(x)
z=-1
endfunction
integral1=l*integrate('f1','x',-1*%pi,0)
function r=f4(x)
r=1
endfunction
integral2=l*integrate('f4','x',0,%pi)
a0=integral1 + integral2
disp(a0,"first Fourier coefficient (a0)")
//////gap............
disp("value of a1,a2,-----an")
function w=f2(x)
w=-1*cos(i*x)
endfunction
function s=f5(x)
s=1*cos(i*x)
endfunction
for i=1:m
integral3=l*integrate('f2','x',-1*%pi,0)
integral4=l*integrate('f5','x',0,%pi)
an=integral3 + integral4
disp(an)
end
/////break.......
disp("value of b1,b2,----bn")
function v=f3(x)
v=-1*sin(i*x)
endfunction
function t=f6(x)
t=1*sin(i*x)
endfunction
for i=1:m
integral5=l*integrate('f3','x',-1*%pi,0)
integral6=l*integrate('f6','x',0,%pi)
bn=integral5 + integral6
disp(bn)
end
OUTPUT:
no. of Fourier coefficients you need
5 (entered by user)
0.
value of a1,a2,-----an
0.
0.
0.
0.
0.
value of b1,b2,----bn
1.2732395
7.071D-17
0.4244132
-3.272D-17
0.2546479
INPUT:
clc;
clf;
funcprot(0);
n=input("enter the value of n =");
m=input("enter the value of m =");
z=integrate('legendre(n,0,x)*legendre(m,0,x)', 'x',-1,1)
disp(z);
OUTPUT:
enter the value of n =
4
enter the value of m =
4
0.2222222
0.
2. Plot ,
INPUT:
l=nearfloat("pred",1);
x=linspace(-1,1,200)';
y=legendre(0:5,0,x);
clf()
plot2d(x,y',leg="p0@p1@p2@p3@p4@p5@p6")
xtitle("first 6 legendre polynomials")
OUTPUT:
INPUT:
clc;
funcprot(0);
x=linspace(0.01,10,5000)';
y=besselh(0:5,x);
plot2d(x,y)
OUTPUT:
INPUT:
clc;
funcprot(0);
n= input("enter value of n");
for x =-1:0.5:1;
p=(n+1)*legendre(n+1,0,x)+n*legendre(n-1,0,x);
q=((2*n)+1)*x*legendre(n,0,x);
if p==q then
disp("the first recursion relation is proved")
else
disp("the relation is not proved");
end
end
OUTPUT:
enter value of n
4
II. = + n
INPUT:
clc;
funcprot(0);
n= input("enter value of n");
for n=1:1:5;
x=1;
p=(n*(n+1)-n*(n-1))/2;
q=n*legendre(n,0,x);
if p==q then
disp("the second recursion relation is proved")
else
disp("the relation is not proved");
end
end
OUTPUT:
enter value of n
3
Integral transform of
INPUT:
///Fourier transform
clc;
i=sqrt(-1);
funcprot(0);
function c=f(x)
c=exp((i*(2*i)*x)-x^2); /// =2i
endfunction
a=-999;
b=999;
integral=intg(a,b,f);
disp(integral,"the value of Fourier integral will be")
OUTPUT:
the value of Fourier integral will be
4.8180291