This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Problem 1(a): function [ a ] = euler( step, T_final ) % Euler Method with comparison to exact solution in homework 1. % step = dt g = 9.81; m = 75; cd = .25; maxError = 0; v1 = 0:step:T_final; % numerical solution t = 0:step:T_final; % step v2 = 0:step:T_final; % exact solution for x = 1:T_final/step v1(x+1) = v1(x) + step * (g - (cd / m * v1(x) * v1(x)) ); v2(x+1) = sqrt(g * m / cd) * tanh(sqrt(g * cd / m) * t(x+1)); if (maxError &lt; abs(v1(x+1) - v2(x+1))) maxError = abs(v1(x+1) - v2(x+1)); end end plot(t,v1, 'ro' ,t, v2, 'b' ); leg = legend( 'Euler Method' , 'Exact' ); set(leg, 'Location' , 'NorthWest' ) fprintf( 'Exact = %f\n' , v2(T_final/step+1)); fprintf( 'Numerical = %f\n' , v1(T_final/step+1)); % solution to problem 1(a) fprintf( 'Max Error = %f\n' , maxError); a = maxError; % solution to problem 1(a) end Problem 2(a): function [ a ] = RK2( step, T_final ) % Runge-Kutta Method (RK2) to hw 1 with comparison to exact solution....
View Full Document
This note was uploaded on 02/19/2012 for the course ENGR 361 taught by Professor Drexel during the Spring '12 term at Bloomsburg.
- Spring '12