1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Mathematical bretheren, lend me your brains

Discussion in 'Members' Lounge' started by GSRCRXsi, Feb 8, 2008.

  1. GSRCRXsi

    GSRCRXsi Super Moderator Moderator VIP

    Messages:
    9,623
    Likes Received:
    345
    Joined:
    Nov 13, 2002
    Location:
    MD
    ok so i have this homework in my Automatic controls class. i understand the concepts but for whatever reason i just cant get this problem to work out. i think its a problem with my modeling but im not sure. this is basically a system response problem. where i have some masses suspended by springs and dampers. the objective is to come out with the funtions for y1, and y2 (the displacements of the blocks where positive is downward) where i have 2 inputs u1 and u2 which will be constant forces. when i run it in matlab, im getting propagation rather than dampening, which is obviosly wrong. also since its multiple input (and linear) i have to treat this system as 2 single inputs working with the applied forces seperately and then adding them together in the end. the steps ive followed from my example are straight forward although it was only for a single input.

    step 1: Identify input/output relationships
    step 2: draw the FBD in the time domain
    step 3: draw the FBD in the s domain (La Place transform)
    step 4: arrange the equations
    step 5: put them in matrix format
    step 6: apply cramers rule to get the transfer funtions
    step 7: go into matlab for the simulation and plots of y1, y2

    heres my work along with the matlab code:

    Code:
    % HW #2 - Problem #1
    
    %Coefficients
    m1=4;
    m2=7;
    k1=4.2;
    k2=5.7;
    b1=3.2;
    
    % DEN(s) 
    aden=m1*m2;
    bden=m1*b1+m2*b1;
    cden=m1*k1+m2*k1;
    dden=k1*b1+k2*b1;
    eden=k1*k2;
    den=[aden bden cden dden eden];
    
    %NUM_11(s)
    anum_11=m2;
    bnum_11=b1;
    cnum_11=k2;
    num_11=[anum_11 bnum_11 cnum_11];
    
    %NUM_21(s)
    anum_21=b1;
    bnum_21=0;
    num_21=[anum_21 bnum_21];
    
    %NUM_12(s)
    anum_12=b1;
    bnum_12=0;
    num_12=[anum_12 bnum_12];
    
    %NUM_22(s)
    anum_22=m1;
    bnum_22=b1;
    cnum_22=k1;
    num_22=[anum_22 bnum_22 cnum_22];
    
    roots(den)
    %Time vector
    t=(0:0.05:60);
    t=t';
    %Introduce applied forces
    for i=1:1201
        ua1(i)=2;
        ua2(i)=4;
    end;
    %Simulation using LSIM
    sys1=tf(num_11,den);
    sys2=tf(num_12,den);
    sys3=tf(num_21,den);
    sys4=tf(num_22,den);
    
    y1_1=lsim(sys1,ua1,t);
    y1_2=lsim(sys2,ua2,t);
    y1=y1_1+y1_2;
    
    y2_1=lsim(sys3,ua1,t);
    y2_2=lsim(sys4,ua2,t);
    y2=y2_1+y2_2;
    
    %Plots y1 in green, y2 in red
    subplot(211), plot(t,y1,'g');
    subplot(212), plot(t,y2,'r');
     

    Attached Files:

    • hw1.jpg
      hw1.jpg
      File size:
      68.6 KB
      Views:
      43
    • hw2.jpg
      hw2.jpg
      File size:
      65.9 KB
      Views:
      32
    • hw3.jpg
      hw3.jpg
      File size:
      56.6 KB
      Views:
      34
    • hw4.jpg
      hw4.jpg
      File size:
      57.7 KB
      Views:
      36
  2. TommyTheCat

    TommyTheCat Gonzo Scientist

    Messages:
    1,248
    Likes Received:
    11
    Joined:
    Sep 29, 2002
    Location:
    Minneapolis, MN
    A few things:

    Although its a simple problem, your comments are too short. You also didn't make your "roots(den)" statement stand out. I couldn't find it to suppress the output. And your plot has no labeling - not to say it was the last iteration of your code, but practice makes perfect. And you haven't listed units.

    "Cden" definition was also not consistant with your notes. Most likely the problem.

    Lastly, your way of defining your force vector is not proper for matlab. Loops just waste time - especially for constant vectors.




    Below is my changed code:

    Code:
    % HW #2 - Problem #1
     
    %Coefficients
    m1=4;
    m2=7;
    k1=4.2;
    k2=5.7;
    b1=3.2;
     
    % DEN(s) 
    aden=m1*m2;
    bden=m1*b1+m2*b1;
    cden=m1*k2+m2*k1;
    dden=k1*b1+k2*b1;
    eden=k1*k2;
    den=[aden bden cden dden eden];
     
    %NUM_11(s)
    anum_11=m2;
    bnum_11=b1;
    cnum_11=k2;
    num_11=[anum_11 bnum_11 cnum_11];
     
    %NUM_21(s)
    anum_21=b1;
    bnum_21=0;
    num_21=[anum_21 bnum_21];
     
    %NUM_12(s)
    anum_12=b1;
    bnum_12=0;
    num_12=[anum_12 bnum_12];
     
    %NUM_22(s)
    anum_22=m1;
    bnum_22=b1;
    cnum_22=k1;
    num_22=[anum_22 bnum_22 cnum_22];
     
    %Roots of the Den vector
    roots(den);
     
    %Time vector (MY WAY)
    t=linspace(0,160,1200);
    t=t';
     
    % applied forces vector (DITTO)
    ua1 = ones(1,1200);
    ua2 = ones(1,1200);
    ua1 = ua1 .* 2;
    ua2 = ua2 .* 4;
     
    %Simulation using LSIM
    sys1=tf(num_11,den);
    sys2=tf(num_12,den);
    sys3=tf(num_21,den);
    sys4=tf(num_22,den);
    y1_1=lsim(sys1,ua1,t);
    y1_2=lsim(sys2,ua2,t);
    y1=y1_1+y1_2;
    y2_1=lsim(sys3,ua1,t);
    y2_2=lsim(sys4,ua2,t);
    y2=y2_1+y2_2;
     
    %Plots y1 in green, y2 in red (AGAIN, MY WAY)
    figure(1)
     
    subplot(2,1,1)
    plot(t, y1, 'g')
    title('Y1 - displacement')
    xlabel('Time (?)')
    ylabel('Displacement (?)')
    %grid on
     
    subplot(2,1,2)
    plot(t, y2, 'r')
    title('Y2 - displacement')
    xlabel('Time (?)')
    ylabel('Displacement (?)')
    %grid on
     
    Last edited: Feb 8, 2008
  3. GSRCRXsi

    GSRCRXsi Super Moderator Moderator VIP

    Messages:
    9,623
    Likes Received:
    345
    Joined:
    Nov 13, 2002
    Location:
    MD
    thanks for the help! what a minor oversight on Cden! that fixed everything (even without the changes you made to other parts of the code. ) i dont know how i missed it. i even went to the TA for the class and she didnt notice either, lol. and units werent defined in the problem, its just for concept i guess, to make sure we can do it.
     
    Last edited: Feb 8, 2008
  4. GSRCRXsi

    GSRCRXsi Super Moderator Moderator VIP

    Messages:
    9,623
    Likes Received:
    345
    Joined:
    Nov 13, 2002
    Location:
    MD
    next question, how can i model this in simulink? when i get down to the last 4 scopes (my 4 transfer funtions) i cant seem to get them to add together like i need to.
     
  5. YouKnowWhoIBee

    YouKnowWhoIBee my avatar is better.

    Messages:
    2,257
    Likes Received:
    7
    Joined:
    Dec 22, 2003
    Location:
    Maryland
    Hmm...
     

    Attached Files:

  6. TommyTheCat

    TommyTheCat Gonzo Scientist

    Messages:
    1,248
    Likes Received:
    11
    Joined:
    Sep 29, 2002
    Location:
    Minneapolis, MN
    Can you not use the mathematical operator Sum?
     
  7. TommyTheCat

    TommyTheCat Gonzo Scientist

    Messages:
    1,248
    Likes Received:
    11
    Joined:
    Sep 29, 2002
    Location:
    Minneapolis, MN
  8. GSRCRXsi

    GSRCRXsi Super Moderator Moderator VIP

    Messages:
    9,623
    Likes Received:
    345
    Joined:
    Nov 13, 2002
    Location:
    MD
    i just now got it :) i thought you had to sum after getting to the scope (which you cant) so i just summed them after the TF and then into the scope and it works :)
     

    Attached Files:

  9. reckedracing

    reckedracing TTIWWOP VIP

    Messages:
    21,057
    Likes Received:
    1,180
    Joined:
    Dec 5, 2002
    Location:
    NY
  10. GSRCRXsi

    GSRCRXsi Super Moderator Moderator VIP

    Messages:
    9,623
    Likes Received:
    345
    Joined:
    Nov 13, 2002
    Location:
    MD
    lol surprised you didnt break the board with that.

    "pi is exactly 3!" LOL
     
  11. Taco15

    Taco15 I wear stretchy pants VIP

    Messages:
    6,998
    Likes Received:
    203
    Joined:
    Jan 11, 2005
    Location:
    Tallahassee Fl
    holy Fuck man! why coudnt you just post another kitten or something :lol:

    damn

    Ian hope you and Tommy get it. i have no clue what the hell you talking about but good luck
     
  12. reckedracing

    reckedracing TTIWWOP VIP

    Messages:
    21,057
    Likes Received:
    1,180
    Joined:
    Dec 5, 2002
    Location:
    NY
    its fucking up everytime i click on this thread
    lag like a whore
     
  13. GSRCRXsi

    GSRCRXsi Super Moderator Moderator VIP

    Messages:
    9,623
    Likes Received:
    345
    Joined:
    Nov 13, 2002
    Location:
    MD
    should be fixed, i deleted it completely

    now onto the "easier" single input systems. ill check back if i have issues.
     
Verification:
Draft saved Draft deleted

Share This Page