Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with real functions in mathematica

In general, mathematica always assumes the most general case, that is, if I set a function

a[s_]:={a1[s],a2[s],a3[s]}

and want to compute its norm Norm[a[s]], for example, it will return:

Sqrt[Abs[a1[s]]^2 + Abs[a2[s]]^2 + Abs[a3[s]]^2]

However, if I know that all ai[s] are real, I can invoke:

Assuming[{a1[s], a2[s], a3[s]} \[Element] Reals, Simplify[Norm[a[s]]]]

which will return:

Sqrt[a1[s]^2 + a2[s]^2 + a3[s]^2]

Which is what I expect.

Problem happens when trying to, for example, derive a[s] and then (note the D):

Assuming[{a1[s], a2[s], a3[s]} \[Element] Reals, Simplify[Norm[D[a[s],s]]]]

Returns again a result involving absolute values - coming from the assumption that the numbers may be imaginary.

What is the way to overcome this problem? I want to define a real-valued function, and work with it as such. That is, for instance, I want its derivatives to be real.

like image 253
Dror Avatar asked Dec 02 '11 11:12

Dror


People also ask

How do you plot real and imaginary parts in Mathematica?

Use ReImPlot to plot the real and imaginary parts of the function. The real part is solid and the imaginary part is dotted. Change the legend and the styles for the real and imaginary parts. Label the real and imaginary parts of the function.

What is true Mathematica?

True is the symbol that represents the Boolean value true. Expressions that can be rigorously established to be true return this symbol. Examples of testing expressions that may return True include Equal, Unequal, SameQ, UnsameQ, Less/Greater/etc., Exists, and quantifier elimination via Resolve.


1 Answers

I would use a custom function instead, e.g.

vecNorm[vec_?VectorQ] := Sqrt[ vec.vec ]

Then

In[20]:= vecNorm[D[{a1[s], a2[s], a3[s]}, s]]

Out[20]= Sqrt[
Derivative[1][a1][s]^2 + Derivative[1][a2][s]^2 + 
 Derivative[1][a3][s]^2]
like image 172
Sasha Avatar answered Oct 21 '22 07:10

Sasha