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.
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];
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