For[mu = 0; mu < 6, mu++,
mu = -4.84*10^(-4) - 17.82*10^(-4)*T1 +
1.53*10^(-4)*T1*2.303*Log[T1]; Print[T1]]
I want to get the value of T1
for values of mu up to 5. How can I get them?
Perhaps this is what you are looking for. It is the best I can do when trying to guess what you really want to compute. My goal here is show you how your For-loop can be fixed, rather than to instruct you in the better methods available to solve your problem.
For[mu = 0, mu < 6, mu++,
sol =
Quiet @ NSolve[
mu == -4.84*10^(-4) - 17.82*10^(-4) T1 + 1.53*10^(-4) 2.303 T1 Log[T1],
T1];
Print[mu, " ", (T1 /. sol) // First]]
When evaluated the above code prints
Notes
mu = 0; ...
should be mu = 0, ...
, and mu = -4.84*10^(-4) - 17.82*10^(-4)*T1 + 1.53*10^(-4)*T1*2.303*Log[T1]
is not a request to solve an equation, it is assignment to the variable mu
.T1
at each iteration is a more complicated process. I show you a method using NSolve
. Bob Hanlon shows you another way to do it.Quiet
to suppress some warning messages issued by NSolve
, because I think they would alarm you more than they inform you.For
is generally avoided as inefficient. Using a pure Function
with Map
data = T1 /.
Solve[# == -4.84*10^(-4) - 17.82*10^(-4)*T1 +
1.53*10^(-4)*T1*2.303*Log[T1], T1][[1]] & /@ Range[0, 5] // Quiet
(* {158.54, 1329.7, 2164.72, 2915.71, 3619.49, 4291.32} *)
Plotting the results
ListLinePlot[data, DataRange -> {0, 5}, AxesLabel -> {mu, T1}]
Alternatively, using Table
data2 = Table[
T1 /. Solve[
mu == -4.84*10^(-4) - 17.82*10^(-4)*T1 + 1.53*10^(-4)*T1*2.303*Log[T1],
T1][[1]], {mu, 0, 5}] // Quiet
(* {158.54, 1329.7, 2164.72, 2915.71, 3619.49, 4291.32} *)
The different methods provide identical results
data === data2
(* True *)
The parameter T1
doesn't change inside the for-loop.
Here I give a working version
For[mu = 0, mu < 6,mu++, -4.84*10^(-4) - 17.82*10^(-4)*T1 + 1.53*10^(-4)*T1*2.303*Log[T1]; Print[T1]]
which prints T1
6 times.
T1
!!!
$\endgroup$
Nov 14, 2019 at 9:48
mu = -4.84*10^(-4) - 17.82*10^(-4)*T1 + 1.53*10^(-4)*T1*2.303*Log[T1]
an equation which must be solved for T1?
$\endgroup$
Nov 14, 2019 at 9:54
T1
doesn't change inside the loop? PerhapsMonitor
is what you are looking for. $\endgroup$T1=...
which evaluates a new T1. $\endgroup$