20 votes

Expressing a polynomial as a sum of squares

Here is a somewhat heuristic approach, that relies in this case on the SOS having integer coefficients. I will indicate an alteration that gives a numerical approximation in the general case. Start ...
Daniel Lichtblau's user avatar
17 votes

How does Mathematica calculate $\sin(\pi/5)$?

In the course of answering this question, I ran into a little bit of weirdness that doesn't square with my experience with previous versions of Mathematica. I think writing this answer is as good a ...
J. M.'s missing motivation's user avatar
17 votes
Accepted

What is Mathematica's equivalent to Maple's collect with distributed option?

CoefficientRules[eq, {x, y}] /. ({a_, b_} -> c_) :> c x^a y^b // Total Generalize it to a function: ...
xzczd's user avatar
  • 66k
16 votes
Accepted

Lagrangian to Hamiltonian

Here is how you would do it using the standard add-on package VariationalMethods, which is meant for calculations like this: ...
Jens's user avatar
  • 97.3k
14 votes

How to extract all the coefficients of a homogeneous polynomial

Using an undocumented function: ...
14 votes

Differentiating functions of vectors/matrices?

In this post I discuss a function MatrixD which attempts to take a matrix derivative following the guidelines given in the The Matrix Cookbook. I still want to ...
Carl Woll's user avatar
  • 131k
13 votes

Is it possible to have Mathematica move all terms to one side of an inequality?

Since Mathematica 11.3 you can use SubtractSides, that works for equations and inequalities, for example ...
rhermans's user avatar
  • 36.5k
13 votes
Accepted

Factor a polynomial Root into Roots of smallest possible degree

A constructive approach The problem can be solved if the form of the solution is given. Define the two factors using a hint (that these should be cubic equations) in the original post ...
yarchik's user avatar
  • 18.3k
13 votes
Accepted

How can I make Mathematica do, ArcTanh[x] + ArcTanh[y] = ArcTanh[x+y/1+xy]?

A little bit of trickery: ArcTanh[x] + ArcTanh[y] // Tanh // TrigExpand // FullSimplify // ArcTanh (* ArcTanh[(x + y)/(1 + x y)] *) Note the parentheses.
11 votes

How do I use "Factor" to get this form

HornerForm[x1 x2 + x1 x3 x4 + x1 x3 x5] (* x1 (x2 + x3 (x4 + x5)) *)
John Doty's user avatar
  • 13.7k
11 votes

Finding coefficients in polynomial function

One liner: Solve[PolynomialRemainder[6 x^3 - 5 x^2 - 12 x + k, 3 x + 2, x] == 0, k]
11 votes
Accepted

Extract common factor

I think PolynomialGCD is the most direct tool: ...
Carl Woll's user avatar
  • 131k
11 votes
Accepted

Computing the seven roots of a polynomial

poly = x^7 + x^6 - 18 x^5 - 35 x^4 + 38 x^3 + 104 x^2 + 7 x - 49; Find an extension in which the polynomial splits: ...
Michael E2's user avatar
  • 236k
11 votes
Accepted

How do two equations multiply left by left equals right by right?

I much prefer MultiplySides[eq1, eq2] //Expand to BobHanlon's otherwise fine solution. It also generalizes quite nicely to ...
David G. Stork's user avatar
11 votes

What is Mathematica's equivalent to Maple's collect with distributed option?

Update 2: An alternative way to define a function that works like Maple's collect using CoefficientRules + FromCoefficientRules: ...
kglr's user avatar
  • 395k
10 votes

Lagrangian to Hamiltonian

genCoords = {x[t]}; ke = 1/2 m x'[t]^2; v = 1/2 k x[t]^2; q = -c x'[t]; l = ke - v; Solve for x'[t] in terms of ...
march's user avatar
  • 23.4k
10 votes
Accepted

How can I simplify a super long expression?

It might help to be familiar with how expressions are structured in the Wolfram Language. Try reading through some of the tutorials here, particularly this one about expressions as trees and then this ...
ccosm's user avatar
  • 408
10 votes

Mathematica function equivalent to MATLAB's residue function (partial fraction expansion)

This is cheating, but: ...
Daniel Lichtblau's user avatar
10 votes
Accepted

Working in Mathematica over a cyclotomic ring

PolynomialMod[x^20 + x^8 + x + 3, x^7 - 1] 3 + 2 x + x^6.
cvgmt's user avatar
  • 72.7k
10 votes
Accepted

Present a logarithm in terms of two logarithms

There doesn't seem to be a single built-in function for the task, but I can think out a solution involving a bit manual analysis. First use PowerExpand: ...
xzczd's user avatar
  • 66k
9 votes

Factor a polynomial Root into Roots of smallest possible degree

I'll show the resultant formulation for the degree 15 example. The polynomial in question: ...
Daniel Lichtblau's user avatar
9 votes
Accepted

Finding an analytic solution of a cubic equation

It comes with which roots correspond to which branches of a cubic root in the exact expression. For instance, consider the simpler $$y^3 = z$$ Then my three solutions are $y=\sqrt[3]{z}$, $y=(-1)^{2/...
Alex Meiburg's user avatar
9 votes
Accepted

Can't get Mathematica to simplify an expression

A few things of note: Like @m_goldberg suggested, it is wise to explicitly state d ∈ Reals, s ∈ Reals. Because you introduced .'...
Feyre's user avatar
  • 8,597
9 votes
Accepted

Factor a polynomial over the reals

One way is to find the roots, separate into real and complex, further separate the complex ones into conjugate pairs, then reform as a factorization (taking into account the leading coefficient). I'll ...
Daniel Lichtblau's user avatar
9 votes
Accepted

Expressing $x_{1} ^ n + x_{2}^ n$, where $x_{1}$ and $x_{2}$ are the roots of $ax^2 +bx+c=0$

SymmetricReduction is a good tool for this: ...
Carl Woll's user avatar
  • 131k
9 votes
Accepted

Collecting the terms of a multi-variable polynomial

You can use the third argument of Collect to bind the coefficients in something like Hold. Afterwards, release the hold or ...
Michael E2's user avatar
  • 236k
9 votes

Reconstructing a polynomial from its coefficient array

Internal`FromCoefficientList[mat, {x, y}] 3 + 2 x + 5 x^3 + 8 x y + 6 x^2 y + 7 x y^2 + 4 y^3 ...
kglr's user avatar
  • 395k
9 votes
Accepted

How to implement split-complex numbers?

Try this: J /: Power[J, p_Integer?OddQ] := J J /: Power[J, p_Integer?EvenQ] := 1 J^Range[-10, 10] {1, J, 1, J, 1, J, 1, J, 1, J, 1, J, 1, J, 1, J, 1, J, 1, J, ...
Henrik Schumacher's user avatar
9 votes
Accepted

Is it possible to make Decompose work with coefficients containing radicals?

One way to decompose a polynomial $p(x)$ is to factor $p'(x)$ over a field and exploit $\frac{d}{dx}f(g(x)) = f'(g(x))g'(x)$. The following code does just that to find all candidate $g'(x)$: ...
Greg Hurst's user avatar
  • 35.9k
9 votes
Accepted

How to apply chain rule to a differential equation

deq = y''[x] + (epsilon - x^2) y[x]; deq /. {y -> (y[#^2] &)} /. x -> Sqrt[s] (*(epsilon - s) y[s] + 4 s y''[s] + 2 y'[s]*)
Bill Watts's user avatar
  • 8,217

Only top scored, non community-wiki answers of a minimum length are eligible