Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Help with vectorization, instead of loops

1 vue (au cours des 30 derniers jours)
kyrresc
kyrresc le 31 Mar 2016
Clôturé : Sabin le 19 Déc 2022
I've just recently started reading up on vectorization, and I wondered if anyone could give me some advice on how I could vectorize this code: NB: Instead of the outer while-loop I could've used a for loop from 1:dt:1000, which is why I want to vectorize it. Thanks in advance!!
while t < 1000
Z = 0.5;
Kz = (rho*kt*A*pin)/(400*Mh*Gm*fh^2*H*Kh^2);
fz = Z + log(1-Z) + Kz;
dfz = 1 - (1/(1-Z));
while abs(fz/dfz) >= 10^-4
fz = Z + log(1-Z) + Kz;
dfz = 1 - (1/(1-Z));
Z = Z - fz/dfz;
end %while
%
dhdt = @(H) (- (100*Mh)/M *((2*H^2*fh^2*Gm*Z^2)/pin + (kts*As*rho*(H-Hv))/(100*Mh)));
F1 = dt*dhdt(H);
F2 = dt*dhdt(H+1/2*F1);
F3 = dt*dhdt(H+1/2*F2);
F4 = dt*dhdt(H+F3);
X(i) = H;
tvec(i) = t;
zvec(i) = Z;
H = H + 1/6*(F1+2*F2+2*F3+F4);
t = t + dt;
i = i + 1;
end %while
plot(tvec,X);
figure
plot(tvec,zvec)

Réponses (0)

Cette question est clôturée.

Tags

Aucun tag saisi pour le moment.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by