I am struggling to get started on this MATLAB question. Any tips on how to use for loops in this? Or important things to take note of?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ned Williams
am 16 Sep. 2021
Kommentiert: Ned Williams
am 18 Sep. 2021
Akzeptierte Antwort
Image Analyst
am 16 Sep. 2021
Bearbeitet: Image Analyst
am 16 Sep. 2021
Do you know how to program in the MATLAB language yet?
Here's a start
sa = 32760; % Surface area
wallHeight = 26;
data = readmatrix('data_river_discharge.dat');
inputRate = data(:, 1); % Column 1 is the river input charging rate (into the lake).
outputRate = data(:, 2); % Column 2 is the discharge rate from the dam (out of the lake).
numTimePeriods = size(data, 1); % Number of rows. Each row is a different time point.
for k = 1 : numTimePeriods
% Code goes here
if waterLevel > 0.8 * wallHeight
% Goes over spillway.
Qout =
elseif waterLevel < 0.3 * wallHeight
% Reduce outflow
Qout =
else
% Normal operating condition.
end
% Get water level at end of this time period
waterLevel = something involving prior water level and Qout and Qin
end
7 Kommentare
Image Analyst
am 17 Sep. 2021
When you do this:
y(i)=y(i-1)+((Qin(i-1))/sa)-(Qout(i-1)/sa)
p=y/wallHeight
you're setting the ith element of y in the first equation, so y is a vector. In the next line, you're using the entire y (all elements) so p will not be a single number, but a whole vector of numbers, as I'm sure you found out when you stepped through the code. So p < 0.3 will also be a logical vector, not a single true or false value but a whole array of them.
Also
if 0.8>p>0.3
is not allowed. You have to do it this way, with 2 comparisons
if p > 0.3 && p < 0.8
If you do this:
for i=2
then the loop will only iterate once. Setting i to a new value at the end of the loop does not change the fact that it will still only go through once. The format is
for k = startingValue : incrementValue : endingValue
Looks like you first need to spend 2 hours with this:
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!