Evaluation of an expression with symbols

2 views (last 30 days)
Ben Tay
Ben Tay on 8 Apr 2020
Commented: Walter Roberson on 8 Apr 2020
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
Ben Tay
Ben Tay on 8 Apr 2020
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?
Walter Roberson
Walter Roberson on 8 Apr 2020
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)

Products

Community Treasure Hunt

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

Start Hunting!