在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:MasonProtter/Symbolics.jl开源软件地址:https://github.com/MasonProtter/Symbolics.jl开源编程语言:Julia 100.0%开源软件介绍:Symbolics.jlThis is a package I'm throwing together after getting inspired by the talk Physics in Clojure which was about porting scmutils to clojure. scmutils is a Scheme package with a very interesting and powerful computer algebra system meant as a companion to the book Structure and Interpretation of Classical Mechanics. My intention with Symbolics.jl is to attempt to recreate the functionality of scmutils in julia using julian syntax. The package is slowly morphing into some sort of hybrid between scmutils and Mathematica. This package works on Julia 1.0. To add it, simply
Note: This package is very much a work in progress! Don't rely on it for anything important. Examples of use:
julia > using Symbolics
julia> @sym x y z t;
julia> x^2 + x^2
2 * x ^ 2
julia> ex = 2x + x^2
2x + x^2
julia> ex(x => y)
2y + y^2
julia> f(x) = x^3;
julia> g(x) = x^2;
julia> f + g
(::#70) (generic function with 1 method)
julia> ans(x)
x ^ 3 + x ^ 2
julia> f * g
(::#72) (generic function with 1 method)
julia> ans(x)
x ^ 5
julia> D(f+g)(x)
3 * x ^ 2 + 2x
julia> (D^2)(f+g)(x)
3 * (2x) + 2
julia> (D^3)(f+g)(x)
6 The derivative operator,
julia> D(x(t)^2 + 2x(t), t)
2 * (x)(t) * (D(x))(t) + 2 * (D(x))(t) New: Generate the Euler Lagrange Equations from a LagrangianWe can now define a Lagrangian, say that of a simple harmonic oscillator as using Symbolics
@sym x m ω t
function L(local_tuple::UpTuple)
t, q, qdot = local_tuple.data
(0.5m)*qdot^2 - (0.5m*ω^2)*q^2
end where the local_tuple is an object describing a time, posisition and velocity (ie. all the relevant phase space data). According to SICM, this data should be provided by a function Γ(w) = t -> UpTuple([t, w(t), D(w)(t)]) Hence, as shown in SICM, the Euler-Lagrange condition for stationary action may be written as the functional Lagrange_Equations(L) = w -> D(∂(3)(L)∘Γ(w)) - ∂(2)(L)∘Γ(w) where julia> Lagrange_Equations(L)(x)(t)
(D(D(x)))(t) * m + (x)(t) * m * ω ^ 2 which when set equal to zero is the equation of motion for a simple harmonic oscillator, generated in pure Julia code code symbolically! |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论