# Stuck with a .vi

## Recommended Posts

I'm trying to do a quadratic formula .vi I have the equation complete and everything will run fine for real numbers, but when I try to get an answer for the imaginery numbers I can't display it in the indicators all I'm getting is NaN. Any help would be appreciated.

First, put all the formula part into one formula node, it accepts several lines.

Second, while your value "a" is 0 you will always get NaN, since the in second and third formula you divide by (2*a). Division by 0 is by mathematic rules undefined and therefore results to NaN.

I'm trying to do a quadratic formula .vi I have the equation complete and everything will run fine for real numbers, but when I try to get an answer for the imaginery numbers I can't display it in the indicators all I'm getting is NaN. Any help would be appreciated.

The formula nodes work with real number only and the function sqrt() returns NaN for negative arguments.

You should cast A'B'C to complex and use math nodes instead of formula nodes since they handle complex numbers.

Otherwise you have to manipulate real and imaginary parts explicitely like this (not checked for correctness):

float D;

D=B*B-4*A*C;

ReE=-b/(2*A);

ReF=ReF;

if (D>=0)

{

ReE=ReE+sqrt(D)/(2*A);

ReF=ReF-sqrt(D)/(2*A);

ImE=0;

ImF=0;

}

else

{

ImE=sqrt(-D)/(2*A);

ImF=-ImE;

}

Maybe I'm missing something but I do not beleive LV does the math correctly for complex numbers. Isn't the square root of -9 = to 0+3i? If so why does LV give a result of -8.13152E-20 +3 i? It's close but not correct.

Maybe I'm missing something but I do not beleive LV does the math correctly for complex numbers. Isn't the square root of -9 = to 0+3i? If so why does LV give a result of -8.13152E-20 +3 i? It's close but not correct.

That may be 1 bit flip from zero... I'm not sure. there are issues sometimes with numbers that approach zero when using double/single data types.

Besides that however, I wire a complex into the squareroot and get the correct answer out (0 + 3i)... what were you using exactly to get your result? The expression node didn't seem to work with a complex number and neither did the formula node so I couldn't figure out what you were doing.

How would you wire it then to have it accept complex numbers because each time that I'm doing it I'm getting errors.

• 2 weeks later...

I am feading a constant complex double (CDB) set to -9+0i into the square root function and displaying the result.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×