How can I apply 'for' cycle for two arrays?

조회 수: 4 (최근 30일)
Parham Babakhani Dehkordi
Parham Babakhani Dehkordi 2015년 4월 10일
댓글: Parham Babakhani Dehkordi 2015년 4월 12일
Hello,
I have these parameters:
D=0.030;
A=7.0685*10^-4;
Jo=0.763;
Jw=[0.778090833 0.998156927 1.194644511 1.395061847 1.583689928 1.772318008 1.964875841 2.369640264];
ro_o=910;
ro_w=1000;
mu_w=0.001;
mu_o=[1.057 1.079 1.057 1.117 1.086 1.050 1.057 0.993];
and the function as:
Hw = fsolve(@(Hw) (((8*ro_o*((D-(2*sqrt(Hw*A/pi)))*(Jo/(1-Hw))*ro_o/mu_o)^-1.0)*(((Jo/(1-Hw))-(Jw/Hw))*((Jo/(1-Hw))-(Jw/Hw))))*(pi*(D-(2*sqrt(Hw*A./pi)))*(1/(1-Hw))))-((0.023*(((Jw*D*ro_w)/mu_w)^-.2)*ro_w*(Jw/Hw)^2*(pi*D))), 0.9)
For each value of Jw and mu_o, there must be one value of Hw, how can I write 'for' loop to take into consideration of two vectors Jw and mu_o?

채택된 답변

Roger Stafford
Roger Stafford 2015년 4월 10일
편집: Roger Stafford 2015년 4월 10일
It depends on what you mean by "For each value of Jw and mu_o". If you mean for each of eight corresponding pairs of numbers from these two vectors, do this:
for k = 1:8
Hw(k) = fsolve(@(Hw) .....mu_o(k).....Jw(k).....
end
If you mean for each of the sixty-four possible combination of pairs from these two arrays, then do:
for k1 = 1:8
for k2 = 1:8
Hw(k1,k2) = fsolve(@(Hw) .....mu_o(k1).....Jw(k2).....
end
end
Let us hope that the initial estimate of 0.9 will lead to successful convergence for all cases.
There is also the possible problem of multiple solutions for this equation.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by