You are on page 1of 43

aim -- Plot different functionsusing differentplotsyntaxes

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);

-->plot2d(x,y,xtitle("plot 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*(14*x + 4)*(7*x^2 + 4*x)^2 - 12*x

3. Differentiate sin(x)+cos(x))/tan(x^2)

>> Syms x

>> Y=(sin(x)+cos(x))/tan(x^2);

>> diff(Y)

7
ans =

(cos(x) - sin(x))/tan(x^2) - (2*x*(tan(x^2)^2 + 1)*(cos(x) + sin(x)))/tan(x^2)^2

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 =

cos(x)/4 - log(x^2)/4 - x*(sin(x)/4 + 1/(2*x))

10. Differentiate (( tan(4*x))^2)/exp(x^3);

>> Syms x
>> Y=((tan(4*x))^2)/exp(x^3);

>> diff(Y)

ans =

(2*tan(4*x)*(4*tan(4*x)^2 + 4))/exp(x^3) - (3*x^2*tan(4*x)^2)/exp(x^3)

10
Aim-- solvethefirst orderordinary differential equations

1. Solve the ODE y’ = -(y^2+1)/(x^2+1)

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

2. Solve the ODE y’=-(x+2*y)/(2*x+y)

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

3. Solve the ODE y’=(x*y+x)/(x^2*y^2+x^2+y^2+1)

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

5. Solve the ODE y’=(1-3*x*y)/y^2

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

6. Solve the ODE y’=(3*x^2*y+(y/x))/x^3+log(x)

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

a) constant coefficient and


b) variablecoefficient

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 differentiate both the eqn. i.e,


dx(1)=y ‘
dx(2)=y’’

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

solve the ode y’’-y=0


for y(0)=6 , y’(0)=-1

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

solve ode for y’’-2y’+5y=0

for y(o)=3 , y’(0)=-1

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

-8.3370677 -18.642611 -14.575429 -0.622806 -3.3053134 49.566269

column 7 to 10

33.731326 90.001009 69.081035 25.612126

Output plot is

19
3.solve the ode for y’’+5y+12.5y=0

For y(0)=0 , y’(0)=5

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

0.0982512 -0.5744373 -0.0268837 -0.0292794 -0.0129224 0.0418624 -0.0001281


0.0099672
0.0010376 -0.0016354

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

109.24613 436.63599 806.8691 3227.3986 5961.9223 23847.672

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

6.0991207 6.3398755 9.6393181 7.8660473 14.014134 9.6862385

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.

1. solve the ode x^2*y’’-3*x*y’+3*y=0


for y(1)=0 , y’(1)=-2
by Cauchy euler eqn. Y’’-4y’+3y=0

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

2. 4. 6.8532901 19.607656 32.189456 104.82068

output plot is

24
Aim-- evaluatethelaplacetransformin matlab

1.evaluate the L.T. of sin (t)

>> syms t
>> f=sin(t);
>> L=laplace(f)
>>ezplot(L)

Ans

L=

25
1/(s^2 + 1)

Output plot

2. evaluate the L.T. of cos (t)

>> 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

4. evaluate the L.T. of e3t

>> 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

1. evaluate the I.L.T. of 3/s


>> syms s
>> f=3/s;
>> L=ilaplace(f)
Ans

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)

3. evaluate the I.L.T. of f=(s+1)/((s+1)^2+16)


>> syms s
>> f=(s+1)/((s+1)^2+16);
>> L=ilaplace(f)

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)

Aim-- evaluatetheFOURIERSERIESin matlab

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

Run in command window:-

enter the function

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)

4. compute the co-efficient of F.S of f(x)=x^3*sin(x) 0<x<2*pi

>> 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

5. Compute the co-efficient of F.S for f(x)=tan(x) 0<x<2*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 =

(4*(12*sin(pi*n)^2 + 8*pi^3*n^3*sin(2*pi*n) - 12*pi^2*n^2*(2*sin(pi*n)^2 - 1) -


12*pi*n*sin(2*pi*n)))/(pi*n^4)

>> % computing bn
>> f=4*(x^3)*sin(n*x);
>> bn=(1/pi)*int(f,0,2*pi)

bn =

-(4*sin(2*pi*n)*(6/n^4 - (12*pi^2)/n^2) - 4*cos(2*pi*n)*((12*pi)/n^3 - (8*pi^3)/n))/pi

Aim-- evaluatetheFOURIERtransformin matlab

40
1.evaluate the F.T. of sin(x)

>> syms x
>> f=sin(x);
>> F=fourier(f)

F=

pi*(dirac(- w - 1) - dirac(1 - w))*i

2.evaluate the F.T. of cos (x)

>> syms x
>> f=cos(x);
>> F=fourier(f)

F = pi*(dirac( w - 1) + dirac(w+1))

3.evaluate the F.T. of exp (jx)

>> syms x
>> f=exp(i*x);
>> F=fourier(f)

F=

2*pi*dirac(1 - w)

4.evaluate the F.T. of exp (-abs(x))

41
>> syms x
>> f=exp(-abs(x));
>> F=fourier(f)

F=

2/(w^2 + 1)

>> ezplot(F)

5.evaluate the F.T. of δ (x)

>> syms x

>> f=dirac(x);

>> F=fourier(f)

F=

42
>> ezplot(F)

` ~~~ `

43

You might also like