Evaluation of an expression with symbols

Dear all, I am new to MATLAB and I was wondering is there a way to expand out an expression that has symbols within it?
Is there a way to simplify the left hand side to get the right hand side polynomial?
Thanks all in advance!

3 Comments

Not automatically, no
syms I J N
A = symsum(symsum(N-piecewise(J<2,0,J-2),J,1,N),I,N-1,N)
This will give you the summation expression, but only partly evaluated.
You need to use a bit of logic to get the desired polynomial
Hi there, thanks for the insight! However when I try to evaluate the above expression, it gives me an error saying:
A = 2*symsum(piecewise(J == 1, N, symtrue, N - J + 2), J, 1, N)
What should I do to get rid of the symsum? Or at least allow the software to evaluate it?
As I said, that will give you the summation expression, but only partly evaluated. That is not an error you are seeing, that is the output of the expression.
You can evaluate for any given number by using subs,
subs(A, N, 17)
At the moment I cannot think of any way to get it to automatically produce the desired output.
I would point out, however, that you can break the inner sum into two ranges: one for j = 1, and one for j = 2 to n. The one for j=1 is the only one for which the max() changes the result, so you can evaluate that one directly using the 0. The other case j=2 to n, the max does not change the value so you can remove it and use (j-2) directly in the formula. You would then have symsum() with respect to i, of (symsum() for j=1 plus symsum() for j=2 to n)

Sign in to comment.

Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Asked:

on 8 Apr 2020

Commented:

on 8 Apr 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!