For loop not generating result
2 次查看(过去 30 天)
显示 更早的评论
I have the equation below to program
k should assume 1 if
≥
and assume 0 if
≤
.
All other parameters are constants.
R = 2; C = 2.5; eta = 2.5; Pac = 5; Tp = 76; t_delta = 1;
t = 0:5/12:24;
alpha = 1-t_delta/(60*R*C);
beta = eta*R*(9/5)+32;
T0 = 86 - 14*cos(0.0035*t);
Ta(1) = Tp;
k(1) = 0;
for j = 1:length(t)
Ta(j+1) = alpha*Ta(j)+(1-alpha).*(T0(j)-k(j)*beta*Pac);
if (Ta(1:j) <= Tp-0.5)
k(j) = repelem(0,length(j));
Ta(j+1) = alpha*Ta(j)+(1-alpha).*(T0(j)-k(j)*beta*Pac);
for m = 1:j
if (Ta(1:m) >= Tp+0.5)
k(m) = repelem(1,length(m));
Ta(m+1) = alpha*Ta(m)+(1-alpha).*(T0(m)-k(m)*beta*Pac);
end
end
end
end
plot(t,Ta) suppose to give a pulse-like shape, similar to the shape in orange in the attached file. But I'm not getting anything close.
I don't know what is wrong. Please assist. I'm very new to matlab.
7 个评论
Cris LaPierre
2021-10-7
Nice. I suggest moving you last post to an Answer. You can accept your own answer, and doing so will let others know this question has a solution.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

