0
$\begingroup$

I am dealing with a problem in electromagnetism involving problems in different regions, and there is something that I haven't been able to figure out yet. What I would like to be able to do is take an algebraic expression in terms of symbolic functions and constants, and give them labels depending on which side of an interface they are at (thus creating new functions/constants).

As a minimal working example, consider the quantity

$$\frac{1}{\mu}\dfrac{\partial B}{\partial x} $$

where $\mu$ is a constant and $B = B(x,y,z)$ is an arbitrary function. What I would really like to do is write a function which evaluates the above at some ordinate given by a label $\rm{f}$, and another, $\rm{s}$, and compute the difference between them. In other words: I would like Mathematica to analytically compute

$$ \left[\dfrac{1}{\mu} \dfrac{\partial B}{\partial x} \right]^{\rm f}_{\rm s}:=\dfrac{1}{\mu_{\rm f}}\dfrac{\partial B_{\rm f}}{\partial x}-\dfrac{1}{\mu_{\rm s}}\dfrac{\partial B_{\rm s}}{\partial x}$$ particularly so that the variables with subscripts can be used later on (e.g. replaced with specific values, or manipulated as a function so that it can be obtained as a solution to a differential equation). In particular, I would like (a) the subscripting procedure to work inside of differential operators as seen above, and (b) the option to specify variables which are unchanged by the above procedure (e.g. due to being continuous across the interface).

I know you can use something like

AtFunc[func_[vars__], label_] := Subscript[func, label][vars]

to give a label to a function, but how can this be adapted to (a) apply to constants as well as functions, and (b) adjusted so that the labelling goes inside the derivatives?

EDIT: I am only looking for a solution which gives me a symbolic expression, not a numerical solution to any problem. The goal of this is to automate the "writing down" of the model I am to solve, before applying numerical (or asymptotic) methods of any sort.

$\endgroup$
4
  • $\begingroup$ It is not clear if you are looking for a numerical solution or something else. Have you looked at Electric Motor Example? $\endgroup$
    – Tim Laska
    Oct 12 '20 at 14:30
  • $\begingroup$ @TimLaska I am not looking for a numerical solution. I am just after a symbolic expression which is given by the definition above. $\endgroup$ Oct 12 '20 at 14:31
  • $\begingroup$ The link does show how to model jump conditions to non-linear material models using a Piecewise function and ElementMarkers as applied to a numerical example. $\endgroup$
    – Tim Laska
    Oct 12 '20 at 15:13
  • $\begingroup$ I appreciate that, although the goal of what I Mathematica to do is to quickly generate the governing equations and boundary conditions for a complicated TEMHD problem so I can then use an alternative method to attempt to solve the problem. $\endgroup$ Oct 12 '20 at 15:25
1
$\begingroup$

If I understand correctly, this should be easy. First, as μ is a constant, it does not need an index and I do not write it in the following. Second, I think it is a bad idea to write a arguments like your "f" and "s" as sub- and superscript. They are arguments, so treat them like arguments.

The derivative of B[x] can simply be written as B'[x]. Therefore, to specify a function that gives the difference of the derivatives at two arguments, we may write:

diff[a_,b_]= B'[a] - B'[b]

Now if you want to generalize this for a general func B we may write:

diff[fun:B_,a_,b_]

Let's make an example:

 diff[Sin, 0, 1]
(*1 - Cos[1]*)

Have fun.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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