obvious error in differentiation
조회 수: 1 (최근 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?
댓글 수: 0
채택된 답변
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
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 Exchange에서 Assumptions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!