1
$\begingroup$

I made a routine to find roots of the equation for a specific range of input angle. For this model, usually total number of roots is 10, however at some angles total number of roots is 8. Because of this, a table with a list of roots has some rows misaligned roots. When plotting, I end up with zig-zagging line instead some curve. For this case, see row 11th for example. It has 8 roots. By looking at the numbers (see first column of the same row) , I can see 8th root should be 10th, 7th root should be 9th and 6th root should be 8th. And the empty columns for 11th row should be 6 and 7. Is it possible to do root finding thouroughly and alligned properly so that plot can be made consistently?

f[a_]:=Sin[a]*Cos[a]+Sin[a]*x^2-Cos[a]*x^4+(Sin[a]-Cos[a])*x^6-(Sin[2*a]-Cos[2*a])*x^8+(Sin[1*a]-Cos[1*a])*x^10;
roots = Table[x /. NSolve[f[angle] == 0], {angle, 0, 2*Pi, Pi/40}];
roots // TableForm

WolfMath V9

$\endgroup$
2
  • $\begingroup$ similar to this I think.. mathematica.stackexchange.com/q/83906/2079 ( not exactly a dup but you may find something useful there ) $\endgroup$
    – george2079
    Commented Jun 19, 2017 at 15:51
  • $\begingroup$ If you only need plots you might end run the issue by avoiding "special" values of angle that make coefficients exactly zero. For example make your table from 0.001,2 Pi , 0.05 $\endgroup$
    – george2079
    Commented Jun 19, 2017 at 16:00

1 Answer 1

1
$\begingroup$

Writing:

f[a_] := Sin[a] Cos[a] + Sin[a] x^2 - Cos[a] x^4 + (Sin[a] - Cos[a]) x^6 -
         (Sin[2 a] - Cos[2 a]) x^8 + (Sin[a] - Cos[a]) x^10;

roots = Table[If[Sin[angle] - Cos[angle] != 0, x /. NSolve[f[angle] == 0], 
                 ## &[]], {angle, 0, 2 Pi, Pi/40}];

roots // TableForm

you get a table without the two rows where, by canceling the coefficient of the tenth grade degree, the solutions are 8 rather than 10.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.