Handout_ex_code_SS_2004

Handout_ex_code_SS_2004 - MATLAB SIMULINK Sample Code May...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 MATLAB SIMULINK Sample Code May be useful for HW 4 and/or MSP1 ME3504 SS 2004 Example Euler and modified Euler calculations SIMULINK called from MATLAB Use of ode45 function for MATLAB time step integration of equations 2 June 2004 R. G. Kirk
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 Euler and modified Euler Solutions for a mass on an inclined plane % Vib_S_01_p1mu.m 2-2001 rgk % Sliding on an inclined plane, system not in static equil. at x = 0; clear all; close all; prtopt = input([ 'Do you wish to auto print to default printer?' ... ' 1 = yes; 0 == NO ==> ' ]); if isempty(prtopt) prtopt = 0; end ; code missing here Eulertype = input( 'Input 1 = Euler; 2 == Castelli-Euler (default = 2) ==> ' ); if isempty(Eulertype) Eulertype = 2 ; end ; cc = 2 * m * wn; zeta = c/cc; t = linspace(0,ncyc*2*pi/(wn),np); dt =t(2) - t(1); ti(1) = 0.0; tt = 0.0; x(1) = xo; xd(1) = vo; %cnl = ccnl * .00000001 if Eulertype == 2 for n = 1:np tt = tt + dt; ti(n+1) = tt; xdd = 1/m*(-k*x(n)-c*xd(n)-mu*m*9.806*cos(theta*pi/180)*sign(xd(n)) ... + m*9.806*sin(theta*pi/180)); xd(n+1) = xd(n) + xdd*dt; x(n+1) = x(n) + xd(n+1) * dt; end ; % end of n for loop for Castelli-Euler else for n = 1:np tt = tt + dt; ti(n+1) = tt; xdd= 1/m*(-k*x(n) -c*xd(n)-mu*m*9.806*cos(theta*pi/180)*sign(xd(n)) ... + m*9.806*sin(theta*pi/180)); xd(n+1) = xd(n) + xdd*dt; x(n+1) = x(n) + xd(n) * dt; end ; % end of n for loop for normal Euler end ;
Image of page 2
3 Example of putting things on plot or picking points info from Euler and modified Euler Solutions for a mass on an inclined plane code missing for plot if prtopt == 1 print -dwin; end ; gtext([ 'dt = ' num2str(dt) ' sec.' ]); gtext([ 'total time = ' num2str(tt) ' sec.' ]); gtext([ 'n = ' num2str(np/ncyc) ' pts per cycle of wn for ' num2str(ncyc) ' cycles' ]); [nr nc] = size(x); gtext([ 'x-final = ' num2str(x(nc-1)) ' m' ]); xstatic = m*9.806*sin(theta*pi/180) / k; gtext([ 'x-static = ' num2str(xstatic) ' m' ]); prtopt2 = input([ 'Do you wish to add a figure caption?' ... ' 1 = yes; 2 == NO ==> ' ]); if isempty(prtopt2) prtopt2 = 2; end ; if prtopt2 == 1 disp( ' Example of following input:' ); disp( ' ==> [ "Fig 1. Response for Problem 1.95b "]' ); disp( ' note: use single quote inside [ ] rather than " "as shown' ); FigCapt = input( ' Specify string for caption now ==> ' ); if
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern