필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Help with vectorization, instead of loops

조회 수: 1 (최근 30일)
kyrresc
kyrresc 2016년 3월 31일
마감: Sabin 2022년 12월 19일
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)

답변 (0개)

이 질문은 마감되었습니다.

태그

아직 태그를 입력하지 않았습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by