Why is my iteration not working. ? ( the solution array has all the same value from first iteration )

%function F = Gaddis(x)
for (i = 1:40)
vol(1) = 5*10^(-6); % volumetric gas flow rate
sig = 0.0728;
do = 6*(10^(-3));
den = 998;
g = 9.81;
mu = 8.9*10^(-4);
s = (6*do*sig/(den*g));
L = (81*mu*vol(i)/(pi*g*den));
T = (135*(vol(i)^2)/(4*(pi^2)*g));
F = (x^3) - s - (L/x) - (T/(x^2));
vol(i+1) = vol(i) + 10^(-6);
end
end
I used fsolve solver to solve this function . '
As my volume changes , i am supposed to get new values of diametre , but it shows the same value for all the 40 iterations.
command code xsol(i) = fsolve(@(x) Gaddis(x), 0.0001);

 采纳的回答

function main
for i=1:40
vol(i) = 5e-6+(i-1)*1e-6;
xsol(i)=fsolve(@(x)Gaddis(x,vol(i)),1e-4);
end
plot(vol,xsol)
function F = Gaddis(x,vol)
sig = 0.0728;
do = 6*(10^(-3));
den = 998;
g = 9.81;
mu = 8.9*10^(-4);
s = (6*do*sig/(den*g));
L = (81*mu*vol/(pi*g*den));
T = (135*(vol^2)/(4*(pi^2)*g));
F = (x^3) - s - (L/x) - (T/(x^2));
Best wishes
Torsten.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by