Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose I wanted to solve the following for $a[1], a[2], a[3]$ in the Mathematica code:


with $a[1] = 1$ where $t$ is just a variable and the equation above is identically 0. How would I automate this in Mathematica to get $a[3] = -1, a[2] = -1/2$?

share|cite|improve this question

closed as off-topic by Adam Hughes, Watson, Henrik, Jonas, RecklessReckoner Jun 4 at 21:43

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question is not about mathematics, within the scope defined in the help center." – Adam Hughes, Watson, Henrik, Jonas, RecklessReckoner
If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 2 down vote accepted

In general, you can do it this way:

a[1] = 1; 
Solve[# == 0] & /@ 
 CoefficientList[(a[1] + a[3])*t + (a[1] + 2*a[2])*t^2, t]

Out[1] = {{{}}, {{a[3] -> -1}}, {{a[2] -> -(1/2)}}}

What the above does is it first collects the coefficients of the polynomial using CoefficientList and passes them to Solve which solves each of them.

share|cite|improve this answer

This will do it:

a[1] = 1; Solve[{a[1] + a[3] == 0, a[1] + 2*a[2] == 0}, {a[2], a[3]}]
share|cite|improve this answer
Ah, thanks! But what if instead of 2 relations, I had 100 of them? Is there a way to extract this using a for loop? – Shayla Jun 8 '11 at 4:05
@Shayla: How would you enter the 100 relations into Mathematica? Are they somehow being generated automatically? – Jim Belk Jun 8 '11 at 4:09
@Shayla: Incidentally, Mathematica is a functional programming language (see Though it does have loop constructions, commands like Table, Map, and Apply are considerably more useful. – Jim Belk Jun 8 '11 at 4:12
Yes, so let's say I have a differential equation $f''+f=0$ whose solution I'm going to write as $f(t)=\sum_{n = 1}^{100}a_{n}t^{n-1}$. It would be nice to compute the values of $a_{n}$. – Shayla Jun 8 '11 at 4:14

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