Ask Your Question
0

Strange constants in desolve_system result for first-order linear system

asked 0 years ago

Nate Eldredge gravatar image

updated 0 years ago

I'm trying to find the general solution of a first-order linear system with desolve_system. I solved it first with initial conditions, and then wanted to find the general solution:

var('t')
y=function('y')(t)
x=function('x')(t)
print(desolve_system([diff(x,t) == y, diff(y,t) == -10*x + -2*y], [x,y], ics=[0,-1,1]))
print(desolve_system([diff(x,t) == y, diff(y,t) == -10*x + -2*y], [x,y]))

The output is:

[x(t) == -cos(3*t)*e^(-t), y(t) == (cos(3*t) + 3*sin(3*t))*e^(-t)]
[x(t) == 1/3*((x(0) + 1)*sin(3*t) + 3*cos(3*t)*x(0))*e^(-t), y(t) == -1/3*((10*x(0) + 1)*sin(3*t) - 3*cos(3*t))*e^(-t)]

Try it on SageMathCell

In the general solution, there ought to be two unknown constants x(0) and y(0), but instead there's only x(0), and a very strange-looking x(0) + 1.

If I omit the preceding desolve_system with initial values, then I get the expected output

[x(t) == 1/3*((x(0) + y(0))*sin(3*t) + 3*cos(3*t)*x(0))*e^(-t), y(t) == -1/3*((10*x(0) + y(0))*sin(3*t) - 3*cos(3*t)*y(0))*e^(-t)]

Try it on SageMathCell

This is reproducible on SageMathCell and also with SageMath version 10.4, Release Date: 2024-07-19 on MacOS arm64 installed from the Homebrew cask.

Update: Still reproducible with SageMath 10.5. I have now reported it on Github as #39104.

Preview: (hide)

Comments

1

At Sagecell (running Sage 10.2) and at my local Sage 10.5beta, result is

[x(t) == 1/3*((x(0) + y(0))*sin(3*t) + 3*cos(3*t)*x(0))*e^(-t),
 y(t) == -1/3*((10*x(0) + y(0))*sin(3*t) - 3*cos(3*t)*y(0))*e^(-t)]
Max Alekseyev gravatar imageMax Alekseyev ( 0 years ago )

I updated the test case. It seems that an earlier command had an effect.

Nate Eldredge gravatar imageNate Eldredge ( 0 years ago )

It looks like a bug. Please report at https://github.com/sagemath/sage/issues

Max Alekseyev gravatar imageMax Alekseyev ( 0 years ago )

This may or may not be a bug :

sage: reset()
sage: t=var("t")
sage: x=function("x")(t)
sage: y=function("y")(t)
sage: des=[diff(x,t) == y, diff(y,t) == -10*x + -2*y]
sage: SolG=desolve_system([diff(x,t) == y, diff(y,t) == -10*x + -2*y], [x,y]) ;
....: SolG
[x(t) == 1/3*((x(0) + 1)*sin(3*t) + 3*cos(3*t)*x(0))*e^(-t),
 y(t) == -1/3*((10*x(0) + 1)*sin(3*t) - 3*cos(3*t))*e^(-t)]

This strange-looking solution does check the original equations :

sage: list(map(lambda c:bool(reduce(lambda a, b:a.substitute_function(b.lhs().operator(), b.rhs().function()), SolG, des[0])), des))
[True, True]

But this solution may be only part of the solution.

To be continued...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 0 years ago )

Follow-up.

Sympy offers a more complete solution :

sage: import sympy
sage: SolGS=[u._sage_() for u in sympy.dsolve(*map(sympy.sympify, ([diff(x,t) ==
....:  y, diff(y,t) == -10*x + -2*y], [x,y])))] ; SolGS
[x(t) == 1/10*(3*C1 - C2)*cos(3*t)*e^(-t) + 1/10*(C1 + 3*C2)*e^(-t)*sin(3*t),
 y(t) == C2*cos(3*t)*e^(-t) - C1*e^(-t)*sin(3*t)]

which does check the original differential equations:

sage: var("C1, C2")
(C1, C2)
sage: list(map(lambda c:bool(reduce(lambda a, b:a.substitute_function(b.lhs().op
....: erator(), b.rhs().function()), SolGS, des[0])), des))
[True, True]
Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 0 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 0 years ago

Emmanuel Charpentier gravatar image

x(0) and y(0) are your constants, fixed by the initial values.. In this specific case, Sage was able to identify them and dispense with new symbols for these constants.

Note : on Sage 10.5.rc0 running on Debian testing, I get the same results as Max Alexeiev. Could you check your inputs ?

HTH,

Preview: (hide)
link

Comments

You're right, there were earlier inputs that affected it, though I don't see why they should. I updated the question with a test case that should be reproducible.

Nate Eldredge gravatar imageNate Eldredge ( 0 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 0 years ago

Seen: 164 times

Last updated: Dec 09 '24