Mathematica,用代入简化方程

Mathematica, simplify equation with subsitutions

有如下公式:

s = R*(lat - lat0)
rho = R/Tan[lat]
f = (x^2 + (rho + s - y)^2 - rho^2)*(Sin[lat])^2

及其导数

fd = D[f, lat]

哪里

Output[1] = 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

我想用 s, rho 的替换来表达 fd

FullSimplify[fd, TransformationFunctions -> {Automatic, # /. R (lat - lat0) -> s &, # /. R/Tan[lat] -> rho &}]

但是,只出现没有任何代入的简化公式:

Output[2] = 2 Cos[lat] ((1 + (lat - lat0)^2) R^2 + x^2 + 2 (-lat + lat0) R y +   y^2 + R (lat R - lat0 R - y) Cot[lat]) Sin[lat]

感谢您的帮助。

尝试替换并确认结果不变

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])

现在为什么 R/Tan[lat] 替换在原始 fd 中不起作用?

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] 很多年前,有一个人写了一个包 "mathematical substitutions" 而不是 Mathematica "literal substitutions",但那已经过时了日期,我还不够了解当前版本。

让我们尝试 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 并且通常会尝试用 rho 替换 R Cot[lat]。而且,在这个特定的示例中,它甚至可以与

一起使用
Simplify[fd, R/Tan[lat] == rho]

但不能保证这会一直有效或会做你想做的事,在某些情况下这会做更奇怪和离奇的事情。

也许这给了你足够的提示,你可以取得一些进展。