简体   繁体   English

F#适合物理应用吗?

[英]Is F# suitable for Physics applications?

I hate Physics, but I love software development. 我讨厌物理学,但我喜欢软件开发。 When I go back to school after Thanksgiving, I'll be taking two more quarters of Physics before I'm done with the horrid thing. 当我在感恩节后回到学校时,在我完成可怕的事情之前,我将再接受两个季度的物理学习。 I am currently reading postings on the F# units of measurement feature, but I've never used a language like F#. 我目前正在阅读关于F#测量单位功能的帖子,但我从未使用像F#这样的语言。 Would it be suitable to write applications so I can perhaps learn something about Physics while doing something I like? 是否适合编写应用程序,以便我可以在做自己喜欢的事情的同时学习物理知识?

I'm interested in command-line applications (even those that I can just execute and have spit out an answer without needing inputs) for things like kinematics, planar motion, Newton's Laws, gravitation, work, energy, momentum and impulse, systems of particles, rotational kinematics and dynamics, angular momentum, static equilibrium, oscillatory motion, wave motion, sound, physical optics, electrostatics, Gauss' law, electric field and potential, capacitance, resistance, DC circuits, magnetic field, Ampere's law, and inductance. 对于运动学,平面运动,牛顿定律,引力,工作,能量,动量和冲动等系统,我对命令行应用程序(甚至那些我可以执行并且不需要输入就能吐出答案)感兴趣粒子,旋转运动学和动力学,角动量,静态平衡,振荡运动,波动,声,物理光学,静电学,高斯定律,电场和电势,电容,电阻,直流电路,磁场,安培定律和电感。

The reason I'm interested in F# is because of the units of measure functionality that the language provides. 我对F#感兴趣的原因是因为语言提供的度量单位功能。

In my biased opinion, F# is ideal for physics. 根据我的偏见,F#非常适合物理学。 It has a feature called Units of Measure which does dimensional analysis for you, providing errors if you get it wrong. 它有一个称为度量单位的功能,可以为您进行尺寸分析,如果您弄错了则会提供错误。 For example if you write: 例如,如果你写:

let distance : float<meters> = gravity * 3.0<seconds>

That would yield a compile-error , since gravity is < meters/seconds^2 > and not < meters >. 这会产生编译错误 ,因为重力是<米/秒^ 2>而不是<米>。 This prevents a great deal of physics-related programming errors. 这可以防止大量与物理相关的编程错误。

For more information check out Andrew Kennedy's blog . 有关更多信息,请查看Andrew Kennedy的博客

I rode the introduction of a book call "F# for scientists" (the intro is available for free), and it seems to be a good introduction to the field, since F# seems to be very well adapted to this kind of field. 我推出了一本名为“F#for scientific”的书(这个介绍是免费提供的),这似乎是该领域的一个很好的介绍,因为F#似乎非常适合这种领域。

You might want to have a look at the introduction. 您可能想看看介绍。

http://www.ffconsultancy.com/products/fsharp_for_scientists/ http://www.ffconsultancy.com/products/fsharp_for_scientists/

(And no, I have no relationship with the author ;-) (不,我与作者没有关系;-)

Yes (any language is) and No (learn what your future colleagues will use, like maybe they use python.). 是(任何语言都是)和否(了解未来的同事会使用什么,比如他们使用python。)。 An interesting aside is Fortress . Fortress是一个有趣的地方。

About dimensional analysis : a fun calculus trick once given by one of my physics professors: given that it takes one hour to perfectly cook a one pound turkey in a given oven, how long would it take to cook a 2 pound turkey is the same oven ? 关于尺寸分析:我的一位物理学教授给出了一个有趣的微积分技巧:考虑到在一个给定的烤箱中完美烹饪一磅火鸡需要一个小时,煮一个2磅火鸡需要多长时间就是同一个烤箱?

Well, dimensional analysis shows 嗯,尺寸分析显示

(1) that the total amount of heat energy needed in order to cook the turkey is proportional to the mass of the turkey, which itself is proportional to its volume, which itself is proportional to the cube of it average "radius" (1)为了煮火鸡所需的热能总量与火鸡的质量成正比,火鸡本身与其体积成正比,火鸡本身与其平均“半径”的立方成正比。
ie
Cooking heat energy needed = k1 * (turkeyRadius" ^3) ==> unit : m^3 * k (where k1 unit is J / m^3) 所需的烹饪热能= k1 *(turkeyRadius“^ 3)==>单位:m ^ 3 * k(其中k1单位为J / m ^ 3)

(2) That the total amount of heat energy provided by the oven is proportional to the surface of the turkey multiplied by the amount of time you cook it, (2)烤箱提供的热能总量与火鸡表面的比例乘以你煮的时间,
ie
Heat provided by the oven = k2 * time * (turkeyRadius ^ 2) (where k2 unit is J / s / m^2 ) 烤箱提供的热量= k2 *时间*(turkeyRadius ^ 2)(其中k2单位为J / s / m ^ 2)

Then by using (1) = (2) , you obtain 然后通过使用(1)=(2),您获得
time = k1 / k2 * turkeyRadius ^ (3/2) time = k1 / k2 * turkeyRadius ^(3/2)

ie
- the cooking time is proportionnal to the radius ^ 3/2 - 烹饪时间与半径^ 3/2成比例
- given that turkeyRadius is proportionnal to the cubic root of the mass, we obtain - 鉴于土耳其的Radius与质量的立方根成比例,我们得到了
cooking time = k3 * sqrt(mass) 烹饪时间= k3 * sqrt(质量)

So, it will take sqrt(2) times longer to cook our 2 pounds turkey, and the result is obtained with no calculation at all - only dimensional analysis. 因此,烹饪我们的2磅火鸡需要花费2到2倍的时间,结果是完全没有计算 - 仅进行尺寸分析。

Yes, F# is a great way to build on functional programming, just as Chris Smith said in his response. 是的,就像克里斯史密斯在回答中所说的那样,F#是建立函数式编程的好方法。 I am working on building an extensive discussion about physics, engineering and biology using F#. 我正在使用F#建立关于物理,工程和生物学的广泛讨论。 I could certainly use input from a student like yourself. 我当然可以使用像你这样的学生的输入。 Programming without a real life problem in mind is one way of programming. 没有现实生活问题的编程是一种编程方式。 The other way that is successful is to provide solutions that are only used by people using computers, certainly another way to go and one that builds wealth. 另一种成功的方法是提供仅供使用计算机的人使用的解决方案,这当然是另一种方式,也是建立财富的方式。

F# is made for knowledge domains like Physics. F#适用于物理等知识领域。

Fsharp is one choice. Fsharp是一种选择。 If you want to learn a skill which may also be of more long-term benefit why not learn python. 如果你想学习一种技能,这也可能是更长远的好处,为什么不学习python。 You'll also have numpy and scipy at your fingertips then too. 你也可以在指尖找到numpy和scipy。

Learning any computer language won't teach you physics, and you can learn physics by writing programs in any language. 学习任何计算机语言都不会教你物理学,你可以用任何语言编写程序来学习物理。

Dimensional analysis is a rather handy tool for physics problems, it can steer you away from being "not even wrong". 尺寸分析是物理问题的一个相当方便的工具,它可以引导你远离“甚至不错”。

I've always gained a certain perverse pleasure in getting an answer wrong by factors of 10^34 because I'd got my units wrong somewhere ;-) 我总是因为10 ^ 34的因素而得到一个错误的答案而获得某种不正常的乐趣,因为我的某些地方的单位出错;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM