MATLAB Answers

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?

35 views (last 30 days)

Accepted Answer

Image Analyst
Image Analyst on 16 Sep 2021
Edited: Image Analyst on 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 Comments
Ned Williams
Ned Williams on 18 Sep 2021 at 4:22
clc;close;clear
format short g
data=xlsread('data_RiverDischarge.xls');
sa=352760;
H=26;
vol=sa*H;
Rin=data(:,1);
days=size(data,1);
y(1)=18.8;
Qin=data;
Qout=5.33;
Qr=2.2*Qout;
for i=2:1:days
I(i-1)=(Qin(i-1))/sa
O(i-1)=(Qout(i-1))/sa
R(i-1)=(Qr(i-1))/sa
y(i)=y(i-1)+I(i-1)-O(i-1)-R(i-1)
p=y(i)/H
for Q=Qout
if p>0.3 && p<0.8
Q=5.33; Qr=0
elseif p>0.8
Q=5.33;Qr=2.2*Qo
elseif p<0.3
Q=(1/1)*Qin(i)
else p>=1
disp('overflow')
end
end
y(i+1)=y(i)+I(i)-O(i)-R(i)
p=(y(i+1))/H
end
Does this make any more sense> I am still getting an error saying that the Index exceeds the number of array elements (1)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by