This preview shows pages 1–3. Sign up to view the full content.
CE 335
Solutions to Homework 1
8)
Given the differential equation, the Euler's method numerical approximation is
y(t +
Δ
t) = y(t) +
Δ
t(3(Q/A)sin
2
(t)  Q/A).
Here, the number of time steps to take is n = (t
1
 t
0
)/
Δ
t = (10 d)/(0.5 d) = 20.
We can write a Matlab script to execute Euler's method and display the result from each step:
%set values for parameters in problem
Q = 500; %m^3/d
A = 1200; %m^2
%step size to use
Dt = 0.5; %d
%number of steps
n = 20;
%initial condition
t = 0;
y = 0;
%display the initial condition
%cf. Sec. 3.2 for usage of fprintf
fprintf('
t(d)
y(m)\n');
fprintf('%5.1f %10.3f\n', t, y);
%do Euler's method and display the result from each step
for i = 1:n
y = y + Dt*(3*(Q/A)*(sin(t)^2)  Q/A);
t = t + Dt;
fprintf('%5.1f %10.3f\n', t, y);
end
The result is
t(d)
y(m)
0.0
0.000
0.5
0.208
1.0
0.273
1.5
0.039
2.0
0.375
2.5
0.683
3.0
0.699
3.5
0.503
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document4.0
0.371
4.5
0.521
5.0
0.910
5.5
1.276
6.0
1.379
6.5
1.220
7.0
1.040
7.5
1.102
8.0
1.443
8.5
1.847
9.0
2.037
9.5
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '11
 Lybas

Click to edit the document details