1
$\begingroup$

enter image description hereI have a nonlinear equation in single variable( $x \tan(x)=5$ ) and it have an infinite number of roots , I got some of them and I want to add them in a table this is my code please, tell me how to do this?

(* In[1]:= *) Reduce[x Tan[x] == 5 && 0 <= x <= 100, x]

then I used a ToRule to convert the || to

(* In[2]:= *) ToRules[Out[1]]

then I used export to export all roots to excel sheet but i got failed

Export["myfile.xls", Out[2]]

Export::noelem: {x->Root[{-5+#1 Tan[Slot[<<1>>]]&,4.0335677903399816532}]} is not a valid set of export elements for the XLS format.

(* Out[3] = $Failed *)
$\endgroup$
6
  • $\begingroup$ "this is my code" - where? $\endgroup$ – J. M.'s ennui May 9 '20 at 3:37
  • 1
    $\begingroup$ Reduce[x Tan[x] == 5 && 0 <= x <= 100, x] $\endgroup$ – Ragab Mohamed May 9 '20 at 3:43
  • 1
    $\begingroup$ n = ToRules[Out[53]] $\endgroup$ – Ragab Mohamed May 9 '20 at 3:44
  • 1
    $\begingroup$ Edit your question to include this information, instead of leaving it in comments. $\endgroup$ – J. M.'s ennui May 9 '20 at 3:44
  • 1
    $\begingroup$ now you can see my code $\endgroup$ – Ragab Mohamed May 9 '20 at 3:48
6
$\begingroup$

Actually, the conversion of Sequence into the List can be done easy:

   a=ToRules@Reduce[x Tan[x] == 5 && 0 <= x <= 100, x];
   b=x /. List[a];
   Export["file.xlsx", b]

The Export gives you an Excel file with the desired column of numbers

$\endgroup$
1
  • 1
    $\begingroup$ Thank you very much , you did it $\endgroup$ – Ragab Mohamed May 9 '20 at 5:08
6
$\begingroup$

I think you probably want to use NSolve instead of Reduce.

roots = x /. NSolve[x Tan[x] == 5 && 0 <= x <= 100, x]
Export["outfile.xls", roots]

This will produce a column of 32 roots, which I think is what you want.

$\endgroup$
1
  • 1
    $\begingroup$ Thank you very much , you did it $\endgroup$ – Ragab Mohamed May 9 '20 at 5:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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