0
$\begingroup$

I have a non linear equation and want to create a polynomial of that. For this I have to calculate the coefficients. The problem is that the equation is a little bit long. So I wanted to do it with Mathematica. I tried it with the function coeffs but this didn't work.

0 =-s2 + s1 + th3*(v1 + (b1 - j2*x)^2/(2*j2) + (j2*x^2)/2 - (b1*(b1 - j2*x))/j2 + j2*x*th1) + ((j2*th3)/2 + (4*j2*v1 - 4*j2*v2 - 2*b1^2 + 2*b2^2 + 4*j2^2*x^2 + j2^2*th3^2 + 4*j2^2*x*th1)^(1/2)/2)^3/(6*j2^2) + x*(v1 + (b1 - j2*x)^2/(2*j2) - (b1*(b1 - j2*x))/j2 + j2*x*th1) - (j2*th3 - 2*b2 + (4*j2*v1 - 4*j2*v2 - 2*b1^2 + 2*b2^2 + 4*j2^2*x^2 + j2^2*th3^2 + 4*j2^2*x*th1)^(1/2))^3/(48*j2^2) - (b1 - j2*x)^3/(6*j2^2) + (j2*x^3)/3 + th1*(v1 + (b1 - j2*x)^2/(2*j2) - (b1*(b1 - j2*x))/j2) + (th3^2*((j2*th3)/2 + (4*j2*v1 - 4*j2*v2 - 2*b1^2 + 2*b2^2 + 4*j2^2*x^2 + j2^2*th3^2 + 4*j2^2*x*th1)^(1/2)/2))/2 + (v1 + (b1 - j2*x)^2/(2*j2) + (j2*x^2)/2 - (b1*(b1 - j2*x))/j2 + j2*x*th1)*(tau - x - th1 - th3 + (j2*th3 - 2*b2 + (4*j2*v1 - 4*j2*v2 - 2*b1^2 + 2*b2^2 + 4*j2^2*x^2 + j2^2*th3^2 + 4*j2^2*x*th1)^(1/2))/(2*j2) + (b1 - j2*x)/j2 + ((j2*th3)/2 + (4*j2*v1 - 4*j2*v2 - 2*b1^2 + 2*b2^2 + 4*j2^2*x^2 + j2^2*th3^2 + 4*j2^2*x*th1)^(1/2)/2)/j2) + (j2*x*th1^2)/2 - (v1*(b1 - j2*x))/j2 - ((j2*th3 - 2*b2 + (4*j2*v1 - 4*j2*v2 - 2*b1^2 + 2*b2^2 + 4*j2^2*x^2 + j2^2*th3^2 + 4*j2^2*x*th1)^(1/2))*(v1 - ((j2*th3)/2 + (4*j2*v1 - 4*j2*v2 - 2*b1^2 + 2*b2^2 + 4*j2^2*x^2 + j2^2*th3^2 + 4*j2^2*x*th1)^(1/2)/2)^2/(2*j2) + th3*((j2*th3)/2 + (4*j2*v1 - 4*j2*v2 - 2*b1^2 + 2*b2^2 + 4*j2^2*x^2 + j2^2*th3^2 + 4*j2^2*x*th1)^(1/2)/2) + (b1 - j2*x)^2/(2*j2) + (j2*x^2)/2 - (b1*(b1 - j2*x))/j2 + j2*x*th1))/(2*j2) - (((j2*th3)/2 + (4*j2*v1 - 4*j2*v2 - 2*b1^2 + 2*b2^2 + 4*j2^2*x^2 + j2^2*th3^2 + 4*j2^2*x*th1)^(1/2)/2)*(v1 + (b1 - j2*x)^2/(2*j2) + (j2*x^2)/2 - (b1*(b1 - j2*x))/j2 + j2*x*th1))/j2 + (b1*(b1 - j2*x)^2)/(2*j2^2) + (((j2*th3)/2 + (4*j2*v1 - 4*j2*v2 - 2*b1^2 + 2*b2^2 + 4*j2^2*x^2 + j2^2*th3^2 + 4*j2^2*x*th1)^(1/2)/2)*(j2*th3 - 2*b2 + (4*j2*v1 - 4*j2*v2 - 2*b1^2 + 2*b2^2 + 4*j2^2*x^2 + j2^2*th3^2 + 4*j2^2*x*th1)^(1/2))^2)/(8*j2^2)

or available here

expr = ToExpression@Import["https://pastebin.com/raw/91YKVF4N"]

There are only parameter in this function excepts of x which is the variable.

$\endgroup$

closed as unclear what you're asking by Henrik Schumacher, Daniel Lichtblau, MarcoB, JimB, m_goldberg Jul 23 '18 at 23:17

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    $\begingroup$ It is not clear what you are asking for: If the expression is an equation you should use 0==... instead of 0=... ! Do you want to solve this equation (Solve[...]) or expand around x=... (Series[...])? $\endgroup$ – Ulrich Neumann Jul 23 '18 at 6:18
  • 1
    $\begingroup$ There is no function coeffs, details are important!. Edit your question to explain in detail what you need and share the code you say didn't work. $\endgroup$ – rhermans Jul 23 '18 at 7:56
  • $\begingroup$ How would the nonlinear equation and the polynomial that you want to create be related to each other? $\endgroup$ – Henrik Schumacher Jul 23 '18 at 8:05
1
$\begingroup$

If you expression is already a polynomial (your example) then use CoefficientList.

With[
 {
  expr = ToExpression@Import["https://pastebin.com/raw/91YKVF4N"]
  },
 CoefficientList[expr, x]
 ]

Mathematica graphics

If not, you can get the Series first.

With[
 {
  expr = Exp[x]
  },
 CoefficientList[
  Normal@Series[expr, {x, 0, 5}]
  , x
  ]
 ]

Mathematica graphics

Side note:

Do not confuse Set(=) with Equal (==).

$\endgroup$
  • $\begingroup$ But is this a polynom ? because i have the variable x in the expression of the coefficients $\endgroup$ – IlPad Jul 25 '18 at 19:20

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