Professional Documents
Culture Documents
1. plot of Sin(x)
-->x=[0:0.1:2*%pi];
--> y=sin(x);
-->plot2d(x,y,xtitle("plot sin(x)"),xlabel("angles"))
sol--
2. plot of cos(x)
--> x=[0:0.2:4*%pi];
-->y=cos(x);
-->plot2d(x,y,xtitle("plot cos(x)"),xlabel("angles"))
sol--
1
3. plot of tan(x)
-->x=[0:0.2:4*%pi];
-->y=tan(x);
-->plot2d(x,y,xtitle("plot tan(x)"),xlabel("angles"))
sol--
4. plot of Cosec(x)
2
-->x=[0:0.2:4*%pi];
-->y=csc(x);
plot2d(x,y,xtitle("plot cosec(x)"),xlabel("angles"))
sol--
5. plot of sec(x)
--> x=[0:0.2:4*%pi];
-->y=sec(x);
-->plot2d(x,y,xtitle("plot sec(x)"),xlabel("angles"))
sol--
3
6. plot of cot(x)
-->x=[0:0.2:4*%pi];
-->y=cotg(x);
-->plot2d(x,y,xtitle("plot cot(x)"),xlabel("angles"))
sol—
4
7. plot of (x^2)
-->x=[-4*%pi:0.1:4*%pi];
-->y=x^2;
-->plot2d(x,y,xtitle("plot x^2"))
sol—
5
8. plot of (x^2+exp(x))
-->x=[-4*%pi:0.1:4*%pi];
-->y=x^2+exp(x);
sol—
6
Aim-- FINDTHE DERIVATIVEOF THEGIVEN FUNCTIONUSING MATLAB
1. Differentiate x^2+4*x-5
>> Syms x
>> Y=x^2+4*x-5;
>> diff(Y)
ans =
2*x + 4
2. Differentiate (7*x^2+4*x)^3-6*x^2
>> Syms x
>> Y=(7*x^2+4*x)^3-6*x^2;
>> diff(Y)
ans =
3. Differentiate sin(x)+cos(x))/tan(x^2)
>> Syms x
>> Y=(sin(x)+cos(x))/tan(x^2);
>> diff(Y)
7
ans =
4. Differentiate tan(4*x)*sin(x)
>> Syms x
>> Y=tan(4*x)*sin(x);
>> diff(Y)
ans =
tan(4*x)*cos(x) + sin(x)*(4*tan(4*x)^2 + 4)
5. Differentiate exp(6*x)+exp(3)
>>Syms x
>> Y=exp(6*x)+exp(3);
>> diff(Y)
ans =
6*exp(6*x)
6. Differentiate exp(x^3)/exp(x^2);
>> Syms x
>> Y=exp(x^3)/exp(x^2);
>> diff(Y)
8
ans =
(3*x^2*exp(x^3))/exp(x^2) - (2*x*exp(x^3))/exp(x^2)
7. Differentiate 4*log(x^2)
>> Syms x
>> Y=4*log(x^2);
>> diff(Y)
ans =
8/x
8. Differentiate log(x)/3*log(x^3)
>> Syms x
>> Y=log(x)/3*log(x^3);
>> diff(Y)
ans =
log(x)/x + log(x^3)/(3*x)
9. Differentiate (cos(x)-log(x^2))/4*x
>> Syms x
>> Y=(cos(x)-log(x^2))/4*x;
>> diff(Y)
9
ans =
>> Syms x
>> Y=((tan(4*x))^2)/exp(x^3);
>> diff(Y)
ans =
10
Aim-- solvethefirst orderordinary differential equations
function dx=f(x, y)
dx=-(y^2+1)/(x^2+1)
endfunction
y0=0;
x0=0;
x=[0:0.1:%pi];
sol = ode(y0,x0,x,f);
disp(sol,"answer")
plot2d(sol)
11
output plot is
function dx=f(x, y)
dx=-(x+2*y)/(2*x+y)
endfunction
y0=4;
x0=1;
x=[2 4 6 8 10];
sol = ode(y0,x0,x,f);
disp(sol,"answer")
plot2d(sol)
12
output plot is
function dx=f(x, y)
dx=(x*y+x)/(x^2*y^2+x^2+y^2+1);
endfunction
y0=3;
x0=0;
x=[2 4 6 8 10];
sol = ode(y0,x0,x,f);
disp(sol,"answer")
plot2d(sol)
output plot is
13
3.
4. Solve the ODE y’=x*tan(y-x)+1
function dx=f(x, y)
dx=x*tan(y-x)+1;
endfunction
y0=0;
x0=0;
x=[2 4 6 8 10];
sol = ode(y0,x0,x,f);
disp(sol,"answer")
plot2d(sol)
14
output plot is
function dx=f(x, y)
dx=(1-3*x*y)/y^2;
endfunction
y0=2;
x0=0;
x=[2 4 6 8 10];
sol = ode(y0,x0,x,f);
disp(sol,"answer")
plot2d(sol)
15
output plot is
function dx=f(x, y)
dx=(3*x^2*y+(y/x))/x^3+log(x);
endfunction
y0=0;
x0=2;
x=[2 4 6 8 10];
sol = ode(y0,x0,x,f);
disp(sol,"answer")
plot2d(sol)
output plot is
16
Aim-- solvethesecond orderordinary differential equations for
for solving second order differential equation ,first we put the value for y and y’ i.e,
x(1)=y ...(1)
x(2)=y’ ...(2)
then put the value of dx(1) and dx(2) in the terms of x(1) and x(2)
i.e,dx(1)=x(2) and for dx(2) ,we find the value for y’’ from our main differential
equation.
Then writing the commands for solving the ode in scilab as given examples
function dx=f(t,x)
dx(1)=x(2);
dx(2)=x(1);
endfunction
t=[1:0.1;5];
sol = ode([6,-1],0,t,f);
disp(sol,"answer")
plot2d(sol)
17
answer
371.05662 371.00945
Output plot is
function dx=f(t,x)
dx(1)=x(2);
dx(2)=2*x(2)-5*x(1);
endfunction
t=[1:0.5:3];
sol = ode([3,-1],0,t,f);
18
disp(sol,"answer")
plot2d(sol)
answer
column 1 to 6
column 7 to 10
Output plot is
19
3.solve the ode for y’’+5y+12.5y=0
function dx=f(t,x)
dx(1)=x(2);
dx(2)=-5*x(2)-12.5*x(1);
endfunction
t=[1:0.5:3];
sol = ode([0,5],0,t,f);
disp(sol,"answer")
plot2d(sol)
answer
Output plot is
20
4. solve the ode y’’-y’-12y=0
for y(0)=3 , y’(0)=5
function dx=f(t,x)
dx(1)=x(2);
dx(2)=x(2)+12*x(1);
endfunction
t=[1:0.5:2];
sol = ode([3,5],0,t,f);
disp(sol,"answer")
plot2d(sol)
answer
output plot is
21
5. solve for ode 16y’’-8y’+y=0
for y(0)=1 , y’(0)=4
function dx=f(t,x)
dx(1)=x(2);
dx(2)=(8*x(2)-x(1))/16;
endfunction
t=[1:0.5:2];
sol = ode([1,4],0,t,f);
disp(sol,"answer")
plot2d(sol)
answer
Output plot is
22
convert second order differential eqn. With variable coefficient to constant
coefficient manually by Cauchy euler and legendrie equation method.
Then solve them on scilab same as above.
function dx=f(t,x)
dx(1)=x(2);
dx(2)=4*x(2)-3*x(1);
endfunction
t=[1:0.5:2];
sol = ode([0,-2],1,t,f);
disp(sol,"answer")
plot2d(sol)
answer
0. -2. -2.8329679 -11.796346 -17.367257 -57.538334
23
2.solve the ode for (2x+5)^2y’’-6(2x+5)y’+8y=0
By legendrie equation y’’-4y ‘+2y=0
function dx=f(t,x)
dx(1)=x(2);
dx(2)=4*x(2)-2*x(1);
endfunction
t=[1:0.5:2];
sol = ode([2,4],1,t,f);
disp(sol,"answer")
plot2d(sol)
answer
output plot is
24
Aim-- evaluatethelaplacetransformin matlab
>> syms t
>> f=sin(t);
>> L=laplace(f)
>>ezplot(L)
Ans
L=
25
1/(s^2 + 1)
Output plot
>> ezplot(L)
>> syms t
>> f=cos(t);
>> L=laplace(f)
Ans
L=
s/(s^2 + 1)
>>ezplot(L)
26
3. evaluate the L.T. of t^3
>> syms t
>> f=t^3;
>> L=laplace(f)
Ans
L=
6/s^4
>>ezplot(L)
27
Output plot is
>> ezplot(L)
>> syms t
>> f=exp(3*t);
>> L=laplace(f)
Ans
L=
1/(s - 3)
Output plot
28
5. evaluate the L.T. of cosh(3*t)+exp(4*t)
>> syms t
>> f=cosh(3*t)+exp(4*t);
>> L=laplace(f)
Ans
L=
1/(s - 4) + s/(s^2 - 9)
29
>> ezplot(L)
output plot is
L=
Output plot is
>> ezplot(L)
30
2. evaluate the I.L.T. of s/(s2+36)
>> syms s
>> f=s/(s^2+36);
>> L=ilaplace(f)
Ans
L=
cos(6*t)
31
output plot is
>> ezplot(L)
Ans
L=
cos(4*t)/exp(t)
output plot is
>> ezplot(L)
32
4. evaluate the I.L.T. of f=(2*s+1)/(s^2-4)
>> syms s
>> f=(2*s+1)/(s^2-4);
>> L=ilaplace(f)
Ans
L=
3/(4*exp(2*t)) + (5*exp(2*t))/4
Output plot is
>> ezplot(L)
33
5. evaluate the I.L.T. of f=s/(s^2-4)
>> syms s
>> f=s/(s^2-4);
>> L=ilaplace(f)
Ans
L=
34
1/(2*exp(2*t)) + exp(2*t)/2
Output plot is
>> ezplot(L)
35
1.evaluate the Fourier coefficient for f(x) =0 , -pi<x<0
=x2, 0<x<pi
In editor window:-
function[ao an bn]=Fourier_c()
syms pi x n
disp('enter the function')
f=input('f=');
ao=simplify((int(f,0,pi)/pi))
an=simplify((int(f*cos(n*x),0,pi)/pi))
bn=simplify ((int(f*cos(n*x),0,pi)/pi))
end
f=x^2
ao =
pi^2/3
an =
(pi^2*n^2*sin(pi*n) - 2*sin(pi*n) + 2*pi*n*cos(pi*n))/(pi*n^3)
bn =
(pi^2*n^2*sin(pi*n) - 2*sin(pi*n) + 2*pi*n*cos(pi*n))/(pi*n^3
36
2. compute the fourier coefficient of function f(x)=x , interval 0 – 2*pi.
>> syms x n pi
>> f=x;
>> ao=(1/2*pi)*int(f,0,2*pi)
ao =
pi^3
>> f=x*cos(n*x);
>> an=(1/pi)*int(f,0,2*pi)
an=
-(2*sin(pi*n)^2 - 2*pi*n*sin(2*pi*n))/(pi*n^2)
>> f=x*sin(n*x);
>> bn=(1/pi)*int(f,0,2*pi)
bn=
(sin(2*pi*n) - 2*pi*n*cos(2*pi*n))/(pi*n^2)
3.compute the coefficient of F.S of f(x)=(pi -x)/2 0<x<2*pi
>> syms x n pi
>> % computing ao
>> f=(pi-x)/2;
>> ao=(1/pi)*int(f,0,2*pi)
ao =
37
>> % computing an
>> f=((pi-x)/2)*cos(n*x);
>> an=(1/pi)*int(f,0,2*pi)
an =
(sin(pi*n)^2 - (pi*n*sin(2*pi*n))/2)/(pi*n^2)
>> % computing bn
>> f=((pi-x)/2)*sin(n*x);
>> bn=(1/pi)*int(f,0,2*pi)
bn =
-(cos(pi*n)*(sin(pi*n) - pi*n*cos(pi*n)))/(pi*n^2)
>> syms x n pi
>> % computing ao
>> f=x^3*sin (x);
>> ao=(1/pi)*int(f,0,2*pi)
ao =
(12*pi - 8*pi^3)/pi
38
>> % computing an
>> f=(x^3*sin (x))*cos(n*x);
>> an=(1/pi)*int(f,0,2*pi)
an =
int(x^3*cos(n*x)*sin(x), x = 0..2*pi)/pi
>> % computing bn
>> f=(x^3*sin (x))*sin(n*x);
>> bn=(1/pi)*int(f,0,2*pi)
bn =
int(x^3*sin(n*x)*sin(x), x = 0..2*pi)/pi
>> syms x n pi
>> f=4*(x^3);
>> % computing ao
>> ao=(1/pi)*int(f,0,2*pi)
ao =
16*pi^3
39
>> % computing an
>> f=4*(x^3)*cos(n*x);
>> an=(1/pi)*int(f,0,2*pi)
an =
>> % computing bn
>> f=4*(x^3)*sin(n*x);
>> bn=(1/pi)*int(f,0,2*pi)
bn =
40
1.evaluate the F.T. of sin(x)
>> syms x
>> f=sin(x);
>> F=fourier(f)
F=
>> syms x
>> f=cos(x);
>> F=fourier(f)
F = pi*(dirac( w - 1) + dirac(w+1))
>> syms x
>> f=exp(i*x);
>> F=fourier(f)
F=
2*pi*dirac(1 - w)
41
>> syms x
>> f=exp(-abs(x));
>> F=fourier(f)
F=
2/(w^2 + 1)
>> ezplot(F)
>> syms x
>> f=dirac(x);
>> F=fourier(f)
F=
42
>> ezplot(F)
` ~~~ `
43