Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing behavior while defining list of equations for a multi vaiable system #255

Closed
soumyasrtk opened this issue Sep 29, 2024 · 1 comment · Fixed by #258
Closed

Confusing behavior while defining list of equations for a multi vaiable system #255

soumyasrtk opened this issue Sep 29, 2024 · 1 comment · Fixed by #258
Labels
bug Something isn't working

Comments

@soumyasrtk
Copy link

For a set of equations,

# define equation of motion
@variables ω1, ω2, t, ω, F, γ, α1, α2, k, x(t), y(t);
eqs = [ d(x, t, 2) + ω1^2 * x + γ*d(x,t) + α1*x^3 - k*y, 
                    d(d(y,t),t) + ω2^2*y + γ*d(y,t) + α2*y^3 - k*x]

diff_eq = DifferentialEquation(eqs~[F*cos*t), 0], [x, y])
System of 1 differential equations
Variables:       x(t)
Harmonic ansatz: x(t) => ;   

Symbolics.Num[Differential(t)(Differential(t)(x(t))) - k*y(t) + Differential(t)(x(t))*γ + x(t)*(ω1^2) + (x(t)^3)*α1, Differential(t)(Differential(t)(y(t))) - k*x(t) + Differential(t)(y(t))*γ + y(t)*(ω2^2) + (y(t)^3)*α2] ~ Symbolics.Num[F*cos(t*ω), 0]

gives a different result than

# define equation of motion
@variables ω1, ω2, t, ω, F, γ, α1, α2, k, x(t), y(t);
eqs = [ d(x, t, 2) + ω1^2 * x + γ*d(x,t) + α1*x^3 - k*y, 
                    d(d(y,t),t) + ω2^2*y + γ*d(y,t) + α2*y^3 - k*x]-[F*cos*t), 0]

diff_eq = DifferentialEquation(eqs, [x, y])
System of 2 differential equations
Variables:       x(t), y(t)
Harmonic ansatz: x(t) => ;   y(t) => ;   

Differential(t)(Differential(t)(x(t))) - F*cos(t*ω) - k*y(t) + Differential(t)(x(t))*γ + x(t)*(ω1^2) + (x(t)^3)*α1 ~ 0
Differential(t)(Differential(t)(y(t))) - k*x(t) + Differential(t)(y(t))*γ + y(t)*(ω2^2) + (y(t)^3)*α2 ~ 0
@soumyasrtk soumyasrtk added the bug Something isn't working label Sep 29, 2024
@oameye
Copy link
Member

oameye commented Oct 6, 2024

Thanks for the report :)

You are using wrong syntax in the first example. eqs is a vector of Num (symbolic expression). Writing eqs~[F*cos(ω*t), 0] equates the vectors so that the type would be Symbolics.Num[...] ~ Symbolics.Num[...]. However, you would to equate the indivual expressions. Broadcasting the equation symbol ~ gives Vector{Equation}, i.e., eqs .~ [F*cos(ω*t), 0] (Notice, .~ vs ~.)

@variables ω1, ω2, t, ω, F, γ, α1, α2, k, x(t), y(t);
rhs = [ d(x, t, 2) + ω1^2 * x + γ*d(x,t) + α1*x^3 - k*y,
        d(d(y,t),t) + ω2^2*y + γ*d(y,t) + α2*y^3 - k*x]
eqs = rhs.~[F*cos*t), 0]

diff_eq = DifferentialEquation(rhs .~[F*cos*t), 0], [x, y])

Nevertheless, we should throw an argument error. Will implement this.

oameye added a commit that referenced this issue Oct 6, 2024
@oameye oameye linked a pull request Oct 6, 2024 that will close this issue
oameye added a commit that referenced this issue Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants