Handout_ex_code_SS_2004

# Handout_ex_code_SS_2004 - MATLAB SIMULINK Sample Code May...

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

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

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

View Full Document
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 ;
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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern