Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.1K Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

No output from Print inside For

Posted 2 years ago

![enter image description here][1]

Here is the code:

For[i = 1, i = 7, i++
    For[lambda = 0.01, lambda = 0.2, lambda = lambda + 0.001
        Print[
        Log10[R[10^-3, 10^-3, 10^(-i/10), 10^(-i/10), lambda, 0.5, 0]]]
    ]
  ];

Theses are othe fiunctions

ql[Y0A_, Y0B_, etaA_, etaB_, 
  lambda_] := (1 - ((1 - Y0A)/(1 + etaA*lambda)^2) - ((1 - 
       Y0B)/(1 + etaB*lambda)^2) + ((1 - 
       Y0A)*(1 - 
        Y0B)/(1 + etaA*lambda + etaB*lambda - etaA*etaB*lambda)^2))

el[Y0A_, Y0B_, etaA_, etaB_, lambda_, e0_, 
  ed_] := ((e0*
      ql[Y0A, Y0B, etaA, etaB, 
       lambda]) - ((2*(e0 - ed)*etaA*etaB*
        lambda (1 + lambda))/((1 + etaA*lambda)*(1 + etaB*lambda)*(1 +
           etaA*lambda + etaB*lambda - etaA*etaB*lambda))))*(1/
    ql[Y0A, Y0B, etaA, etaB, lambda])

H[x_] := -x*Log2[x] - (1 - x)*Log2[1 - x]
R[Y0A_, Y0B_, etaA_, etaB_, lambda_, e0_, ed_] := 
 0.5*ql[Y0A, Y0B, etaA, etaB, 
   lambda]*(1 - 2 H[el[Y0A, Y0B, etaA, etaB, lambda, e0, ed]])
POSTED BY: Indranil Maiti
2 Replies
Posted 2 years ago

There are syntax errors in the For loops, missing commas. The test needs to be a boolean expression, not a Set.

For[i = 1, i != 7, i++, 
  For[lambda = 0.01, lambda != 0.2, lambda = lambda + 0.001 , 
   Print[Log10[R[10^-3, 10^-3, 10^(-i/10), 10^(-i/10), lambda, 0.5, 0]]]]];

There are much better alternatives to For in the Wolfram Language.

Table[{i, lambda, Log10[R[10^-3, 10^-3, 10^(-i/10), 10^(-i/10), lambda, 0.5, 0]]},
  {i, 1, 7}, {lambda, 0.01, 0.2, 0.001}] // Flatten[#, 1] &

This evaluates to a list of {i, lambda, Log10[R]} for each value of i and lambda, which can be used for subsequent computation, export to a CSV file, ...

POSTED BY: Rohit Namjoshi
Posted 2 years ago
POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard