Philley Posted December 8, 2005 Report Posted December 8, 2005 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. Download File:post-3066-1134010336.vi Quote
didierj Posted December 8, 2005 Report Posted December 8, 2005 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. Download File:post-253-1134023630.vi Quote
jpdrolet Posted December 8, 2005 Report Posted December 8, 2005 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; } Quote
DredPirate Posted December 8, 2005 Report Posted December 8, 2005 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. Quote
m3nth Posted December 8, 2005 Report Posted December 8, 2005 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. Quote
Philley Posted December 9, 2005 Author Report Posted December 9, 2005 How would you wire it then to have it accept complex numbers because each time that I'm doing it I'm getting errors. Quote
DredPirate Posted December 21, 2005 Report Posted December 21, 2005 I am feading a constant complex double (CDB) set to -9+0i into the square root function and displaying the result. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.