sol_hw1 - CE 335 Solutions to Homework 1 8) Given the...

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
4.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
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

sol_hw1 - CE 335 Solutions to Homework 1 8) Given the...

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

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