Why am i receiving "Error:Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters."? for S(K)>0

1 次查看(过去 30 天)
%General Data
G = 32.2
%none needed for this exercise
%Problem Specific Data
Simtime = 9000;
Area = 358098; %ft^2
HMAX = 6 %ft
%Time Step
N = 100; %start with 100 then go up to make it work
DT = Simtime/(N-1);
%Initial Conditions
K = 1;
Time(K) = 0;
S(K) = 0;
H(K) = 0; %depth at beginning
QI(K) = 0; %Q inlet in the beginning
%Simulation
for K = 1:N-1;
Time(K+1) = Time(K)+DT; %time at the second node
QI(K+1) = (750/pi)*(1-cos(pi*Time(K+1)/4500));
S(K+1) = S(K)+ DT*((QI(K)+QI(K+1))/(2));
H(K+1) = S(K+1)/Area
end
%Plots/ Animations
figure(1)
plot(Time,S);
xlabel('Time (s)');
ylabel('Storage');
title ('Reservoir Filling Storage vs. Time')
figure(2)
plot(Time,H);
xlabel('Time (s)');
ylabel('Depth (ft)');
title ('Reservoir Filling Depth vs Time')
%Program for Reservoir Emptying
%Implementation
Cd = .65; %discharge coefficient
d = 2; %ft
a = (pi/((4*d)^2)); %cross sectional area
Term = Cd*a*sqrt(2*G);
DT = Simtime/(N-1); %find DT use previous one and check on that?
%Initial Conditions
K = 1;
Time(K) = 0;
S(K)= S(N); %
H(K) = H(N); %max height in previous simulation
%Simulation
for S(K)>0; %as long as storage is greater than zero
Time(K+1) = Time(K)+DT;
S(K+1) = S(K)-(Term*sqrt(H(K))*DT);
H(K+1) = S/Area;
K = (K+1);
end

采纳的回答

Mischa Kim
Mischa Kim 2021-1-19
Hi, since you do not know the number of iterations it makes more sense to use a while instead of a for loop:
while S(K)>0 %as long as storage is greater than zero
Time(K+1) = Time(K)+DT;
S(K+1) = S(K)-(Term*sqrt(H(K))*DT);
H(K+1) = S(K)/Area;
K = (K+1);
end
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by