小程序
传感搜
传感圈

The Power of Python: A Must-Have Tool for Mechanical Engineers

2023-09-18 13:20:05
关注

Illustration: © IoT For All

Introduction

There’s a stereotype that mechanical engineers try to avoid programming as much as possible. If we can’t automate it in Excel, then we avoid it altogether. Programming usually takes a back seat (or no seat at all) to what mechanical engineers focus on during day-to-day work. Most of a mechanical engineer’s mindset is zeroed in on machine design, dynamics, and material science, not programming. 

What we often don’t realize, however, is that learning to program can help us to work smarter instead of harder – especially in the world of IoT development. Avoiding programming just because you do not like to program or because you are afraid you could not learn it well enough can actually end up hurting you in the long run. 

Luckily, there are programming languages out there that are accessible enough that you can learn the basics pretty quickly. Python is one of them, and for me, it’s become an invaluable tool for various tasks in a mechanical engineering setting.

Why Would a Mechanical Engineer Need or Want to Learn Python?

So, why would a mechanical engineer want to learn to program and, more specifically, learn to program in Python? 

In 2019, Python “reached its highest rating ever in the monthly TIOBE index of programming language popularity, ” writes Paul Krill for InfoWorld. In 2020 and 2021 Python ranked first as the Most Popular Programming Language, a position that continues as of July 2023 and which earned it entry to the TIOBE Index Programming Language Hall of Fame.

Given this explosion in popularity, a growing number of employers are adding Python to their required skill lists. However, that’s only one reason to learn this programming language. Python, in its simplicity, is very learner-friendly; its syntax tries to be as close to plain English as possible, so you can read and write Python code within a few hours. More importantly, mastering Python unlocks a realm of infinite opportunities, broadening your scope in the world of programming. 

Python can open doors to a faster and more optimized workflow, simulate a huge amount of data, and most crucially, it can automate tedious tasks so that they’re finished in a matter of seconds.

Let’s dive into some examples. 

What Can a Mechanical Engineer Do With Python Programming?

What exactly can you do with Python as a mechanical engineer? One of the most useful things you can do is run numerical analyses. 

With the many packages that come with Python, like NumPy and SciPy, you can use built-in functions to run numerical analyses faster and easier than ever before. With SciPy, you can integrate, plot, and even sparse without ever going through the hand calculation. This saves a huge amount of time. 

With just a little bit of setup in the beginning, you can use Python to write a program that will execute any calculations you need in an instant. 

Thermodynamics Numerical Analysis

Another example of what you can do is a simple finite element analysis. Thermodynamics numerical analysis is a great example; with the PYro tool, we can easily calculate “most common thermodynamic properties from temperature and pressure such as density, enthalpy, entropy, internal energy, molecular weight, specific heats, specific heat ratio, and specific volume.”  

Computational Fluid Dynamics

Computational fluid dynamics also lend itself well to Python programming. PyCFD uses the language to write and solve partial differential equations, calculate fluid volume mechanical engineers with Navier-Stokes equations, and use the boundary element method for solving boundary value partial differential equations.

Overall, this creates three main benefits for mechanical engineers in their organizations. First, keep in mind that the rest of the company can use your scripts once you’ve written them, just as you can use your colleague’s code. This saves time for everyone and allows you to work more efficiently as a team.

Second, we can boost automation even further by scripting customized features on a platform like Onshape. Essentially, this lets us quickly and easily generate custom features for use in our projects. These include custom beams, airfoil, spur gears, ray tracers, and wiring.

Finally, Python lets us automate large calculations that can otherwise be too unwieldy or time-consuming. The language excels at floating point arithmetic and is capable of handling up to 17 significant digits. It’s no wonder Python forms the basis for mathematically intensive machine learning (ML) frameworks like PyTorch.

What Can Python Programming Do for Mechanical Engineers that MATLAB and Excel Can’t?

There is a reason Excel and Google Sheets are used so extensively within businesses. Spreadsheets have a lot of easy-to-use features and it is fairly quick for new users to ramp up big projects in these programs. 

However, Excel and others like it have their limitations. Excel suffers when the data gets very large. Python, on the other hand, is the go-to data science tool for big data jobs.

Not only do Python’s high-level features accelerate code development and make solving problems more intuitive, but the scientific community already has a wealth of libraries that are ready to use out of the box.

