*How do I* Simplify by substituting user defined variables for several repetitive expressions in a symbolic Matlab result (answer)
Show older comments
I have a very long result. It is the result of symbolically differentiating a somewhat complicated expression. The result is probably 2000 characters long. There are many repetitive expressions that arise in the result. Not only will it make it look nicer to substitute many of the expressions for simpler ones, but it is actually also necessary in order to proceed with coding.
I have two specific examples that I am concerned with.
First, I have many repetitive expressions such as "1/(ti-tj)+1/(ti-tk)" which arise a lot inside what I will call sub-expressions, and I would prefer to change all instances of this to 2(1-Eta)/S2. Another would be that I want to convert all 2*(1-Eta)*(ti-tj)*(ti-tk) to a simple "S1".
Second, in differentiating there are now terms such as D(L)(ti) which mean the derivative of L with respect to ti. I would like Matlab to replace all of these with "L1". If it does this, there will then be many cancellation with other expressions already using L1(L1 is a symbolic variable used by me and appears many times in the initial equation and result), and this will greatly simplify the result. If it can't do this I need to go through and manually change them, which gets very tedious with results that are 4+ pages long.
Thanks in advance for any replies to my query,
Braden
Accepted Answer
More Answers (0)
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!