Académique Documents
Professionnel Documents
Culture Documents
Week #3
EXERCISE#01
QUESTION#01
Use the subplot command to provide following three plots in one figure:
CODE
t=-1:0.1:1;
y1=sin(t);
y2=sin(3*t);
y3=sin(5*t);
subplot(3,1,1)
plot(t,y1,'g',t,y2,'b',t,y3,'r')
xlabel('time(sec)')
ylabel('sin(t)')
title('plot1')
legend('sint','sin(3t)','sin(5t)')
c1=cos(t);
c2=cos(3*t);
c3=cos(5*t);
subplot(3,1,2)
plot(t,c1,'g',t,c2,'b',t,c3,'r')
xlabel('time(sec)')
ylabel('cos(t)')
title('plot2')
legend('cost','cos(3t)','cos(5t)')
z1=tan(t);
z2=tan(3*t);
z3=tan(5*t);
subplot(3,1,3)
plot(t,z1,'g',t,z2,'b',t,z3,'r')
xlabel('time(sec)')
ylabel('tan(t)')
title('plot3')
13-EE-131
M. Danish Bilal
C-2
Lab #01
Week #3
legend('tan(t)','tan(3t)','tan(5t)')
OUTPUT
plot1
sin(t)
sint
sin(3t)
sin(5t)
0
-1
-1
-0.8
-0.6
-0.4
-0.2
cos(t)
0.4
0.6
-0.8
-0.6
-0.4
-0.2
20
0
0.2
time(sec)
plot3
0.4
0.6
0.8
0.6
tan(t)
tan(3t)
tan(5t)
0.8
1
0
-20
-1
0.8
cost
cos(3t)
cos(5t)
0
-1
-1
tan(t)
0
0.2
time(sec)
plot2
-0.8
-0.6
-0.4
-0.2
0
0.2
time(sec)
0.4
QUESTION#02
Write a MATLAB function, which takes the following two inputs:
CODE
function [Req]=reqsp(R,F)
R=input('enter vector R for resistance=')
F=input('enter flag for series parallel=')
if(F==1)
Req=sum(R)
else
if(F==2)
13-EE-131
M. Danish Bilal
C-2
Lab #01
Week #3
Req1=sum(1/R)
Req=1/Req1
else
disp('incorrect flag')
end
end
QUESTION#3
Define the symbolic variable x. Make use of this variable to define the symbolic function
sin(1/x). Then, plot the function from 0 to 2. What do you see? Why might the plotting routine be
having trouble plotting this function?
CODE
syms x;
y=sin(1/x);
ezplot(y)
axis([0 2 -2 2])
OUTPUT
13-EE-131
M. Danish Bilal
C-2
Lab #01
Week #3
sin(1/x)
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
0.2
0.4
0.6
0.8
1
x
1.2
1.4
1.6
1.8
QUESTION#04
The natural response of a series RC circuit is given by
V(t) = V0 e-t /RC
Write a MATLAB function that takes two inputs R and C, and plots the natural
response of this circuit for t [0,2]
CODE
function v=rc(r,c)
r=input('enter the value of r=')
c=input('enter the value of c=')
t=0:0.1:2;
vo=100;
v= vo.*exp(-t./r*c);
plot(t,v,'b*-')
xlabel('time(sec)')
ylabel('voltage(V)')
title('natural respnse of rc series circuit')
13-EE-131
M. Danish Bilal
C-2
Lab #01
Week #3
OUTPUT
natural respnse of rc series circuit
100
90
80
voltage(V)
70
60
50
40
30
20
10
13-EE-131
0.2
0.4
0.6
0.8
1
1.2
time(sec)
1.4
M. Danish Bilal
1.6
1.8
C-2