I made the algorithm converge to an answer; I have no idea if it is correct. Here are the changes I made:
I replaced the statement Twater = Tnew, with Cwater = QuantityMagnitude[
ThermodynamicData["Water",
"ThermalConductivity", {"Temperature" ->
Quantity[Tnew, "Kelvins"]}]]; <-- note the Tnew here.
I added the variable prevTnew, initialized it to 10^5, and set it to Tnew just before Tnew is computed.
I changed the completion test to (Abs[prevTnew - Tnew] > tol) && (iters++ < iterLim).
Also, please note I created the variable plotList, and initialized it to plotList = {}. Then after you compute point, I added AppendTo[plotList, point]. Later, you could put in Print[ListPlot[plotList]] if the reason you compute point is to plot it. I don't understand the 100 in point.
Here is the new routine:
prog := Module[{Twater = 300., Tnew = 0, Cwater, Dwater, Ewater,
ClassicalRungeKuttaCoefficients, f, x, y, 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;
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 = ParametricNDSolveValue[{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[3.], {x, 0., 3.}, z,
Method -> {"ExplicitRungeKutta", "DifferenceOrder" -> 4,
"Coefficients" -> ClassicalRungeKuttaCoefficients},
StartingStepSize -> 1/10];
point = {z /. FindRoot[f[z] == 100., {z, 1}, Evaluated -> False],
100.};
AppendTo[plotList, point];
Print[point];
FindRoot[f[z] == 100., {z, 1}, Evaluated -> False];
prevTnew = Tnew;
Tnew =
170 + 1.89*z /.
FindRoot[f[z] == 100., {z, 1}, Evaluated -> False];
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];
];