需要帮助将径向距离放入 lisp 程序的逆波兰概念中
极坐标的距离公式如下所示: http://math.ucsd.edu/~wgarner/math4c/derivations /distance/distancepolar.htm
我尝试这样做:
(defun distant-formula (r1 r2 t1 t2)
(setq d ( sqrt (*(-(+ (expt r1 2)(expt r2 2))(* 2 r1 r2))
(cos(- t1 t2))))))
但是减法和乘法之间的额外括号改变了公式,但是我不太确定如何在不正确的情况下做到这一点,任何帮助都是赞赏。
The distance formula for polar coordinated is shown here:
http://math.ucsd.edu/~wgarner/math4c/derivations/distance/distancepolar.htm
I've tried doing it this way:
(defun distant-formula (r1 r2 t1 t2)
(setq d ( sqrt (*(-(+ (expt r1 2)(expt r2 2))(* 2 r1 r2))
(cos(- t1 t2))))))
but the extra parenthesis between the subtraction and multiplication changes the formula, however I'm not quite sure how to do it without correctly, any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您代码中的变量 D 没有用。您不应该给未定义的变量赋值。 Lisp 还返回计算的值。这使得这样的任务特别无用。
您可以这样编写公式:
请注意,三行代码的布局比仅使用一行更容易理解公式。使用编辑器的自动缩进来帮助布局。
The variable D in your code is of no use. You should not assign values to undefined variables. Lisp also returns the value of the computation. That makes such an assignment especially useless.
You can write the formula like this:
Note that the layout of the code over three lines makes it easier to understand the formula, than using just one line. Use the automatic indentation of the editor to help with the layout.
查看原始公式:
您想要从外到内进行操作:
您需要注意运算符的优先级。进行转换的一种方法是转换为中缀表示法中的所有隐式括号(因此
a * b + c
转到((a * b) + c)
)然后重新排列,使操作员位于前面。Looking at the original formula:
You want to work from the outside to the inside:
You need to be careful about the precedence of the operators. One way to do the conversion is to all all of the implicit parentheses in infix notation (so
a * b + c
goes to((a * b) + c)
) and then rearrange so the operators are at the front.