4
$\begingroup$

How would I go about solving the following for c?

Solve[0 == Sum[(t[i]*m[i] - c*t[i]^2)/s[i]^2, {i, 1, n}], c, Reals]

I get the error

Solve::nsmet : This system cannot be solved with the methods available to Solve

but it is fairly straight forward to get that

c = Sum[m[i]*t[i]/s[i]^2, {i, 1, n}] / Sum[t[i]^2/s[i]^2, {i, 1, n}]

I need to repeat this for a similar equation that is not quite so straight forward to do on paper. I intended to use Mathematica to check my result but since I cannot verify the one I am confident in, I may be out of luck. I am new to Mathematica so I would not be surprised if the problem is my ignorance.

Edit: A friend pointed out that N was a defined function in Mathematica (also mentioned in a comment below). I replaced that with n with the same overall outcome.

$\endgroup$
3
  • 1
    $\begingroup$ I think you will fairly consistently find that Mathematica is not particularly helpful with "abstract" things, like sums where you don't give it integer upper and lower bounds or vectors and matricies where you don't give it specific integer dimensions or even functions where you don't actually define what the functions are. $\endgroup$
    – Bill
    Oct 14 '15 at 0:23
  • $\begingroup$ For simple problems such as yours, you might try Summa.m, you need to patch it for use with the latest versions of mma, as shown here mathematica.stackexchange.com/questions/31426/… . Please note, you won't be able to use solve directly, but you might find the simplification and BringOut functions useful. (Usage and help are available on the Mathsource). $\endgroup$
    – Peltio
    Oct 14 '15 at 1:41
  • 1
    $\begingroup$ The fact that the summation limit and the coefficients aren't numeric makes Mathematica give up, especially since you're asking for a solution over the Reals (which can't be done for the generic coefficients). But if I choose a numeric upper limit for the sum, and remove Reals, it works: Table[c/.First@Solve[0==Sum[(t[i]*m[i]-c*t[i]^2)/s[i]^2,{i,1,n}],c],{n,1,4}]. So you can at least check your manual calculations by inserting specific n. And: never use capitals like N as variable names. Type ?N. $\endgroup$
    – Jens
    Oct 14 '15 at 2:38
3
$\begingroup$

If the variable to be solved for appears in the Sum in polynomial form, then the following works.

solvsum[s_, z_] := Module[{coef, in = s[[2]], cf = CoefficientList[s[[1]], z]}, 
    Solve[0 == Sum[coef[i] z^(i - 1), {i, Length[cf]}], z] /. 
    Table[coef[j] -> Sum[cf[[j]], Evaluate[in]], {j, Length[cf]}]]

For the Sum in the question,

s1 = Sum[(t[i]*m[i] - c*t[i]^2)/s[i]^2, {i, 1, n}];
solvsum[s1, c]
(* {{c -> -(Sum[(m[i]*t[i])/s[i]^2, {i, 1, n}]/Sum[-(t[i]^2/s[i]^2), {i, 1, n}])}} *)
$\endgroup$
2
  • 1
    $\begingroup$ This works great for the example case. Unfortunately, the more difficult sums do not strictly have the variable in polynomial form. I am fairly confident there is no analytic solution though. $\endgroup$ Oct 15 '15 at 0:53
  • $\begingroup$ @stvn66 Thanks for accepting the answer. It probably can be generalized to solve with a Sum many expressions that Solve can handle without a Sum. Best wishes. $\endgroup$
    – bbgodfrey
    Oct 15 '15 at 1:32
0
$\begingroup$

If your goal is to check the work you do on paper you may want to go this route :

First define

c[n_Integer] := 
  Sum[m[i]*t[i]/s[i]^2, {i, 1, n}]/Sum[t[i]^2/s[i]^2, {i, 1, n}];

ShouldBeZero[n_Integer] := 
 Sum[(t[i]*m[i] - c[n]*t[i]^2)/s[i]^2, {i, 1, n}] // FullSimplify

then check a few values :

Table[ShouldBeZero[n], {n, 1, 20}]
(* {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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