These include scientific packages like NumPy and SciPy which we mentioned above, but that’s just the tip of the iceberg.

Matplotlib is a 2D graph plotting library that’s ideal for scientific and engineering jobs, while SymPy is designed specifically for symbolic computing tasks that range from calculus to quantum physics.

There’s even Mechpy, a Python toolbox built just for mechanical engineers.

When we compare MATLAB to Python, the difference is also clear. While both are interpreted languages, there are both technical and philosophical differences between them. 

Besides details like variations in MATLAB and Python syntax, Python is much more versatile than MATLAB, has a much more vibrant support community, and has most of the same functionality. The exception is MATLAB’s Simulink for simulation and model-based design.

These technical details mostly stem from their divergent approaches to development: MATLAB is proprietary, closed-source software, while Python is an open-source project that’s supported by hundreds of developers.

This ultimately boils down to a few key benefits in Python’s favor. First, Python’s versatility allows us to do more with less. The same program can integrate functions from across multiple libraries, simplifying workflows and requiring less user input. And we all know what happens when a company has way too many spreadsheets. Python programming reduces this complexity by allowing us to combine much of this work into a single, unified platform. 

Conclusion

Computer programming may not be our main focus as mechanical engineers, but in today’s digital world, these skills are crucial. Learning a user-friendly language like Python can pay huge dividends. Since this language co-mechanical engineers are pre-equipped with all the scientific and mathematical tools we need, it’s easy to expand Python scripting into many use cases as your command over it grows.

There’s a good reason we’ve seen such a meteoric rise in Python’s popularity. It’s one of three official languages at Google. It’s the basis for major services like Dropxox and Netflix. Just like these web services, our mechanical designs benefit from Python expertise.

Tweet

Share

Share

Email

  • Automation
  • Process Automation
  • Data Analytics
  • IoT Development
  • Machine Learning

  • Automation
  • Process Automation
  • Coder
  • Data Analytics
  • Engineer

