Jump to content

Stuck with a .vi


Philley

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.

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;

}

Link to comment
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.

Link to comment
  • 2 weeks later...

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.