Matlab 3-Higher order ODE (1)

docx

School

Auburn University *

*We aren’t endorsed by this school

Course

2010

Subject

Mechanical Engineering

Date

Feb 20, 2024

Type

docx

Pages

11

Uploaded by ChancellorKoupreyPerson1035

Report
Name: MECH 2220 Matlab Lab 3, Fall 2020 Matlab Lab 3: Numerical Solutions to Higher Order ODE’s Assigned: 11/02/ 2020 Due: 2 weeks from the lab attended Problem Statement #1: 1. Write an uwf that will solve a system of first order ordinary differential numerically using Euler’s method. Code for problems: %Matlab Lab 3: Higher Order %Enoch Crittenden %Number 1 Code function out = EulerODE(slope,x_initial,dx,x_final,y_initial) x(1) = x_initial; G(1,:) = y_initial; n = 1; while x(n) < x_final G(n+1,:) = G(n,:) + slope(x(n),G(n,:))*dx; x(n+1) = x(n) + dx; n=n+1; end out = [x',G];
Name: MECH 2220 Matlab Lab 3, Fall 2020 2. Find the analytic solution to the following third order ode. Transform the ode into a system of three first order equations. Solve the system with the uwf developed in task one. Solve the system with the built in function ode45. Compare the three solutions. ''' cos( ); ''(0) 1; '(0) 0; (0) 1 y x y y y  Code for problems: %Matlab Lab 3: Higher Order %Enoch Crittenden clc clear all slope = @(x,G)[cos(x),G(1),G(2)]; %Slope form x_initial = 0; %initial x value x_final = pi; %final x value dx = (pi/20); %derivative of value IV = [1,0,-1]; fprintf( '\t\tX\t\tY''''\t\tY''\t\tY\n' ) Matrix = EulerODE(slope,x_initial,dx,x_final,IV) %Matrix derivation x = Matrix(:,1);y = Matrix(:,4); plot(x,y) %Plot hold on y_analytical = -sin(x)+(x.^2)/2 + x-1; plot(x,y_analytical, 'r+' ) %Plot %Now the ode45 method slope2 = @(x,G) [cos(x),G(1),G(2)]'; [x,GV] = ode45(slope2,[x_initial:dx:x_final],IV); y_ode=GV(:,3); plot(x, y_ode, 'k.' ) %plot for graph xlabel( 'x' ) ylabel( 'y' ) legend( 'Euler Method' , 'Analytical' , 'ode45' )
Name: MECH 2220 Matlab Lab 3, Fall 2020 Solution for problems: 3.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: MECH 2220 Matlab Lab 3, Fall 2020 4. Do problem 22.15 in your text using the function developed in #1 above. Repeat using ode45. The motion of a damped spring-mass system (Fig. P22.15) is described by the following ordinary differential equation: m d 2 x dt 2 + c dx dt + kx = 0 where x = displacement from equilibrium position (m), t =time (s), m = 20-kg mass, and c = the damping coefficient (N · s/m). The damping coefficient c takes on three values of 5 (underdamped), 40 (critically damped), and 200 (over damped). The spring constant k = 20 N/m. The initial velocity is zero, and the initial displacement x = 1 m. Solve this equation using a numerical method over the time period 0 ≤ t ≤ 15 s. Plot the displacement versus time for each of the three values of the damping coefficient on the same plot. Code for problems: %Matlab Lab 3: Higher Order %Enoch Crittenden %Number 3 Code clc clear all %Initial values for formula %time in seconds t_initial = 0; t_final = 15; dt = .05; c = 200; %Damped value (change for each value) k = 20; %N/m m = 20; %kg(s) %Slope forumula 1 slope = @(t,G)[(-c*G(1) - k*G(2))/m, G(1)]; IV = [0,1];
Name: MECH 2220 Matlab Lab 3, Fall 2020 Matrix = EulerODE(slope,t_initial,dt,t_final,IV); t = Matrix(:,1); x = Matrix(:,3); plot(t,x) hold on %Slope formula 2 slope_2 = @(x,G)[(-c*G(1) - k*G(2))/m, G(1)]'; [t2,G] = ode45(slope_2,[t_initial:dt:t_final],IV); ode = [t2,G]; t1 = ode(:,1);x2 = ode(:,3); %Plotting the line plot(t1,x2, 'r.' ); xlabel( 'Time (seconds)' ); ylabel( 'Displacement (meters)' ); legend( 'Euler' , 'ode45' ); Solution for problems:
Name: MECH 2220 Matlab Lab 3, Fall 2020
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: MECH 2220 Matlab Lab 3, Fall 2020 Solution for problems: 5. Dragster: An application of ODE solvers After reaching a top speed of 250 mph a 3000 lbm dragster deploys the semispherical parachute and engages wheel brakes to stop the car. The diameter of the parachute is 10 feet, and the wheel brakes can result in a constant -2g acceleration (the wheel brake force is 2 times the weight of the car). The force exerted by the parachute may be approximated by
Name: MECH 2220 Matlab Lab 3, Fall 2020 The drag coefficient for the parachute has been experimentally determined to be 1.4. The governing differential equation is then developed with Newton’s Second Law. Write this second order equation as a system of first order equations assuming the following units: Use MATLAB to determine the following questions. A. How long and how many feet does it take to stop the car? B. Create formatted output that tabulates time, position, velocity, and parachute force. C. Compute the total work performed by the parachute on the car. Code for problems: %Matlab Lab 3: Higher Order %Enoch Crittenden %Number 4 Code clc
Name: MECH 2220 Matlab Lab 3, Fall 2020 clear all %Given values and formula t_initial = 0; %seconds t_final = 3.5; %seconds dt = 0.01; %derivative (seconds) slopeode = @(t,G)[-((4.123*(G(1)^2))/3000) - 64.4, G(1)]'; IV = [366.67,0]; %Time Matrix [time,Matrix] = ode45(slopeode,[t_initial:dt:t_final],IV); velocity = Matrix(:,1); distance = Matrix(:,2); p_force = 4.123*velocity.^2; fprintf( '\ttime\t\tV\t\t\tD\t\tF' ) T = [time,Matrix,p_force] %Graph Formation plot(distance,velocity, 'r.' ) %Answer for A xlabel( 'distance(ft)' ); ylabel( 'velocity' ); fprintf( '%6.2f,T' ); %Answer for B total_work = trapz(distance,p_force) %Part C Answer
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Name: MECH 2220 Matlab Lab 3, Fall 2020 Solution for problems:
Name: MECH 2220 Matlab Lab 3, Fall 2020