You are on page 1of 18

 = e-x

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:

0 0.0951626 0.1812692 0.2591818 0.3296799 0.3934693 0.4511883 0.5034147 0.550671


0.5934303 0.6321206 0.6671289 0.6988058 0.7274682 0.7534031 0.7768699 0.7981035
0.8173165 0.8347011 0.8504314 0.8646647 0.8775436 0.8891968 0.8997411 0.909282
0.917915 0.9257264 0.9327945 0.9391899 0.9449768 0.9502129 0.9549508 0.9592378
0.9631168 0.9666267 0.9698026 0.9726762 0.9752764 0.9776292 0.979758 0.9816843
0.9834273 0.9850044 0.9864314 0.9877226 0.9888909 0.9899481 0.9909046 0.9917702
0.9925533 0.993262
 = x2-ye-x

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:

-0.4896668 -0.5168011 -0.5387308 -0.5552487 -0.5661999 -0.5714838 -0.5710549


-0.5649233 -0.5531553 -0.5358722 -0.5132496 -0.4855158 -0.4529492 -0.415876
-0.3746671 -0.3297341 -0.2815255 -0.2305223 -0.1772333 -0.1221898 -0.0659407
-0.0090468 0.0479247 0.1044059 0.1598336 0.2136552 0.2653341 0.3143549 0.3602291
0.4024989 0.4407431 0.4745803 0.503673 0.5277311 0.5465149 0.5598372 0.5675651
0.5696218 0.5659871 0.5566975 0.541846 0.5215812 0.4961056 0.4656738 0.43059
0.3912047 0.3479114 0.3011428 0.251366 0.1990785 0.1448025 0.0890804 0.0324689
-0.0244664 -0.0811568 -0.1370358 -0.1915452 -0.2441404 -0.2942959
-0.3415106 -0.3853128
 + =- y

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:

0.0732626 0.067948 0.0629814 0.0583448 0.0540203 0.0499905 0.0462384 0.0427478


0.0395028 0.0364883 0.0336897 0.0310934 0.0286861 0.0264554 0.0243895 0.0224772
0.020708 0.019072 0.0175598 0.0161627 0.0148725 0.0136815 0.0125825 0.0115687 0.010634
0.0097724 0.0089784 0.0082471 0.0075737 0.0069537 0.0063832 0.0058582
0.0053754 0.0049314 0.0045233 0.0041481 0.0038034 0.0034868 0.0031959 0.0029289
0.0026837 0.0024587 0.0022522 0.0020627 0.0018889 0.0017295 0.0015833 0.0014493
0.0013265 0.0012139 0.0011107 0.0010162 0.0009296 0.0008502 0.0007776 0.0007111
0.0006502 0.0005945 0.0005434 0.0004967 0.000454
 Plotting

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:

 Evaluate )dx , σ =1,0.1,0.01 and show it tend to 5

 σ =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:

0. 0.0182073 0.0409417 0.0690185 0.1033159 0.1447587 0.1942961 0.2528741


0.3214026 0.4007184 0.4915459 0.5944557 0.7098257 0.8378046 0.9782813
1.1308627 1.2948615 1.4692954 1.6528991 1.8441486 2.041298 2.2424269
2.4454962 2.6484096 2.8490789 3.0454873 3.2357501 3.4181681 3.5912718
3.7538544 3.9049933 4.0440578 4.1707059 4.2848693 4.3867295 4.4766867
4.555323 4.6233639 4.6816386 4.7310417 4.7724987 4.8069346 4.8352485
4.8582927 4.8768581 4.8916637 4.9033514 4.9124845 4.9195492 4.9249587
4.929059 4.9321355 4.9344205 4.9361006 4.9373234 4.9382045 4.9388329
4.9392765 4.9395866 4.9398012 4.9399481 4.9400478 4.9401146 4.9401591
4.9401883 4.9402073 4.9402196 4.9402274 4.9402324 4.9402355 4.9402374
4.9402386 4.9402393 4.9402397 4.94024 4.9402401 4.9402402 4.9402402
4.9402403 4.9402403 4.9402403 tends to 5
 σ =0.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:
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

2) Evaluate the Fourier coefficients of a given periodic function(square wave)


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)

first Fourier coefficient (a0)

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

 Frobenius method and special functions


1. =

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

enter the value of n =


4
enter the value of m =
3

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:

3. Show recursion relation


I. (n+1) + n = (2n+1)x

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

the first recursion relation is proved


the first recursion relation is proved
the first recursion relation is proved
the first recursion relation is proved
the first recursion relation is proved

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

the second recursion relation is proved


the second recursion relation is proved
the second recursion relation is proved
the second recursion relation is proved
the second recursion relation is proved

 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

Theoretically the Fourier transform of is


= 2i gives the value of the Fourier transform = 4.81802909

You might also like