Hello again, sorry for the trouble.
I've tried NDSolve method to search for "z" instead of ParametricNDSolveValue
So here's what I done but still there's some error.
prog := Module[{Twater = 300., Tnew = 0, Cwater, Dwater, Ewater,
ClassicalRungeKuttaCoefficients, f, x, y, z = 60, point, ans,
tol = 0.001, iters = 0, iterLim = 100, prevTnew = 10^5,
plotList = {}}, $MinPrecison = 50;
Cwater =
QuantityMagnitude[
ThermodynamicData["Water",
"ThermalConductivity", {"Temperature" ->
Quantity[Twater, "Kelvins"]}]];
ans = "Twinkle, twinkle, little star,
How I wonder what you are.
Up above the world so high,
Like a diamond in the sky.
Twinkle, twinkle, little star,
How I wonder what you are!";
While[(Abs[prevTnew - Tnew] > tol) && (iters++ < iterLim),
Dwater = (5 Cwater)/Pi;
Ewater = Dwater^3 + 2*Cwater;
While[
(Abs[point] < 100) && (iters++ < iterLim),
ClassicalRungeKuttaCoefficients[4, prec_] :=
With[{amat = {{1/2}, {0, 1/2}, {0, 0, 1}},
bvec = {1/6, 1/3, 1/3, 1/6}, cvec = {1/2, 1/2, 1}},
N[{amat, bvec, cvec}, prec]];
f =
NDSolve[{SetPrecision[
Derivative[1][y][x] ==
Piecewise[{{(y[x] + x^3 + 3 z - 120*Ewater),
0 <= x <= 1}, {(y[x] + x^2 + 2 z),
1 <= x <= 2}, {(y[x] + x + z), 2 <= x <= 3}}], 40],
y[0] == 0}, y, {x, 0., 3.},
Method -> {"ExplicitRungeKutta", "DifferenceOrder" -> 4,
"Coefficients" -> ClassicalRungeKuttaCoefficients},
StartingStepSize -> 1/100];
point = y[1] /. f[[1]];
z++
]
Print[point];
prevTnew = Tnew;
Tnew = 170 + 1.89*z;
Cwater =
QuantityMagnitude[
ThermodynamicData["Water",
"ThermalConductivity", {"Temperature" ->
Quantity[Tnew, "Kelvins"]}]];
(*Note Tnew here!*)
Print["Twater: ", Twater, " Tnew: ", Tnew];];
(*End while*)
ans = {"Tnew: ", Tnew, "Cwater: ", Cwater, "Dwater: ", Dwater,
"Ewater: ", Ewater};
Print["The answer is:\n", ans];];
What I tried to do is to have "While Loop" inside a "While Loop" and instead of FindRoot, I use ReplaceAll,
Here's the plan,
The inner loop is to find the value of "z" so that the "point" is 100, and the increment of "z" is 1 each time.
After it reach the correct value of "z", the the command will continue to look for Tnew, and repeat again.
But the problem is
point = y[1] /. f[[1]];
does not work properly in the While loop.
I can do it outside of While loop but not inside.
So, i'm stuck here