Message Boards Message Boards

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

[?] Get the right Units in this piece of code?

Posted 7 years ago

I am getting the magnetic scalar potential of a bar magnet:

rbm = Entity["PhysicalSystem", "RectangularBarMagnet"][
   "MagneticScalarPotential"];

I make it Active:

rbmmsp[x_, y_, z_] = Activate[rbm];

Then, I differentiate it to get the magnetic field:

rbmmf[x_, y_, 
   z_] = -D[
    rbmmsp[x, y, 
     z], {{QuantityVariable["x", "Length"], 
      QuantityVariable["y", "Length"], 
      QuantityVariable["z", "Length"]}}];

Then, I would like to see what is its value, - if I give some values to system variables M0,a,b,c -, in a given {x,y,z} point. So, I do:

(* Let's see how does it look like for a point at {0.03,0.03,0.03} \
from the (0.01,0.01,0.01) cube.  Lengths are in Meters*)

mmf = rbmmf[x, y, 
    z] //. {Subscript["M", 0] -> Quantity[10^6, "Ampere/Meter"], 
    "a" -> Quantity[0.03, "Meter"] , "b" -> Quantity[0.03, "Meter"], 
    "c" -> Quantity[0.03, "Meter"], "x" -> Quantity[0.01, "Meter"], 
    "y" -> Quantity[0.01, "Meter"], "z" -> Quantity[0.01, "Meter"]};

My expectation is, that if at this point I ask for the QuantityMagnitude and QuantityUnit of mmf//N, I should have a simple three component numeric vector for magnitudes and an "A/m" for unit. Well, looks like my expectations are overwritten.

{QuantityMagnitude[mmf // N], QuantityUnit[mmf // N]}

Units

What is wrong here? Thanks ahead, János

POSTED BY: Janos Lobb
2 Replies
Posted 7 years ago

Thanks Gianluca Gomi! Your reply helped a lot.

POSTED BY: Janos Lobb

The correct substitutions should be

mmf = rbmmf[x, y, 
   z] //. {QuantityVariable[Subscript["M", 0], "Magnetization"] -> 
    Quantity[10^6, "Ampere/Meter"], 
   QuantityVariable["a", "Length"] -> Quantity[0.03, "Meter"], 
   QuantityVariable["b", "Length"] -> Quantity[0.03, "Meter"], 
   QuantityVariable["c", "Length"] -> Quantity[0.03, "Meter"], 
   QuantityVariable["x", "Length"] -> Quantity[0.01, "Meter"], 
   QuantityVariable["y", "Length"] -> Quantity[0.01, "Meter"], 
   QuantityVariable["z", "Length"] -> Quantity[0.01, "Meter"]}

and then

mmf /. a_*Log[b_] :> Log[b^a] //. Log[a_] + Log[b_] :> Log[a*b]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract