This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CEE 291 Problem Solving Using Computer Tools Homework 3: Matlab Assigned: 2/10/2010 Due: 2/16/2010 by 5:00 pm in the ECOW2 drop box and in the hall box outside 1261 EH. For each file, copy your code into Word and include a plot (if necessary). Problem 1 Conditional statements- One of the most important and fundamental operations in programming is the ability choose different paths to take to get to the end result. The conditional “IF Statement” is the same principle as it is in Excel; however, the syntax is different. In Matlab, the syntax is: if(condition) statements elseif(condition) statements else statements end where: elseif and else are optional. You can include as many elseif conditions as necessary. The conditional statement can include more than one condition with the & &(and) or the | | (or) between conditions. E.g. if(x>4 & & x<10), if(x<3 | | t >10) a.) Create a vector of time from 0 to 24 hours with spacing of 5 minutes. Use a for loop to cycle through the time array and calculate Q. Similar to problem 3 from homework 2, Q changes at different times: Q = 300 + 600 t for 0 < t<= 3 hours and Q = 2100 – 200( t-3) for 3 < t <= 12 hours, and Q = 300 for t > 12 hours. However, treat this conditional flow as the primary outflow from the reservoir. Use an if, elseif, and else statement inside the for loop to calculate Q and make a plot of Q vs. time. Construct a plot of Q vs. t. T=0:5/60:24; for i=1:length(T) if(T(i)<=3) 5 10 15 20 25 200 400 600 800 1000 1200 1400 1600 1800 2000 2200 Q(i)=300+600*T(i); elseif(T(i)>3 & & T(i) <=12) Q(i)=2100-200*(T(i)-3); else Q(i)=300; end end b.) Now modify your script to include an emergency outlet. Once the primary outlet reaches a discharge of 1800, allocate the rest of the flow to the emergency spillway. This will require nesting an additional for loop into your code....
View Full Document
- Spring '10
- Switch statement, sight distance, Arithmetic IF