# Re: RealValued functions and derivatives

```Ernesto Rico-Schmidt wrote:
>
> Hello Mathematica Group!
>
>   I'm having some troubles with some symbolic differential equations
> that include functions with real and complex parts.  I'm marking these
> functions as RealValued but the mark doesn't seem to remain valid if I
> apply derivatives to the function.  Marking them with RealValued
> doesn't work, I get a message "Recursion depth of 256 exceeded".
>
.......[Ernesto's example is used below]
>
>   Is there any way to convince Mathematica that the derivatives are also
> real valued?

Ernesto:
Here is a trick that should work in more general situations:

In[1]:=
<<Algebra`ReIm`;
Im[t] ^= 0;
RealValued[ux, uy, u1, u2, u3];

The trick is this:
Make two lists of replacement rules; the first list {u1'-> du1, u2'->
du2,u3'-> du3,u4'-> du4}, replaces derivatives with symbols that have
been made RealValues and the second list reverses this (use replacement
rather than assignments (= and :=) to avoid circularity)

In[2]:=
RealValued[du1,du2, du2,du3];
rl1={u1'-> du1, u2'-> du2,u3'-> du3,u4'-> du4};

In[3]:=
rl2= Reverse/@rl1;

Having made these, proceed as before:

In[4]:=
u = 2/3 (Exp[I phi1] u1[t] + Exp[I phi2] u2[t] + Exp[I phi3] u3[t])/.
{phi1->0, phi2->2/3 Pi, phi3->4/3 Pi};

In[5]:=

u = ExpToTrig[u];

In[6]:=
us[t_] := Re[u] + I Im[u];

In[7]:=
Re[D[us[t],t]]

Out[7]=
Im[u2'[t]]    Im[u3'[t]]   2 Re[u1'[t]]   Re[u2'[t]] -(----------) +
---------- + ------------ - ---------- -
Sqrt[3]       Sqrt[3]          3             3

Re[u3'[t]]
----------
3

Finally use the rules

In[8]:=
%/.rl1/.rl2

Out[8]=
2 u1'[t]   u2'[t]   u3'[t]
-------- - ------ - ------
3         3        3

--
Allan Hayes
Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642

```

• Prev by Date: Re: Plotting Data
• Next by Date: Re: Plotting Data