Why does Matlab not simplify this further?

2 views (last 30 days)
Fabian
Fabian on 12 Feb 2024
Answered: Star Strider on 12 Feb 2024
I want Matlab to simplify the first partial derivative of the following function:
With the arguments of the function repressed, the first partial derivative with respect to is
Matlab gives me the correct derivative but then does not simplify it further:
clear, clearvars
syms x1 x2 p1 p2 l C rho
syms f(p1,p2)
f(p1,p2) = (l.^(1/(1-rho)) *(p1).^(rho/(rho-1))+(1-l).^(1/(1-rho))*(p2).^(rho/(rho-1))).^((rho-1)/rho)
f(p1, p2) = 
C = f(p1,p2)
C = 
x2 = (diff(f,p2))
x2(p1, p2) = 
simplify(x2,'Steps',10)
ans(p1, p2) = 
I tried to define C=f(p1,p2) but it doesn't help. Any ideas what I can do here?

Answers (1)

Star Strider
Star Strider on 12 Feb 2024
Increase the ‘Steps’ value. It will then continue simplifying until it cannot simplify further, or reaches the maximum ‘Steps’ iteration limit. I use 500 here (as I do usually), however it can be either more or less than that, depending on the result you want. (In this instance, increasing it does not change the result.)
Try this —
clear, clearvars
syms x1 x2 p1 p2 l C rho
syms f(p1,p2)
f(p1,p2) = (l.^(1/(1-rho)) *(p1).^(rho/(rho-1))+(1-l).^(1/(1-rho))*(p2).^(rho/(rho-1))).^((rho-1)/rho)
f(p1, p2) = 
C = f(p1,p2)
C = 
x2 = (diff(f,p2))
x2(p1, p2) = 
simplify(x2,'Steps',500)
ans(p1, p2) = 
.

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!