# Calculating a value

I'm trying to calculate the value of F12 and show the value of it on screen. But for some reason I keep getting Null as an output.

Manipulate[
With[{
k = 8.99*10^9,
r = 0.2,
c1 = Abs[x],
c2 = Abs[y],
F12 = k*c1*c2/((r)^2)
},
Print[F12]],
{x, -1, 1},
{y, -1, 1}
]

• You can't nest definitions in With like that, e.g. F12 depends on k, which is defined as one of the local variables in With along with F12, which means that F12 will never see that value of k. – march Oct 22 '16 at 2:58
• What functions(s) should I use to do it then? – John Smith Oct 22 '16 at 3:01
• I mean, @corey979 already has a perfectly respectable fix. I was just explaining why what you did can't work. – march Oct 22 '16 at 3:03

With[{k = 8.99*10^9, r = 0.2},
Manipulate[
F12 = k*Abs[x]*Abs[y]/r^2,
{x, -1, 1}, {y, -1, 1}
]
]


You are seeing Null because that is what Print, by design, should always return. Ordinarily Print would also make a cell with your expression printed in it, but this doesn't work inside Manipulate and your Print command output appears in the messages window instead. The highlighted bit in the messages window image included below is from running your code.

Another problem (highlighted by @march in the comments) is that some of the variables in F12 are not defined properly. This is because With performs a direct replacement of symbols which are set in its first argument. So in your code Manipulate only sees (c1 c2 k)/r^2, where c1, c2, k, and r are not set.

Here is your code with a slight fix allowing F12 to be defined in the second argument of With:

Manipulate[With[{k = 8.99*10^9, r = 0.2}, F12 = k*Abs[x]*Abs[y]/r^2];
Print[F12], {x, -1, 1}, {y, -1, 1}] Dynamic[F12]
(* 2.02275*10^11 *) 