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
0 个评论
采纳的回答
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 个评论
Mischa Kim
2021-1-19
Correct. This is because S is a vector. Are you trying to access the k-th component in this command? See also code snippet above
H(K+1) = S(K)/Area;
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!