3
$\begingroup$

If I have expression like

a1/x +a2/x^2 + a3/x^3 

I want to return 1/x^3. In general case,

a1/x +a2/x^2 + a3/x^3 + a4/x^4 .....

I will have 1/x^n

Edit:

If I want to print the parameter together, what do I need to do? like an/x^n?

$\endgroup$
1
  • 1
    $\begingroup$ have you looked at documentation for Exponent? It seems you can get what you want using the code below or a variant thereof (depending on how you want to handle coefficients). In[1901]:= x^Exponent[a/x + b/x^2 + c/x^3, x, Min] Out[1901]= 1/x^3 $\endgroup$ Apr 7, 2016 at 15:08

2 Answers 2

5
$\begingroup$
exp=a1/x + a2/x^2 + a3/x^3;   
v=Min@Cases[exp, Power[_, x_?NumberQ] :> x, -1];
Cases[exp, Times[x_, Power[_, v]], -1]
$\endgroup$
2
  • $\begingroup$ I apologize for asking more question, I forgot to include in the question. If I want to print with the parameter a3/x^3, What would I do? $\endgroup$
    – Saesun Kim
    Apr 7, 2016 at 0:05
  • $\begingroup$ @SaesunKim see update. Thanks $\endgroup$ Apr 7, 2016 at 0:34
5
$\begingroup$

You can get all the informations you want in a list, Then to pick the min. It will be the first. The largest is at the end.

expr = a1/x + a2/x^2 + a3/x^3 + a4 x^5 + x^6;
r = {Coefficient[#, x, Exponent[#, x]], #, Exponent[#, x]} & /@ (List @@ expr)

Mathematica graphics

To get the answer you want, now simply pull the second entry in the first cell

 r[[1, 2]]/r[[1, 1]]

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ Thank you so much for your help! $\endgroup$
    – Saesun Kim
    Apr 7, 2016 at 0:54

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.