Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Help with vectorization, instead of loops

1 Ansicht (letzte 30 Tage)
kyrresc
kyrresc am 31 Mär. 2016
Geschlossen: Sabin am 19 Dez. 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)

Antworten (0)

Diese Frage ist geschlossen.

Tags

Noch keine Tags eingegeben.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by