obvious error in differentiation

1 回表示 (過去 30 日間)
Sherwin
Sherwin 2022 年 4 月 9 日
コメント済み: Torsten 2022 年 4 月 10 日
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 Center および File ExchangeAssumptions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by