Do while loop with recursive make the answer incorrect?
古いコメントを表示
Dear all,
I have question about doing while loop since i try to find a value of h0 in while loop by using Newton's method and i let the 4 input parameters be recursive in the folowing(just want to recheck that's why i set N=2). And i also let it print the value of each parameters to recheck the value of h0.
function h0 = minftnaja
mmin = 3;
mmax = 12;
almin = 0.1;
almax = 1;
R0min = 0.013;
R0max = 0.015;
R1min = 0.020;
R1max = 0.050;
ita = 0.1;
frad = 220;
rpm = 20000;
N = 2 ;
[m_, al_, R0_, R1_] = ndgrid( linspace(mmin, mmax, N), ...
linspace(almin, almax, N), ...
linspace(R0min, R0max, N), ...
linspace(R1min, R1max, N));
h0 = 0.00002;
heps = 0.0001;
errF = 1e-4;
err = 1;
while all(err > errF) % will not stop as long as even one entry is out of tolerance,
% so when you stop then all of them will be within tolerance.
k = pi .* (R0_ + R1_) .* tan(al_ .* pi ./ 180) ./ (m_ .* h0);
fu = 6 .* (R1_ - R0_) .* (-rpm .* pi .* (R0_ + R1_) ./ 60) .* ita .* (-log(k+1) + ((2*k)./(k+2))) ./ (tan(al_ .* pi ./ 180)).^2;
f = fu-frad;
h0 = h0+heps;
kk = pi .* (R0_ + R1_) .* tan(al_ .* pi ./ 180) ./ (m_ .* h0);
fu = 6 .* (R1_ - R0_) .* (-rpm .* pi .* (R0_ + R1_) ./ 60) .* ita .* (-log(kk+1) + ((2*kk)./(kk+2))) ./ (tan(al_ .* pi ./ 180)).^2;
f1 = fu-frad;
h0 = h0-heps;
jacobian = (f1-f)/heps;
h0 = h0 - 0.01*f./jacobian;
err = abs(f/frad);
if err > errF
else
m_
al_
R0_
R1_
end
end
I use the value from each parameter to recheck the value of h0 by the function which is not using recursive to be input in the following.
function h0 = GG
frad = 220; %loading
rpm = 20000;
m = 3; %1
alpha = 0.1; %2
R0 = 0.013; %3
R1 = 0.020; %4
ita=0.01;
h0 = 0.00002;
heps = 0.0001;
errF = 1e-4;
err = 1;
while all(err > errF)
k = (2*pi*(R0+R1)/(2*m))*tan(alpha*pi/180)/h0;
fu = -(6*ita*(rpm*2*pi*(R0+R1)/(2*60))*(R1-R0)*(2*pi*(R0+R1)/(2*m))^2)*(-log(k+1)+(2*k)/(k+2))/((k^2)*(h0^2));
f = fu-frad;
h0 = h0+heps;
kk = (2*pi*(R0+R1)/(2*m))*tan(alpha*pi/180)/h0;
fu = -(6*ita*(rpm*2*pi*(R0+R1)/(2*60))*(R1-R0)*(2*pi*(R0+R1)/(2*m))^2)*(-log(kk+1)+(2*kk)/(kk+2))/((kk^2)*(h0^2));
f1 = fu-frad;
h0 = h0-heps;
jacobian = (f1-f)/heps;
h0 = h0 - 0.01*f/jacobian;
err = abs(f/frad);
end
end
The result is not the same and i also recheck that is this h0 correct from while loop with recursive? by use the values of 4 parameters and h0 to find value of fu which should give the value approximately equal to frad but it is not.
So i just wonder may be because of doing recursive in while loop that's the reason why the result is not the same. Am i right??
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!