obvious error in differentiation

2 次查看(过去 30 天)
Hi, I have a function as
Z = (T-Tp)*lambdam*u + ((p*(h^2)*gammaw)/k2) + ((p^2)*(h^2)*l*alpha*r*gammac)/(D*u*C) + (ro*p*(l^2)*u*gammae)/D;
obviously, this function is composed of four terms. I want to divide Z by h (which is a positive, non-zero variable) and then take the derivative of Z with respect to h and put it equal to 0 and get h. so I write the below code:
dh = diff(Z/h,h);
h1 = solve (dh==0,h);
Now I get
h1 = (u*(C*k2*p*(C*D*gammaw*u + alpha*gammac*k2*l*p*r)*(gammae*p*ro*l^2 + T*lambdam*D - Tp*lambdam*D))^(1/2))/(alpha*gammac*k2*l*r*p^2 + C*gammaw*u*D*p)
but if I divide Z by h manually and enter that from the beginning, and then take the derivative, I'll get
h1 = u*((C*k2*(gammae*p*ro*l^2 + T*lambdam*D - Tp*lambdam*D))/(p*(C*D*gammaw*u + alpha*gammac*k2*l*p*r)))^(1/2)
which is consistent with what I get when I do everything manually. Why this happens? what am I missing?

采纳的回答

Torsten
Torsten 2022-4-9
Did you try
pretty(h1)
and/or
isequal(h1,h2)
( I named the second term h2 ) ?
I think they are equal - at least in h1 you can divide
(C*D*gammaw*u + alpha*gammac*k2*l*p*r)
by
(alpha*gammac*k2*l*r*p^2 + C*gammaw*u*D*p)
to get rid of the quotient .
  9 个评论
Sherwin
Sherwin 2022-4-10
But you see that they are equal, right?
Torsten
Torsten 2022-4-10
Under certain assumptions.
When I "show" that h1 = h2, I use e.g. (a*b)^(1/2) = a^(1/2)*b^(1/2). This only holds if a,b are real (not complex) numbers and non-negative.
I suspect that if such assumptions are necessary, MATLAB does not classify two expressions as equal.
But that's a question for the programmers of the symbolic toolbox - I cannot answer it.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by