Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

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

Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
John D'Errico

Posts: 9,126
Registered: 12/7/04
Re: perform arithmetic on symbolic expression
Posted: Jul 22, 2014 6:00 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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


Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2016. All Rights Reserved.