how to sum values of an array that are symbolic varibles in matlab

If you have an array of symbolic variables in MATLAB and you want to find their sum, you can use the symsum function. Here's an example:

main.m
syms x y z
A = [x, y, z];
s = symsum(A);
41 chars
4 lines

In this example, we first define three symbolic variables x, y, and z, and then create an array A that contains those variables. We then use the symsum function to sum up the values in A, which gives us the symbolic expression x + y + z.

Note that symsum can also take additional arguments to specify the range of the sum, for example:

main.m
symsum(A, k, 1, n)
19 chars
2 lines

will sum up the values in A from k=1 to k=n.

gistlibby LogSnag