1
votes

Suppose we want to find summation formula for a sequence. The easiest one would be

x1 = 1; x2 = 2; ... ; xn = n; ...

We all know the sum of the first n items is (n+1)n/2.

My question is how to find the last formula using symbolic calculation with Sympy or matlab or any other software. The difficulty I have is how to deal with n. For example, if each entry in a sequence can be written as a function of n, such as, an = n^2, where n=1, 2, ... Now how do I use symbolic calculation to get a formula for a1+a2+...+an, please? Note I want a formula in terms of a general n without specify a value for n. Is this even possible? If so, how? Thank you!

2

2 Answers

0
votes

The answer depends on the syntax of your symbolic math software. For example: here is the solution using Wolfram alpha: Sum[i, {i, 1, n}] - n is just n - that's why it is called symbolic.

0
votes

As @ChistianFries say, dealing with an arbitrary symbolic variable like your n is what symbolic math is all about.

In Matlab, you should start by reading up on the Symbolic Math toolbox and (optionally) MuPAD, which is a separate environment a bit like Mathematica. Symbolic summation can be accomplished in Matlab via symsum:

syms x n;
symsum(x,1,n)

which returns (n*(n + 1))/2 as expected. I recommend reading the documentation for symsum, and the other symbolic math functions, and trying out the examples provided.