obvious error in differentiation

1 view (last 30 days)
Sherwin
Sherwin on 9 Apr 2022
Commented: Torsten on 10 Apr 2022
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?

Accepted Answer

Torsten
Torsten on 9 Apr 2022
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 Comments
Sherwin
Sherwin on 10 Apr 2022
But you see that they are equal, right?
Torsten
Torsten on 10 Apr 2022
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.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!