Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

re write all the matlab commandes with corrections. b) An engineer develops a program in MATLAB to predict flood due to heavy rainfall in Malaysia.

re write all the matlab commandes with corrections. image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
b) An engineer develops a program in MATLAB to predict flood due to heavy rainfall in Malaysia. The program should correlate amount of rainfall and water level of the river. As trial, the engineer creates a short program for three river monitoring stations in Johor as given in Table 1.1. Table 1.1 River monitoring stations in Johor City River monitoring stations Danger Level (m) 3.00 Johor Bahru Kota Tinggi Segamat Sg.Skudai Sg.Johor Sg.Lenik 9.80 6.00 The program should receive input of rainfall precipitation and expected to give warning when the water level exceeds the danger level which that can cause floods, alert message when water level rise from normal level or safe message if water at normal level. In order to create the program, the engineer gathers information as below: Q = 0.1767P + 0.8248 (1.1) Equation 1.1 obtained from regression of historical data of precipitation, P (mm) and water flowrate, Q (m/s). Qr (BH)5/3/5 n(B + 2H)2/3 (1.2) Equation 1.2 used to estimate the flowrate of a river, Q. (m/s), where S is slope (m/m), H is depth (m), B is river width (m) and n is Manning roughness coefficient. The parameter for each river is given in Table 1.2 below. Table 2.1 Parameters of river in Johor S n B 0.0003 18 River Sg Skudai Sg Johor Sg Lenik 0.05 0.14 23 0.0001 0.0002 20 0.095 The engineer creates a program by comparing the maximum Q, calculated at danger level of height with Q. If Q is greater than Qr, thus the water level exceeds the river danger level, while if Q is around 70% of Qr, it is at alert level otherwise it is at normal level. The expected results of the program are shown in Figure 1.1. Nevertheless, the engineer encountered problems where program in Figure 1.2 has 20 errors messages. As an expert, help the engineer to analyse Question 1 - Page 3 the errors messages shown in Figure 1.3. Rewrite all the MATLAB commands with corrections in Figure 1.4. Remain the program structure and number of lines as original MATLAB program. In your answer, please highlight fixed errors using highlighter. (40 Marks) Command Wadow >> YloodPrediction2 Select city: Johor Bahru/Segamat/Kota Tinggi- Johor Bahru Average Precipitation (mm) 124 Error in input. Please try again >> >> Flood Prediction2 Select city: Johor Bahru/Segamat/Kota Tinggi Johor Bahru Average Precipitation (m) 124 1t! ALERT! Water level rise above normal level at sg Skudai river in Johor Bahru city >> >> Flood Prediction2 Select city: Johor Bahru/Segamat/Kota Tinggi- Segamat Average Precipitation (mm) 100 ***Water Level at Sg Lenik, Segamat: Normal Lovel*** >> Yloodprediction 2 Select city: Johor Bahru/Segamat/Kota Tinggi Kota Tinggi Average Precipitation (mm) 320 11 WARNING! Evacution needed. 5 Johor river in Kota Tinggi city exceed the danger level. Please evacuate people to the nearest evacuation center. Figure 1.1 Expected results of program executed for different cases. 1 2 city=input('Select city: Johor Bahru/Segamat/Kota Tinggi= '); P=input('Average Precipitation (mm) ='); Q=0.1767+P+0.8248; switch City 3 4 5 case Johor Bahru 6 S=0.0003;B=18;n=0.05; Humax=3.0; 7 Location='Sg Skudai'; 8 9 case Segamat S=0.0002;B=20;n=0.095; Hmax=6.0; 10 11 12 Location='Sg Lenik': case Kota Tinggi S=0.0001;B=23;n=0.14; Hmax=9.8; Location=lSg Johor': otherwise disp('Error in input. Please try again') 13 14 15 16 return 17 18 Qr=((BHmax)^(5/3)*sqrt(S))* (B+2Hmax)^(2/3); 19 20 21 22 if Q>Qr fprintf(" !!! WARNING! Evacution needed. 85.2f river in $5.2f city exceed the danger level. In', location, city) disp('Please evacuate people to the nearest evacuation center.') elseif Q>Or0.7 fprintf(" !!! ALERT! Water level rise above normal level at $5.2f river in $5.2f city ', Location, city) elseif fprint(" ***Water Level at 85.2f, 95.24: Normal Level*** ', Location, city) 23 24 25 26 >> Flood Prediction2 Error: File: FloodPrediction2.m Line: 5 Column: 16 Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses. >> Flood Prediction2 Error: File: FloodPrediction2.m Line: 11 column: 15 Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses. >> FloodPrediction2 Error: File: FloodPrediction2.m Line: 18 Column: 34 Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses. >> FloodPrediction2 Error: File: Flood Prediction2.m Line: 24 Column: 7 Invalid expression. Check for missing or extra characters. >> Flood Prediction2 Error: File: FloodPrediction2.m Line: 19 Column: 1 At least one END is missing: the statement may begin here. >> Flood Prediction2 Error: File: Flood Prediction2.m Line: 4 Column: 1 At least one END is missing: the statement may begin here. >> Flood Prediction2 Select city: Johor Bahru/Segamat/Kota Tinggi- Johor Bahru Select city: Johor Bahru/Segamat/Kota Tinggi- Johor Bahru Select city: Johor Bahru/Segamat/Kota Tinggi- Operation terminated by user during LiveEditorEvaluation HelperESectionEvaleb4c2068 (line 1) In matlab.internal.editor evaluateCode >> Flood Prediction2 Select city: Johor Bahru/Segamat/Kota Tinggi= Johorbahru Average Precipitation (mm) =124 Undefined function or variable city'. Error in FloodPrediction2 (line 4) switch City >> Flood Prediction2 Select city: Johor Bahru/Segamat/Kota Tinggi, Johor Bahru Average Precipitation (mm) =124 Undefined function or variable Segamat Error in FloodPrediction2 (line 8) case Segamat >> Flood Prediction2 Select city: Johor Bahru/Segamat/Kota Tinggi, Johor Bahru Average Precipitation (mm) =124 Undefined function or variable 'Qro. Error in FloodPrediction2 (line 22) elseif Q>=0r0.7 >> Flood Prediction2 Select city: Johor Bahru/Segamat/Kota Tinggi= Johor Bahru Average Precipitation (mm) =124 !!! ALERT! Water level rise above normal level at 83.00 river in 103.00 city !!! ALERT! Water level rise above normal level at 32.00 river in 83.00 city !!! ALERT! Water level rise above normal level at 107.00 river in 117.00 city !!! ALERT! Water level rise above normal level at 100.00 river in 97.00 city !!! ALERT! Water level rise above normal level at 105.00 river in 74.000 city !!! ALERT! Water level rise above normal level at 111.00 river in 104.00 city !!! ALERT! Water level rise above normal level at 111.00 river in 114.00 city !!! ALERT! Water level rise above normal level at 32.00 river in 66.00 city !!! ALERT! Water level rise above normal level at 97.00 river in 104.00 city !!! ALERT! Water level rise above normal level at 114.00 river in 117.00 city >> Flood Prediction2 Select city: Johor Bahru/Segamat/Kota Tinggi- Segamat Average Precipitation (mm) -100 Undefined function 'print' for input arguments of type 'char'. Error in FloodPrediction2 (line 25) fprint(" ***Water Level at 85.2f, $5.2f: Level*** ', Location, city) Normal >> FloodPrediction2 Select city: Johor Bahru/Segamat/Kota Tinggi= Kota Tinggi Average Precipitation (mm) - 320 Undefined function or variable location! Error in Flood Prediction2 (line 20) fprintf (" !!! WARNING! Evacution needed. 25.2f river in 45.2f city exceed the danger level. In', location, city) Figure 1.3 Compilation of error messages in the command window 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions