Start by following the instructions in weuler (or wheun or wrk4); just type help weuler to get the instructions. For instance, to solve , T(0) = 280, for , use an editor to create the M-file frcdheat.m (the name is arbitrary)
% frcdheat.m % T' = -0.33*( T - (273 - 0.1*t) ) function Tprime = frcdheat(t, T) Tprime = -0.33*( T - (273 - 0.1*t) );Then start Matlab and type
[t,y] = weuler( 'frcdheat', 0, 24, 280, 0.5);to produce a plot of the approximate solution curve. (The 0.5 in the call to weuler specifies the step-size for the numerical method; a smaller step-size improves accuracy but takes longer.) The solution has been stored in the vector y. (To see it fly by on the screen, type y without a semicolon.
Add labels and a graph of the forcing function to the plot as follows. To put the ``forcing function'' (actually the outside temperature in this case) into the vector z, type
s = 0:0.5:24; z = 273 - 0.1*s;
The next commands build the plot:
plot(t,y,'o'); % plots y with o's hold on; % holds the old plot plot(s,z,'x'); % plots z with x's title(' Heat-Loss Model '); % adds a title xlabel(' Time (hours) '); ylabel(' Temperature (K) '); % label the axes text(10, 278, ' o temperature inside '); % put text at (10, 278) text(10, 275 , ' x temperature outside '); % put text at (10, 275)
To start over, type hold off or close the figure window.
To leave Matlab and save your variables into the file filename.mat, type save filename. When you return to Matlab, type load filename to pick up where you left off.
Next: Second Order Equations
© 1996 by Will Brother. All rights Reserved. File last modified on November 21, 1996.