LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to enter an imaginary number in a formula node?

I would like to enter the following into a forumla node - exp(j*x) where j is the square root of -1
0 Kudos
Message 1 of 13
(16,428 Views)
The only input types specified for formula node are float and integer.
Iyou wish to connect the real or imaginary parts of the complex double as input to the formula node, you can do so by using the Complex to Re/Im.vi from the Functions Palette under Numeric > Complex.

Zvezdana S.
National Instruments
0 Kudos
Message 2 of 13
(16,429 Views)

Following the question above, is there anyway of outputting a complex number from a formula node? Whenever I try it (for example as shown in the VI attached) I get a NaN even if the indicator is defined as a complex single. Is there any way of getting an imaginary result from a formula node then? The answer to the equation in the sample VI should be 3i but I am not getting that out.

 

Thanks for your help

0 Kudos
Message 3 of 13
(16,211 Views)
In your formula, rTT = sqrt((1.5**2)*((sin(1))**2)-9);, which part is real and which is imaginary?  The imaginary part has to contain the square root of -1.  If you remove the sqrt from the formula, the answer is -7.40683.  If you take the absolute value to get 7.40683 and then take the square root, you get 2.72155.  So is this complex number 0 + 2.72155i?  Somewhere, the real and imaginary part have to be separated.
- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 13
(16,198 Views)
Yes the answer is 0+2.7i which is approximately 3i.In the equation  itself there are no imaginary and real parts. If I put a different set of numbers I could get a real number out. In the VI i sent I tried seperating the real and imaginary part at the output but that was no good. So there is no way of getting an imaginary answer at the output without having to manipulate the formula itself (i.e. remove the square root, take absolute and then square root)?
0 Kudos
Message 5 of 13
(16,191 Views)
That is right.  you cannot get an imaginary output from the formula.  Labview will report the square root of a negative number as NaN.  You have to calculate the real part separately from the imaginary part.  Then you have to take the absolute value of the imaginary part to get the square root.  Then you can join the two together to make a complex number.
- tbob

Inventor of the WORM Global
0 Kudos
Message 6 of 13
(16,173 Views)


@chevinator wrote:
I would like to enter the following into a forumla node - exp(j*x) where j is the square root of -1

Don't underestimate the power of LabVIEW! 

 "Exp" is an atomic function that works correctly with complex inputs. There is no reason to use a formula node at all.

Simply feed your complex number to the "exponential" function and you're all set! 😄

(If you want to to textual complex math, upgrade to LabVIEW 8.0 and use a Mathscript node ;))

Message Edited by altenbach on 02-14-2007 09:46 AM

Message 7 of 13
(16,166 Views)

Dear altenbach,

 

it is not about computing any (complex) value with a LabVIEW primitive, but to get the formula node to calculate/evaluate complex values specifically. The formula node cannot be combined with LabVIEW primitives, can it? And one cannot implement/write a complex value in the formula node, i.e., there is no function for it. Search for "Formula Node and Expression Node Functions" in any LabVIEW help.

 

And indeed, the square root primitive chokes in negative numbers (i.e., the result is NaN).

 

Kind regards

0 Kudos
Message 8 of 13
(14,567 Views)

Why this response to a 6 1/2 year old thread?

 

Correct, formula nodes don't handle complex numbers.

 

But you don't need formula nodes when LabVIEW primitives will work.  Square root DOES work on -1 as long as you properly define the control/wire going into the function as a complex double representation as well as the indicator coming out of it.

 

 

0 Kudos
Message 9 of 13
(14,553 Views)

Dear RavensFan,

 

thank you for your post.

 

There is a reason why formula nodes and formula strings exist. And they do not allow for evaluating complex numbers. That is a state-of-art in LV12 and lower. Answering, that the user can solve it with a complex-friendly primitive does not change this fact.

 

My personal example is a "Downhill Simplex nD.vi", which theoretically allows for optimising a real 2D function f(DBL1,DBL2)=DBL, but it does not allow solving complex function f(CDB)=DBL. Some CDB functions are just too complex to be separated to f(DBL1,DBL2) (where CDB=DBL1+iDBL2).

 

In the above example, one could possibly change the operation 34 in the following file:

 

C:\Program Files (x86)\National Instruments\LabVIEW 2012\vi.lib\gmath\parser.llb\Three Register Calculation.VI

 

but sqrt does not allow for "DBL -> sqrt -> CDB" conversion. So, your suggestion cannot be implemented.

 

Kind regards

 

 

p.s. This thread is not LV-version dependent and the question is not answered or is unclear, IMHO. Therefore, I decided to post and update. Please, suggest automatic locking of threads older than X years to administrators of the forum, if you feel there is a need for it.

0 Kudos
Message 10 of 13
(14,536 Views)