尝试替换,确认结果不变
s = R*(lat - lat0);
rho = R/Tan[lat];
f = (x^2 + (rho + s - y)^2 - rho^2)*(Sin[lat])^2;
fd = D[f, lat];
FullSimplify[fd, TransformationFunctions->{Automatic,
#/.R(lat-lat0)->s&, #/.R/Tan[lat]->rho &}];
Simplify[% == fd]
输出是True
请注意,您之前定义了 s=R*(lat-lat0),因此您似乎将 R(lat-lat0) 替换为 R(lat-lat0)
在替换之前尝试取消定义s
s =.;
FullSimplify[fd, TransformationFunctions -> {Automatic,
#/.R(lat-lat0)->s&, #/.R/Tan[lat]->rho&}]
结果是2 Cos[lat](R(s-y)Cos[lat]+(R^2+x^2+(s-y)^2)Sin[lat])
现在为什么原来的fd 中的R/Tan[lat] 替换不起作用?
D[f, lat]==2 Cos[lat](x^2-R^2 Cot[lat]^2+((lat-lat0)R-y+R Cot[lat])^2) Sin[lat]+(2 R^2 Cot[lat]Csc[lat]^2+2((lat-lat0)R-y+R Cot[lat])(R-R Csc[lat]^2)) Sin[lat]^2
请注意,其中没有R/Tan[lat]。 Mathematica 模式匹配非常字面,无法理解 R/Tan[lat]==R Cot[lat] 很多年前,有一个人写了一个包,它做了“数学替换”而不是 Mathematica 的“字面替换”,但那已经过时了,我对当前版本的了解不够。
让我们尝试使用 R Cot[lat] 替换并取消定义 rho,这样它就不会撤消任何替换。
s =.; rho =.
fd /. {R Cot[lat] -> rho}
结果是2 Cos[lat](x^2+((lat-lat0)R+rho-y)^2-R^2 Cot[lat]^2) Sin[lat]+(2 R^2 Cot[lat]Csc[lat]^2+2 ((lat-lat0)R+rho-y)(R-R Csc[lat]^2))Sin[lat]^2
请注意R^2 Cot[lat]^2 仍然存在,并且文字替换不知道您可能期望R Cot[lat]->rho 将其更改为rho^2,因此添加该规则
s=.; rho=.
fd /. {R Cot[lat] -> rho, R^2 Cot[lat]^2 -> rho^2}
请注意 R^2 Cot[lat] 仍然存在,您可能打算将其替换为 R rho,因此添加该规则。
s =.; rho =.
fd /. {R Cot[lat]->rho, R^2 Cot[lat]^2->rho^2, R^2 Cot[lat]->R rho}
您是否开始意识到 Mathematica 中的模式替换会变成一条黑暗而曲折的走廊,通向标有“Frustration”的门。
您可能会使用一种技巧。
Simplify[fd, R Cot[lat] == rho]
这将尝试简化fd,并且通常会尝试将R Cot[lat] 替换为rho。而且,在这个特定的例子中,它甚至可以使用
Simplify[fd, R/Tan[lat] == rho]
但不能保证这将永远有效或会做你想做的事,在某些情况下,这会做更奇怪和离奇的事情。
也许这给了你足够的提示,你可以取得一些进展。