-4
$\begingroup$
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?

$\endgroup$
5
  • $\begingroup$ T1 doesn't change inside the loop? Perhaps Monitor is what you are looking for. $\endgroup$ Nov 14, 2019 at 8:09
  • $\begingroup$ can you please explain. and no T1 doesnot cahnge inside the loop $\endgroup$
    – vijay
    Nov 14, 2019 at 8:13
  • $\begingroup$ Inside your for-loop you use a parameter T1 , which isn't influenced by the for-loop. $\endgroup$ Nov 14, 2019 at 8:17
  • $\begingroup$ so what can i do now? $\endgroup$
    – vijay
    Nov 14, 2019 at 8:24
  • $\begingroup$ Inside your for-loop should be a line T1=... which evaluates a new T1. $\endgroup$ Nov 14, 2019 at 8:26

3 Answers 3

2
$\begingroup$

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

soln

Notes

  1. There are syntax errors in your code. 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.
  2. To solve for 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.
  3. I use Quiet to suppress some warning messages issued by NSolve, because I think they would alarm you more than they inform you.
$\endgroup$
3
$\begingroup$

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}]

enter image description here

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 *)
$\endgroup$
0
$\begingroup$

The parameter T1doesn'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.

$\endgroup$
4
  • $\begingroup$ but i need the value of T1 for different values of mu=0,1,2,3,4,5 $\endgroup$
    – vijay
    Nov 14, 2019 at 9:38
  • 1
    $\begingroup$ There is no calculation inside your for -loop which changes T1 !!! $\endgroup$ Nov 14, 2019 at 9:48
  • $\begingroup$ so what should be the program for that? $\endgroup$
    – vijay
    Nov 14, 2019 at 9:49
  • 2
    $\begingroup$ You should know that! Is the expression 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

Not the answer you're looking for? Browse other questions tagged or ask your own question.