hw1-finished - Problem 1(a): function [ a ] = euler( step,...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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 < 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

Page1 / 3

hw1-finished - Problem 1(a): function [ a ] = euler( step,...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online