{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

This preview shows pages 1–5. 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 Document
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 1.935 10.0 1.730 9) Same idea, but displaying y(t) as a plot will be easier if we make t and y vectors that contain the results from all the time steps, instead of scalars. The new script is: %set values for parameters in problem Q = 500; %m^3/d A = 1200; %m^2 alpha = 300; %step size to use

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.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern