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

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

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.

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

## This note was uploaded on 02/02/2012 for the course CS 1111 taught by Professor Asdf during the Spring '11 term at UCSB.

### Page1 / 4

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

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

View Full Document
Ask a homework question - tutors are online