You are on page 1of 14

NAME: TANUJ SARKAR

SCHOLAR ID:2123022
BRANCH: EE(A)

ASSIGNMENT: 2
1. Write a program to plot y1(t) vs t for y1(t) = sin(2πt/10), t = 1 : 0.01 : 20.
t=1:0.01:20;
y=sin(2*pi*t/10);
plot(y,t)

2. Write a program to plot the function y1(t) and y2(t) on the same figure with same scale. Find
out and plot their resultant wave forms after addition and subtraction also. Where y1(t) is same
as (1) and y2(t) = cos(2πt/10), t = 1 : 0.01 : 20. Insert title, axes labels and legends in the plots.
Find the use of “grid” command.
t=1:0.01:20;
y1=sin(2*pi*t/10);
plot(t,y1)

hold on
y2=cos(2*pi*t/10);

plot(t,y2)

title('Program Plot')
xlabel('value')
ylabel('time')

legend('sin(2*pi*t/10)','cos(2*pi*t/10)')

hold off
a=y1-y2;
plot(t,a)
hold on

b=y1+y2;
plot(t,b)
title('Program Plot')
xlabel('value')

ylabel('time')
legend('a','b')
grid on
3. Plot y1(t) and y2(t) separately in the same figure using ‘subplot’ command. Plot them in
different figures with title and labels of different axes.
t=1:0.01:20;
y1=sin(2*pi*t/10);
y2=cos(2*pi*t/10);

subplot(2,2,1)
plot(t,y1,'r')
subplot(2,2,2)
plot(t,y2,'b')
4. Plot y1(t) and y2(t) in 3-D boxes considering y1(t) in x axis, y2(t) in z-axis with t = −10 : 0.1 :
10.

t=-10:0.1:10;
y1=sin(2*pi*t/10);
y2=cos(2*pi*t/10);
plot3(y1,t,y2)

grid on
5. Generate a unit step function using “stepfun”. Generate a unit gate function between t = 4
and t = 8.

t=0:0.00001:8;
u=stepfun(t,4);
plot(t,u)

6. Write a program to generate a ramp function with a slope of tan(θ) = tan(300 ).


t=-10:1:10;
ramp_t = (t>=0).*t/(3^0.5);

plot(t,ramp_t,'linewidth',2.5)
grid on
7. Generate the curves of the following equations:

a) x.sin(x)
x=-10:0.001:10;
y=x.*sin(x);
plot(x,y)
b) x^(2).sin(x^2 )
x=-10:0.001:10;

y=(x.^2).*sin(x.^2);
plot(x,y)
c) e^(x) .sin(x)
x=-10:0.001:10;

y=exp(x).*sin(x);
plot(x,y)
axis([-10 10 -10000 10000])
d) e ^(−x) .sin(x)
x=-10:0.001:10;

y=exp(-x).*sin(x);
plot(x,y)
8. Generate the following functions and display

a)
t= 0:0.5:5;
y=(t.*stepfun(t,0))+((-t+2).*stepfun(t,2));
plot(t,y)

b)

t=0:0.5:5;
y=(2*t.*stepfun(t,0))+(2*(-t+2).*stepfun(t,2))+(2*(-t+2).*stepfun(t,2))+(2*(t+4).*stepfun(t,4))-
(16*stepfun(t,4));
plot(t,y)
c)
t=0:0.01:5;

y=stepfun(t,2)+stepfun(t,4);
plot(t,y)
d)
t=0:0.01:20;

y=((0.58)*t.*stepfun(t,0))+(2);
plot(t,y)

You might also like