B.Sc Physics 4th Semester Scilab Programmes

1. Dirac Delta Function

Scilab Code

funcprot(0)
function y=dirac(x)
    y=(1/sqrt(2*(%pi)*(sigma^2)))*(%e)^(-((x-2)^2)/(2*(sigma^2)))*(x+3);
endfunction
sigma=0.1
I=intg(-3,3,dirac)
disp(I)
image 10

Output

image 8

2. Ordinary Differential Equation(ODE)

2.1 First order ODE

Aim of the Experiment

  To solve the differential equation dy/dx =exp(x), with y(x=0)=0 Using Scilab.

Apparatus Required

  1. Computer
  2. Scilab Software 
  3. Printer

Scilab Code

function yprime=f(x, y);
    yprime=exp(x);
endfunction
x0=0;
y0=0;
x=x0:1:25;
y=ode(y0,x0,x,f);
disp(y,"y(0)=");
plot(x,y)
xlabel("x","fontsize",2);
xlabel("y(x)","fontsize",2);
title("dy/dx=exp(x), y(0)=0","fontsize",5,"color","green")
image 13

Output

image 9

2.2 Second Order ODE

Aim of the Experiment

To solve the differential equation d2y/dx2 +exp(-x) dy/dx =-y with y(x=0)=0;y'(x=0)=1.

Apparatus required

  1. computer
  2. Scilab Software
  3. Printer

Scilab Code

2nd ode3

Output

2nd order d.e graph 1

Fourier Coefficients

Scilab Code

funcprot(0)
function [a0, A, B]=fourier(l, n, f)
a0=1/l*intg(-l,l,f,.000000001);
for i=1:n
function b=f1(x, f)
b=f(x)*cos(i*%pi*x/l)
endfunction
function c=f2(x, f)
c=f(x)*sin(i*%pi*x/l)
endfunction
A(i)=1/l*intg(-l,l,f1,.000000001)
B(i)=1/l*intg(-l,l,f2,.000000001)
end
endfunction
scilab

Output

image 3
physicsbykk.com
http://physicsbykk.com

Leave a Reply