Anything is helpful!
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?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Ned Williams
el 16 de Sept. de 2021
Comentada: Ned Williams
el 18 de Sept. de 2021
Respuesta aceptada
Image Analyst
el 16 de Sept. de 2021
Editada: Image Analyst
el 16 de Sept. de 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 comentarios
Image Analyst
el 17 de Sept. de 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:
Más respuestas (0)
Ver también
Categorías
Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!