Matlab Workspace
Matlab Workspace
syms t;
2. How is func stored in MATLAB workspace? (That is, what do you see if you type
syms t;
func= sin(2*pi*t)
func =
3. How is func stored in MATLAB workspace? (That is, what do you see if you type
Explanation:- func is stored in matlab as a normal function with independent variable t instead of storing an
array/value.
the variable t. Type help subs to see how to numerically evaluate the symbolic
subs(func,t,0.25)
ans =
Explanation: The subs function will return the value of the given input function by substituting the given input
parameter in the place of the given input variable. Here, my function in func as defined before and i want to
substitute 0.25 in the place of t. Now the subs function returned the value of func at t=0.25 which is 1.
t1= -1:0.01:1;
subs(func,t,t1)
ans =
1
2
6. Type help int to learn about numerical integration. Use int() to evaluate the integralof func and func2 over one
period. Verify the correctness of the results using pen-and-paper calculation.
y1=int(func,t,0,1);
disp(y1);
y2=int(func*func,t,0,1);
disp(y2);
Example 1
1. Using the heaviside function create a signal x(t) = u(t) − u(t − 1).
3. Plot the signals x(t) and h(t). (Use subs to evaluate and then plot the function).
4. Obtain y(t) = x(t) ∗ h(t) by using the formula for convolution. Note that in the
formula for convolution there are two variables. Hence clearly specify the variable of
5. Using subplot, plot x(t), h(t) and y(t) on the same graph and show the plot to the
TA.
syms t;
x(t)=heaviside(t)-heaviside(t-1);
h(t)=heaviside(t)-heaviside(t-1);
syms t1;
y(t)=int(x(t1)*h(t-t1),t1,[0,2]);
subplot(1,3,1)
plot(0:0.001:1,subs(x(t),t,0:0.001:1))
subplot(1,3,2)
plot(0:0.001:1,subs(h(t),t,0:0.001:1))
subplot(1,3,3)
plot(0:0.001:2,subs(y(t),t,0:0.001:2))
3
Example 2
2. Using subplot, plot the signals x1(t), h1(t) and y1(t) = x1(t) ∗ h1(t).
syms t
syms t2
x1(t)=heaviside(t)-heaviside(t-1);
h1(t)=heaviside(t-1)-heaviside(t-3);
y1(t)=int(x1(t2)*h1(t-t2),t2,[1,4]);
subplot(3,1,1)
plot(0:0.001:1,subs(x1(t),t,0:0.001:1))
subplot(3,1,2)
plot(1:0.001:3,subs(h1(t),t,1:0.001:3))
subplot(3,1,3)
plot(0:0.001:4,subs(y1(t),t,0:0.001:4))
4
Example 3
2. Using subplot, plot the signals x2(t), h2(t) and y2(t) = x2(t) ∗ h2(t) for
−10 ≤ t ≤ 10.
syms t;
syms t3;
x2(t)=exp((-2*t))*heaviside(t);
h2(t)=heaviside(t);
y2(t)=int(x2(t3)*h2(t-t3),t3,[0,10]);
subplot(3,1,1)
plot(0:0.001:1,subs(x2(t),t,0:0.001:1))
subplot(3,1,2)
plot(1:0.001:3,subs(h2(t),t,-1:0.001:1))
subplot(3,1,3)
plot(-10:0.001:10,subs(y2(t),t,-10:0.001:10))
5
Example 4
1. Using subplot, plot the signals x3(t), h3(t) and y3(t) = x3(t) ∗ h3(t) for
−10 ≤ t ≤ 10.
syms t;
syms t3;
x3(t)=t*(heaviside(t)-heaviside(t-2));
h3(t)=heaviside(t+1)-heaviside(t-1);
y3(t)=int(x3(t3)*h3(t-t3),t3,[0,10]);
subplot(3,1,1)
plot(0:0.001:2,subs(x3(t),t,0:0.001:2))
subplot(3,1,2)
plot(-2:0.001:2,subs(h3(t),t,-2:0.001:2))
subplot(3,1,3)
plot(-10:0.001:10,subs(y3(t),t,-10:0.001:10))
6
7