调整mathematica中的操作输出
我需要帮助。我在 Graphics[]
命令中使用了许多变量,这些变量依赖于一个变量(在我的示例中为 H)。我想操纵我的图形,以便通过改变 H 图形的值来相应地改变。但这并不像我想象的那么容易。
如果您对如何完成此任务有任何想法,我将不胜感激。
(*This variables are dependent on H that I want to change in
manipulate*)
R = 10;
\[Alpha] = ArcSin[H/R];
p = H/Tan[\[Alpha]];
n = 1.5;
\[Beta] = ArcSin[n Sin[\[Alpha]]];
\[Theta] = \[Beta] - \[Alpha];
l = H/Tan[\[Theta]];
(*This is the graphic I want to make manipulated*)
Graphics[{(*Incident ray*)Line[{{-2, H}, {p, H}}],(*Prism*)
Circle[{0, 0}, R, {0, Pi/2}],
Line[{{0, 0}, {0, 10}}],(*Refracted ray*)
Line[{{p, H}, {p + l, 0}}],(*Surface*)
Line[{{0, 0}, {p + l + 10, 0}}]}]
这是我的解决方案之一,但它真的很混乱。我所做的只是手动插入这些值。是否有更合适的方法来完成此操作:
R = 10;
n = 1.5;
Manipulate[
Graphics[{(*Incident ray*)
Line[{{-2, H}, {H/Tan[ArcSin[H/10]], H}}],(*Prism*)
Circle[{0, 0}, R, {0, Pi/2}],
Line[{{0, 0}, {0, 10}}],(*Refracted ray*)
Line[{{H/Tan[ArcSin[H/10]],
H}, {H/Tan[ArcSin[H/10]] +
H/Tan[ArcSin[n Sin[ArcSin[H/10]]] - ArcSin[H/10]],
0}}],(*Surface*)
Line[{{0,
0}, {H/Tan[ArcSin[H/10]] +
H/Tan[ArcSin[n Sin[ArcSin[H/10]]] - ArcSin[H/10]] + 10,
0}}]}], {H, 0.0001, 10, Appearance -> "Labeled"}]
以及如何使我的图形不不断更改其大小。我希望棱镜具有固定的尺寸,并且入射光线可以改变其位置(在上面的示例/此解决方案中,当 H 大于 6.66 时就会发生这种情况)。
这个问题可能令人困惑,但如果你在 Mathematica 中尝试一下,你就会明白我想要的。感谢您的任何建议。
I need help. I have many variables, that I use in my Graphics[]
command, that are dependent of one variable (H in my example). I want to manipulate my graphic so that by changing value of H graphic changes accordingly. But it is not as easy as I've thought.
If you have any idea on how to acomplish this, I would be grateful.
(*This variables are dependent on H that I want to change in
manipulate*)
R = 10;
\[Alpha] = ArcSin[H/R];
p = H/Tan[\[Alpha]];
n = 1.5;
\[Beta] = ArcSin[n Sin[\[Alpha]]];
\[Theta] = \[Beta] - \[Alpha];
l = H/Tan[\[Theta]];
(*This is the graphic I want to make manipulated*)
Graphics[{(*Incident ray*)Line[{{-2, H}, {p, H}}],(*Prism*)
Circle[{0, 0}, R, {0, Pi/2}],
Line[{{0, 0}, {0, 10}}],(*Refracted ray*)
Line[{{p, H}, {p + l, 0}}],(*Surface*)
Line[{{0, 0}, {p + l + 10, 0}}]}]
Here's one of my solutions but it's really messy. What I did is just manually pluged in those values. Is there any more appropriate way to acomplish this:
R = 10;
n = 1.5;
Manipulate[
Graphics[{(*Incident ray*)
Line[{{-2, H}, {H/Tan[ArcSin[H/10]], H}}],(*Prism*)
Circle[{0, 0}, R, {0, Pi/2}],
Line[{{0, 0}, {0, 10}}],(*Refracted ray*)
Line[{{H/Tan[ArcSin[H/10]],
H}, {H/Tan[ArcSin[H/10]] +
H/Tan[ArcSin[n Sin[ArcSin[H/10]]] - ArcSin[H/10]],
0}}],(*Surface*)
Line[{{0,
0}, {H/Tan[ArcSin[H/10]] +
H/Tan[ArcSin[n Sin[ArcSin[H/10]]] - ArcSin[H/10]] + 10,
0}}]}], {H, 0.0001, 10, Appearance -> "Labeled"}]
And also how to make my graphic not to change it's size constantly. I want prism to have fixed size and incident ray to change its position (as it happens when H gets > 6.66 in my example above / this solution).
The question is maybe confusing, but if you try it in Mathematica, you'll see what I want. Thank you for any suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你的解决方案总的来说还不错,马克已经在他的回复中注意到了。我也喜欢马克解决方案的简单性。只是为了实验,我也分享我的想法。
1) 为特定的 Manipulate 本地化变量总是一件好事,这样它们的值就不会泄漏并干扰其他动态内容。如果你的笔记本中有额外的计算,这很重要 - 它们可能会开始相互重置。
2)在这种特殊情况下,如果您尝试读取将表达式相互插入的额外变量,您的方程就会变得复杂,并且很难看出为什么它们有时会失败。借助函数 TrigExpand 和 FullSimplify 的一些代数知识可能有助于阐明变量 H 具有取决于折射率值 n 的限制(见下文)。
3)如果我们知道第(2)点,我们也可以使变量 n 动态化,并在控件定义中将值 H 链接到 n (重置 H 的上限),因此它始终应该是 H<10/n 。 If[..] 也是必要的,这样控件就不会“粉红色”。
4) 如果您的公式取决于 R,我们也可以使 R 动态化。但我没有这些信息,所以我通过“虚拟”控件的概念(ControlType -> None)对 R 进行了本地化——这对于 Manipulate 来说是非常有用的概念。
5) 使用 PlotRange 和 ImageSize 停止图形的抖动
6) 使其美观;-)
如果您想向 Wolfram 演示项目提交演示,那么这些点就很重要。如果你只是玩玩——我认为你和马克的解决方案非常好。
谢谢,
维塔利
I think your solution is not bad in general, Mark already noticed in his reply. I loved simplicity of Mark's solution too. Just for the sake of experiment I share my ideas too.
1) It is always a good thing to localize your variables for a specific Manipulate, so their values do not leak and interfere with other dynamic content. It matters if you have additional computation in your notebook - they may start resetting each other.
2) In this particular case if you try to get read of extra variables plugging expressions one into each other your equations became complicated and it is hard to see why they would fail some times. A bit of algebra with help of functions TrigExpand and FullSimplify may help to clarify that your variable H has limitations depending on refraction index value n (see below).
3) If we are aware of point (2) we can make variable n dynamic too and link the value H to n (resetting upper bound of H) right in the controls definition, so always it should be H<10/n . If[..] is also necessary so the controls will not “pink”.
4) If your formulas would depend on R we could also make R dynamic. But I do not have this information, so I localized R via concept of a “dummy“ control (ControlType -> None) – which is quite useful concept for Manipulate.
5) Use PlotRange and ImageSize to stop jiggling of graphics
6) Make it beautiful ;-)
These points would be important if you’d like, for example, to submit a Demonstration to the Wolfram Demonstration Project. If you are just playing around – I think yours and Mark’s solutions are very good.
Thanks,
Vitaliy
我认为您的第一批代码看起来不错,并且很容易放入
Manipulate
中。我建议使用Graphics
中的PlotRange
选项。I think your first batch of code looks fine and is easy to place into a
Manipulate
. I would recommend use of thePlotRange
option inGraphics
.