Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: perform arithmetic on symbolic expression
Replies: 2   Last Post: Jul 23, 2014 10:28 AM

 Messages: [ Previous | Next ]
 John D'Errico Posts: 9,130 Registered: 12/7/04
Re: perform arithmetic on symbolic expression
Posted: Jul 22, 2014 6:00 PM

"kumar vishwajeet" wrote in message <lqmbjj\$sfh\$1@newscl01ah.mathworks.com>...
> I have the following expression,
>
> J = l1*x + l2^2*y^2/(l1*x + l2*y) - 1/2*x*y/(l1^2*x^2 + 2*l1*l2*x*y + l2^2*y^2 + l3^2*x^2 + l3^2*y^2)^(3/2)*(8*E*l1^6*x^6 + 8*E*l2^6*y^6 - 4*l1^4*l3^4*x^4 - 4*l1^6*l3^2*x^4 - 4*l2^2*l3^6*x^4 - 4*l2^2*l3^6*y^4 - 8*l2^4*l3^4*y^4 - 4*l2^6*l3^2*y^4 + 8*E*l1^2*l3^4*x^6 + 16*E*l1^4*l3^2*x^6 + 8*E*l2^2*l3^4*y^6)
>
> The original expression is much longer than that. But just to keep it clean, I've made it shorter. Here, l1, l2, l3, x, y are symbolic variables. I have 400 different values for x and y which I want to replace in the expression. Thus I'll have 400 different values of J corresponding to values of x and y. I want to add all these 400 values together to get one final expression. But the MATLAB is not able to perform addition. I mean to say that it does not collect like terms. For e.g. 2*l1^2 + 3*l1*l2 + 3*l1^2 is equal to 5*l1^2 + 3*l1*l2. MATLAB would give me 2*l1^2 + 3*l1*l2 + 3*l1^2 as the answer.
> Is there a way to perform such addition.

Really? I guess if you say it is impossible, you must be right. Not.

syms l1 l2
2*l1^2 + 3*l1*l2 + 3*l1^2
ans =
5*l1^2 + 3*l2*l1

John

Date Subject Author
7/22/14 kumar vishwajeet
7/22/14 John D'Errico
7/23/14 Steven Lord