Why can't i plot a graph for a against t?
Afficher commentaires plus anciens
k_n= 7*10^-11;
n= 2;
i=1;
t(i)=0; %in hours
a = sym('a')
while t<=2.5 %2.5hours
a= 1-exp(-k_n*(t(i))^n); %degree of hydration
dt=1/3600; %1sec interval
t(i+1)=t(i)+dt;
i=i+1;
end
figure(1);
plot(t,a,'r'),xlabel('t [h]'),ylabel('degree of hydration');
hold on;
Réponse acceptée
Plus de réponses (1)
Rik
le 15 Mar 2019
Here are some variations you could try:
k_n= 7*10^-11;
n= 2;
i=1;
dt=1/3600; %1sec interval
t=zeros(1,floor(2.5/dt)); %in hours
a=zeros(size(t));
while t(i)<=2.5 %2.5hours
a(i)= 1-exp(-k_n*(t(i))^n); %degree of hydration
t(i+1)=t(i)+dt;
i=i+1;
end
t(i:end)=[];a(i:end)=[];%remove unneeded parts of preallocated space
figure(1);
plot(t,a,'r'),xlabel('t [h]'),ylabel('degree of hydration');
%or simpler:
k_n= 7*10^-11;
n= 2;
fun=@(t) 1-exp(-k_n.*t.^n);
figure(2)
subplot(1,2,1)
fplot(fun,[0,2.5])
%or explicit:
subplot(1,2,2)
t=0:1/3600:2.5;
a=fun(t);
plot(t,a)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!