1. Limited time only! Sign up for a free 30min personal 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!

Homework Help: Use Matlab to plot x(t) for damped system

  1. Jan 31, 2014 #1
    1. The problem statement, all variables and given/known data
    Plot x(t) for a damped system of natural frequency w_n= 2 rad/s and initial conditions x_0= 1 mm and v_0 = o mm/s, for the following values of the damping ratio: z= 0.01, 0.2, 0.6, 0.1, 0.4 and 0.8
    2. Relevant equations

    3. The attempt at a solution

    I began by defining the values of my constants. I realize that z is not a constant per se but I'm not particularly knowledgeable about matlab

    w_n=2; %rad/s
    x_0=1; %mm
    v_0=0; %mm/s
    z= 0.01; %this value varies, thereby changing the response of the plot

    Next I defined the time interval as well as some intermediate variables and the solution to a damped system.


    With the above code I'm told:

    Error using *
    Inner matrix dimensions must agree.

    I spoke to my professor about this and he explained that my exp and sin portions of x were 1x63 and 1x63 matrices, which doesn't work out. I've got the following lines of code which he gave me, but I'm still confused.

    for i=1:63

    Trying to use this code as it is just repeats:

    Error using *
    Inner matrix dimensions must agree.

    Any help would be greatly appreciated
  2. jcsd
  3. Jan 31, 2014 #2

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    Matlab does everything as vectors - this allows for some shortcuts but also means you have to be mindful of the operations.

    The "*" is a matrix inner-product operation.
    I don't think that's what you want.

    I suspect you need the ith term in the result to be the ith term in one vector multiplied by the ith term in another vector.
    For that you use the ".*" (dot-star) operation instead.


    t,u, and v are 1x49 vectors.

    If I now do y=u*v I get an error because the dimensions are wrong for the dot product.
    If I do y=u*v' (making the dimensions right) I get 50.176 ... because that's the dot-product.
    But that's not what I want: I want the amplitude of the sine function to decrease with t.

    This means that I need ##y=(y_1,y_2,\cdots,y_{49}): y_i=u_iv_i##

    To get that I have to do: y=u.*v.
    Last edited: Jan 31, 2014
  4. Jan 31, 2014 #3
    Thank you so much. I'll admit I still don't fully understand. My final code was

    w_n=2; %rad/s
    x_0=1; %mm
    v_0=0; %mm/s
    z=0.8; %this value varies, thereby changing the response of the plot




    Which by changing z for each value produced the graphs I was looking for.
  5. Feb 1, 2014 #4

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    Well done.

    It can take a while to wrap your head around how you do things in these math-script programs, but it's usually worth the effort. All the program is doing is storing your numbers in matrices - so that's what you have to get used to.

    eg. You could have made z into a vector, then the output would be a matrix where each row is for a different z value. I've had to do this where I had about 50-100 such plots to do but you don't have anything like that kind of number so you may as well just do them one at a time like what you did ;)

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

Have something to add?
Draft saved Draft deleted

Similar Threads - Matlab plot damped Date
Plotting with Matlab Feb 18, 2017
Find Fourier transform and plot spectrum by hand & MATLAB Dec 1, 2016
Plotting in Matlab Nov 12, 2016
Matlab plotting Jun 8, 2016
MATLAB question ( plot) Mar 6, 2016