% Math 23: Take-home midterm. Question 1
% Let's do this professionally: put the Euler method code into a
% subroutine which solves and plots. Why? We need to execute the same
% code for many different h values, don't take to retype.
% How do we use the routine solve_fluid.m ? Type "help solve_fluid"
% and you will find out (this displays the comments at start of routine).
figure; % start a new plot
hs = [0.1 0.02 0.004 0.0008]; % set of h values to explore
clear yf
[yf(1)] = solve_fluid(hs(1), '-+'); % yf(1) is value of y(5) with h=0.1
hold on;
[yf(2)] = solve_fluid(hs(2), 'r-');
[yf(3)] = solve_fluid(hs(3), 'g-');
[yf(4)] = solve_fluid(hs(4), 'k-'); % notice we only need 1 line of code
% per experiment now!
% (we could have been neater and put all the above in a loop over h values)
legend('h=0.1','h=0.02','h=0.004','h=0.0008'); % you can move legend by hand
title('convergence of Euler method for fluid instability');
disp(' h y(t=5)') % nice way to plot the data table
format short
disp([hs' yf'])