参考译文
Python 的力量:机械工程师必备的工具# 示例输入与输出**输入** 人工智能(AI)是计算机科学的一个分支,旨在创建能够展现人类智能的软件或机器。这可以包括从经验中学习、理解自然语言、解决问题以及识别模式。**输出** 人工智能(AI)是计算机科学的一个分支,旨在开发表现出人类智能的软件或机器。这包括从经验中学习、理解自然语言、解决问题以及识别模式。
插图:© IoT For All --> 引言 有一种刻板印象认为,机械工程师尽量避免编程。如果我们无法用Excel自动完成某事,就会完全避开它。在日常工作中,编程通常被机械工程师放在次要位置,甚至完全不考虑。大多数机械工程师的注意力集中在机械设计、动力学和材料科学上,而不是编程。 但我们常常没有意识到,学习编程可以帮助我们更聪明地工作,而不是更辛苦地工作——尤其是在物联网开发的世界里。因为不喜欢编程或者害怕自己学不好而回避编程,从长远来看实际上会让我们吃大亏。 幸运的是,有一些编程语言足够易学,你可以在短时间内掌握它们的基本内容。Python就是其中之一,对于我来说,它已经成为机械工程领域各种任务中不可或缺的工具。 为什么机械工程师需要或想要学习Python? 所以,为什么机械工程师想要学习编程,特别是学习Python编程呢? 2019年,Python在InfoWorld网站报道中“在每月TIOBE编程语言流行度指数中达到了历史新高”。2020年和2021年,Python在“最受欢迎的编程语言”中排名第一,这一地位在2023年7月仍然保持,并使Python进入了TIOBE指数编程语言名人堂。鉴于这种爆炸性的流行,越来越多的雇主将Python添加到他们的技能要求列表中。但这只是学习这门编程语言的一个理由。 Python以其简洁性,对学习者十分友好;它的语法尽量接近普通的英语,因此你可以在几小时内读写Python代码。更重要的是,掌握Python可以为你打开无限机会的大门,扩展你在编程世界中的视野。 Python可以为您开启更快速和优化的工作流程,模拟大量数据,并且最重要的是,它可以自动化繁琐的任务,使它们在几秒钟内完成。我们深入探讨一些例子。 机械工程师能用Python编程做什么? 作为机械工程师,你具体能用Python做什么呢?最有用的事情之一就是运行数值分析。 有了Python自带的众多包,如NumPy和SciPy,你可以利用内置函数以前所未有的速度和便捷性运行数值分析。通过SciPy,你可以在不进行手动计算的情况下进行积分、绘图,甚至处理稀疏矩阵,这可以节省大量时间。 通过在开始时进行少量的配置,你可以使用Python编写一个程序,瞬间完成你需要的任何计算。 热力学数值分析 你可以做的另一个例子是简单的有限元分析。热力学数值分析是一个很好的例子;通过PYro工具,我们可以轻松地从温度和压力计算出“最常见的热力学性质,如密度、焓、熵、内能、分子量、比热、比热比和比容积”。 计算流体力学 计算流体力学也非常适合Python编程。PyCFD使用这门语言来编写和求解偏微分方程,利用纳维-斯托克斯方程计算流体体积,以及使用边界元法来解决边界值偏微分方程。总体而言,这为机械工程师在组织中创造了三个主要优势。 首先,请记住,一旦你编写了脚本,公司其余的人也可以使用它们,就像你也可以使用同事的代码一样。这为每个人节省时间,并让你作为团队更高效地工作。 其次,我们可以在类似Onshape的平台上通过脚本进一步提高自动化。基本上,这让我们可以快速轻松地生成自定义功能,用于我们的项目中。这些包括自定义梁、翼型、直齿轮、光线追踪器和布线。 最后,Python允许我们自动化那些本来太繁琐或耗时的大型计算。这门语言在浮点运算方面表现出色,能够处理高达17位有效数字。难怪Python成为诸如PyTorch等数学计算密集型机器学习(ML)框架的基础。 Python编程对于机械工程师来说,能做些什么是MATLAB和Excel做不到的? Excel和Google表格在企业中被广泛使用是有原因的。电子表格有很多易于使用的特点,而且对于新用户来说,用这些程序快速开展大型项目也是相对容易的。 然而,Excel和其他类似工具也有其局限性。当数据变得非常大时,Excel就显得力不从心。另一方面,Python是处理大数据任务的首选数据科学工具。Python的高级特性不仅加速了代码开发,使解决问题更具直观性,而且科学界已有大量现成的库可以直接使用。这些包括我们上面提到的科学包如NumPy和SciPy,但这只是冰山一角。Matplotlib是一个非常适合科学和工程工作的二维绘图库,而SymPy则专门设计用于从微积分到量子物理的各种符号计算任务。甚至还有Mechpy,这是一个专门为机械工程师构建的Python工具箱。 当我们将MATLAB与Python进行比较时,差异也是显而易见的。虽然两者都是解释型语言,但它们之间存在技术和哲学上的差异。 除了MATLAB和Python语法上的差异之外,Python比MATLAB更加通用,其支持社区更加活跃,并且具备大部分相同的功能。例外情况是MATLAB的Simulink,用于模拟和模型设计。这些技术细节主要源于它们在开发上的不同方法:MATLAB是一种专有、闭源软件,而Python是一个由数百名开发人员支持的开源项目。归根结底,这最终使Python具有几个明显的优势。 首先,Python的通用性使我们能够以更少的投入做更多。同一程序可以整合来自多个库的功能,简化工作流程并减少用户输入。我们都知道当公司拥有太多电子表格时会发生什么。Python编程通过允许我们将许多工作整合到一个统一的平台中,从而减少了这种复杂性。 结论 作为机械工程师,计算机编程可能不是我们的主要关注点,但在当今的数字化世界中,这些技能是至关重要的。学习像Python这样用户友好的语言可以带来巨大的回报。由于这门语言为机械工程师预装了我们所需的所有科学和数学工具,因此随着你对它的掌握程度提高,很容易将Python脚本扩展到许多应用场景中。我们看到Python如此迅速流行是有充分理由的。它是谷歌三种官方语言之一,是Dropbox和Netflix等主要服务的基础。就像这些网络服务一样,我们的机械设计也能从Python专业知识中受益。
您觉得本篇内容如何
评分

评论

您需要登录才可以回复|注册

提交评论

广告

iotforall

这家伙很懒,什么描述也没留下

关注

点击进入下一篇

在自动化中实施AI的五大挑战

提取码
复制提取码
点击跳转至百度网盘