# Help with a MATLAB assigment.

1. Nov 27, 2008

### wiz0r

Ok, so what I need to do is;

Given the functions;

x1(t)= tu(t)-tu(t-1) and x2(t)=10e^-4tu(t), do the following:

1. Plot x1(t) and x2(t) using MATLAB.
2. Use MATLAB to find and plot x(t)=x1(t)* x2(t), where * denotes convolution.
3. Find x(t)=x1(t)* x2(t) by hand using Laplace transforms.
4. Plot the result of part 3 in MATLAB and compare it to that found in part 2.

Okay, what I had trouble was defing u(t). Since, according to my book it says that u(t) = 0 if t<0, and u(t) = 1 if t>0. Also that; u(t-1) = 1 if 1<t<infinite, and u(t-1) = 0 if t<1. So,
what I tried to do was to define the two functions, one would be u(t) and the other u(t-1). So, I had two functions(m.files) named, u, and v. v being u(t-1). So, I would use them on my original program. the two function would look like;

u(t) =

Code (Text):
function u = u(t)

if t > 0
u = 1;
else
u = 0;
end
v(t) = u(t-1)

Code (Text):
function v = v(t)
if t > 1
v = 1;
else
v = 0;
end
my original program would look like;

Code (Text):
t = 0:0.1:10;
x1 = t*u - t*v;
x2 = 10*exp(-4*t)*u;
plot(t,x1)
plot(t,x2)
y = conv(x1,x2);
plot(t,y)
return;
I really thought that would work, but bleh, it doesn't. Can anyone help me telling me what's wrong?

PS: I have no experience programming with MATLAB. I only know very basic C. So, yeah, please bare with me.

Edwin

2. Nov 28, 2008

### MATLABdude

You can't define a function as you've done (well, it can be used to return values, but all it'll do is return values, you can't do operations on these, or on symbolic functions in general). What you need to do is define a vector (a.k.a. 1-D array) with x (or, in this case, t) values, and then evaluate the function at each of these points, producing a second vector with your function values.

If you do this for u and v, you'll then be able to convolve them.

As you're just starting out, here's probably the most helpful MATLAB command: help

help conv would bring up the documentation (including the expected inputs, and examples of use) for the conv function.

Also, if you've got nothing in the way of MATLAB orientation / intro from your class, here's the MATLAB documentation website / online help (link goes to the "Getting Started in MATLAB" document):
http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/bqr_2pl.html

If you know absolutely nothing about MATLAB, the http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/f2-8955.html" [Broken] chapter will intro the basics of MATLAB entry.

Good luck!

Last edited by a moderator: May 3, 2017