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 isempty(FigCapt) FigCapt = [ 'Prob._____' ]; end ; gtext([FigCapt]);

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.

## This note was uploaded on 01/23/2012 for the course ME 3504 taught by Professor Tschang during the Fall '08 term at Virginia Tech.

### Page1 / 11

Handout_ex_code_SS_2004 - MATLAB SIMULINK Sample Code May...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online