任何人都可以解释为什么在 MATLAB 中对余切 (cot
) 函数求导会产生与 Wolframalpha 不同的结果吗?
这是我在 MATLAB 中的代码(带有注释的结果):
syms v d z
F = v + d*(cot(z));
R_v = diff(F,v) % = 1
R_z = diff(F,z) % = -d*(cot(z)^2 + 1)
R_d = diff(F,d) % = cot(z)
这是 Wolframalpha 的结果:
虽然第一个和最后一个结果非常好,但第二个结果我不明白。据我所知,余切导数为:
谁能解答我的困惑?
我使用的是 MATLAB R2017a。
最佳答案
MATLAB 和理论解决方案是等效的。
Matlab 为您提供:
d/dz( cot(z) ) = -( cot(z)^2 + 1 )
让我们从那里开始工作...
= -( 1/tan(z)^2 + 1 ) % By definition cot(z)=1/tan(z)
= -( cos(z)^2 / sin(z)^2 + 1 ) % Using tan(z) = sin(z)/cos(z)
= -( (1 - sin(z)^2) / sin(z)^2 + 1 ) % Using cos(z)^2 + sin(z)^2 = 1
= -( 1/sin(z)^2 - sin(z)^2/sin(z)^2 + 1 ) % Expanding the fraction
= -( 1/sin(z)^2 - 1 + 1 ) % Simplifying
= -1/sin(z)^2 % Expected result!
因此,正如您在最后所述,MATLAB 结果与理论预期完全一致。 d
在偏导数中被视为常数,因此仍为系数。
如果您不喜欢手动计算,您可以让 MATLAB 为您检查等价性...
simplify( R_z - (-d/sin(z)^2) ) % = 0, so they are the same.
您可以通过使用rewrite
和simplify
从MATLAB获得预期的形式。
% rewrite the result R_z in terms in the SIN function
simplify(rewrite( R_z, 'sin' ) )
% >> ans = -d/sin(z)^2
但是请注意,这并没有明确定义。来自 simplify
docs
Simplification of mathematical expression is not a clearly defined subject. There is no universal idea as to which form of an expression is simplest.
您最好使用上面所示的 simplify(...) = 0
方法,然后根据需要将所需结果打印到屏幕上。如果您不输出结果字符串,则表达式的形式无关紧要,您可以继续前进!
对于wolframalpha,我 cannot reproduce你的问题...
但是,您可以再次注意到,您显示的第一个结果是等效的:
% Your result from wolfram alpha
syms x
diff(cot(x), x)
% = - cot(x)^2 - 1
% = - ( cot(x)^2 + 1 )
% This is the same as the MATLAB result, same reasoning follows
关于matlab - 在 MATLAB 中求余切导数时出现意外结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48212788/