Mathematica 中的对数滑块控制
我正在制作一个小接口,用于在 Mathematica 中计算分压器。我有两个滑块(z1 和 z2)表示电阻值,还有几个滑块将 Vin 表示为正弦曲线。
问题是可用电阻值的范围(在现实世界中)大致是 {r, 100, 1,000,000}
上的对数。但是,如果我将滑块范围设置为 r
,则选择大约 100% 左右的常见低电阻值是不切实际的。 {100, 10,000}
。
是否可以创建一个扫过对数范围的滑块? <代码>
Manipulate[
Grid[{{Plot[(VinRCos[t] + VinC), {t, -3, 9},
PlotRange -> {-1, VMax}, AxesLabel -> {t, Vin}]}, {Plot[
z2/(z1 + z2)(VinR*Cos[t] + VinC), {t, -3, 9},
PlotRange -> {-1, VMax}, AxesLabel -> {t, Vout}]}},
ItemSize -> 20],
{{z1, 10000}, 10, 1000000, 10}, {z1}, {{z2, 10000}, 10,
1000000}, {z2}, Delimiter, {{VinR, 2.5}, 0,
5}, {VinR}, {{VinC, 2}, -VMax, VMax}, {VinC}]
I'm making a small interface for calculating voltage dividers in Mathematica. I have two sliders (z1 & z2) that represent the resistor values and a couple of sliders to represent Vin as a sinusoid.
The issue is that the range of available resistor values (in the real world) is roughly logarithmic on {r, 100, 1,000,000}
. If I set my slider range to r
, however, it's impractical to select common low resistor values in approx. {100, 10,000}
.
Is it possible to create a slider that sweeps through a logarithmic range?
Manipulate[ Grid[{{Plot[(VinRCos[t] + VinC), {t, -3, 9}, PlotRange -> {-1, VMax}, AxesLabel -> {t, Vin}]}, {Plot[ z2/(z1 + z2)(VinR*Cos[t] + VinC), {t, -3, 9}, PlotRange -> {-1, VMax}, AxesLabel -> {t, Vout}]}}, ItemSize -> 20], {{z1, 10000}, 10, 1000000, 10}, {z1}, {{z2, 10000}, 10, 1000000}, {z2}, Delimiter, {{VinR, 2.5}, 0, 5}, {VinR}, {{VinC, 2}, -VMax, VMax}, {VinC}]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
迈克尔的答案可能是最好的,即让用户指定指数。另一种解决方案是创建一个 LogSlider 类型命令。这是一个简单的示例:
该函数仅具有
Slider
灵活性的子集,如果您想要自定义步长等,则必须对其进行扩展...然后修改您的
Manipulate
> 通过使用指定变量{{z1, 10000}, 10, 1000000, LogSlider[##]&}
等...Michael's answer is probably the best, i.e. just get the user to specify the exponent. An alternate solution is to make a
LogSlider
type command. Here's a simple example:The function only has a subset of the flexibility of
Slider
and will have to be extended if you want custom step sizes etc...You then modify your
Manipulate
by specifying the variables using{{z1, 10000}, 10, 1000000, LogSlider[##]&}
etc...一个简单的解决方法是让滑块操纵指数,然后在需要实际值的地方插入例如
10^z1
:在您的特定情况下,您当然也可以输入标准电阻器列表可供选择的值:
HTH!
A simple fix is to just make the slider manipulate the exponent, and plug in e.g.
10^z1
where you need the actual value:In your particular case, you could of course also input a list of standard resistor values to pick from:
HTH!
这是我的最终结果:
<代码>
Here is my final result:
这是 LogSlider 的开始,它产生其他控件所具有的标准双向行为。
Here is a start to LogSlider that produces the standard two-way behavior the other controls have.