1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Help with a MATLAB assigment.

  1. Nov 27, 2008 #1
    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. jcsd
  3. Nov 28, 2008 #2

    MATLABdude

    User Avatar
    Science Advisor

    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 "Matrices and Arrays" chapter will intro the basics of MATLAB entry.

    Good luck!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Help with a MATLAB assigment.
  1. Matlab help (Replies: 2)

  2. Matlab help (Replies: 2)

  3. Help with matlab (Replies: 7)

  4. MATLAB help (Replies: 2)

Loading...