Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are raising a negative number to the power of a non-inverse (i.e. 1/2, 0.5, 0.25, 0.333333, etc.) which results in a complex number. Like sqrt(-1) aka (-1)^(0.5)</p> <p>Additionally you could also be equating 0/0 in two of your lines of code.</p> <p>Use this code instead: (It takes the absolute value of your power's base (preventing negative values, thus preventing imaginary answers (complex numbers = NaN = -1.#IND)) It also prevents you from dividing by 0 if n == 0... in this event it adds 0.00001 to the denominator</p> <pre><code>for(int j=0; j&lt;=n; j++)//calculation for angles and output displayed to user { Xnew2 = -j*(Y+R1)/((n)+((0.00001)*(n==0)); //calculate x coordinate Ynew2 = Y*(pow(abs(1-(pow((Xnew2/X),2))),0.5)); if(abs(Ynew2) &lt;= R1) cout&lt;&lt;"\n("&lt;&lt;Xnew2&lt;&lt;", "&lt;&lt;Ynew2&lt;&lt;")"&lt;&lt;endl; } { Xnew3 = -j*(Y+R1)/((n)+((0.00001)*(n==0)); //calculate x coordinate Ynew3 = Y*(pow(abs(1-(pow((Xnew3/X),2))),0.5)); //calculate y coordinate if(abs(Ynew3) &lt;= R1) cout&lt;&lt;"\n("&lt;&lt;Xnew3&lt;&lt;", "&lt;&lt;Ynew3&lt;&lt;")"&lt;&lt;endl; //show x,y coordinates } </code></pre> <p>*In the future avoid taking roots of negative numbers (which is the same as raising a negative number to a non-inverse-fraction power), avoid taking a logarithm of a negative number, and avoid dividing by 0 these all produce NaN (-1.#IND)</p> <p><br><br></p> <p>This code may be better (it uses conditional values to make your power's base zero if it is ever less than zero to prevent imaginary answers):</p> <pre><code>for(int j=0; j&lt;=n; j++)//calculation for angles and output displayed to user { Xnew2 = -j*(Y+R1)/((n)+((0.00001)*(n==0)); //calculate x coordinate Ynew2 = Y*(pow(((1-(pow((Xnew2/X),2)))*((1-(pow((Xnew2/X),2)))&gt;(0))),0.5)); if(abs(Ynew2) &lt;= R1) cout&lt;&lt;"\n("&lt;&lt;Xnew2&lt;&lt;", "&lt;&lt;Ynew2&lt;&lt;")"&lt;&lt;endl; } { Xnew3 = -j*(Y+R1)/((n)+((0.00001)*(n==0)); //calculate x coordinate Ynew3 = Y*(pow(((1-(pow((Xnew3/X),2))))*((1-(pow((Xnew3/X),2))))&gt;(0))),0.5)); //calculate y coordinate if(abs(Ynew3) &lt;= R1) cout&lt;&lt;"\n("&lt;&lt;Xnew3&lt;&lt;", "&lt;&lt;Ynew3&lt;&lt;")"&lt;&lt;endl; //show x,y coordinates } </code></pre> <p><br><br> <strong>*<em></strong> I'd also like to point out what "Magtheridon96" mentioned in his answer. The code now makes sure n is not equal to zero otherwise you could be dividing by zero, although I think that would produce #INF not #IND... unless "-j</em>(Y+R1)" is also zero, then it will be 0/0 which will be #IND</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload