0
$\begingroup$

This question already has an answer here:

I have a couple of questions about the problem I am trying to solve

n = 7;
alpha = 0.01; c = 10;

atable = Table[a[i], {i, 0, n}]; 
Solu = y^Range[0, n].atable;

Leftequ = Solu; 
Rightequ =  A y^2 +  B y + DD + 1/2/alpha Integrate[Solu^2, y];

Lec = CoefficientList[Leftequ, y];
Rec = CoefficientList[Rightequ, y];

Lec = PadRight[Lec, Min[Length[Lec], Length[Rec]]];
Rec = PadRight[Rec, Min[Length[Lec], Length[Rec]]];

eqs = Lec == Rec;

Sol = Solve[eqs, atable]

If I check a[0] it will show that a[0]=a[0], but I want to set it to a[0] = DD. This is probably a mistake I overlooked, but nevertheless could not find it. Thanks in advance.

$\endgroup$

marked as duplicate by m_goldberg, Yves Klett, bobthechemist, Mr.Wizard Feb 5 '14 at 16:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1
$\begingroup$

The result you see is a list of replacement rules (check documentation). If you want to pull a specific value out do something like this...

a[0] /. Sol[[1]]

which in this case will give you DD.

Solve will not assign the value DD to a[0], the replacement rules tell you what they're value is in the solution. If mathematica did assign values to a[0], a[1]... etc when you ran solve the second time you run it everything would break because a[0] wouldn't be a free variable it would be DD.

Note: generally best to use lower-case starting names, sol rather than Sol, rec rather than Rec as all Mathematica's own symbols start with Capital letters and eventually you'll hit one and get an error.

$\endgroup$

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