How do you isolate a nonatomic term from a symbolic expression?

1 view (last 30 days)
I want to is to find the coefficient of some nonatomic term in an expression.
E.g. for the expression:
>> syms x y z
>> expr = z * exp(x + y) + 2 / z * exp(2 * x + y)
Iwant to read the coefficient of "exp(2 * x + y)". How can this be accomplished?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 5 May 2022
Development is investigating ways of streamlining this workflow. However, this may currently be accomplished via:
>> syms t
>> texpr = expand(simplify(subs(expr, x, (log(t) - y) / 2)))
>> dtexpr = diff(texpr, t)
>> cdtexpr = children(dtexpr)
>> cof = 0
>> for i = 1:length(cdtexpr)
>>   if ~has(cdtexpr{i},t)
>>     cof = cof + cdtexpr{i};
>>   end
>> end
>> cof
That is:
1) Define a new variable "t" and solve the expression that should be isolated in terms of one of the dependent variables.
2) Solve "t == exp(2 * x + y)" for "x". Substitute this new term into the expression, simplifying and expanding to bring the expression into a standard form.
3) To find only the linear term of the relevant expression, you can take the derivative "diff" and then if any given term in the expression still has any dependence on "t", eliminate it from the final expression.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!