Ask Your Question
0

Strange constants in desolve_system result for first-order linear system

asked 2024-11-19 04:23:22 +0100

Nate Eldredge gravatar image

updated 2024-12-01 22:08:27 +0100

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.

edit retag flag offensive close merge delete

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 ( 2024-11-20 03:40:29 +0100 )edit

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

Nate Eldredge gravatar imageNate Eldredge ( 2024-12-01 22:09:16 +0100 )edit

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

Max Alekseyev gravatar imageMax Alekseyev ( 2024-12-01 23:31:24 +0100 )edit

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 ( 2024-12-04 15:02:29 +0100 )edit

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 ( 2024-12-04 15:04:57 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2024-11-20 12:42:01 +0100

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,

edit flag offensive delete link more

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 ( 2024-12-01 22:08:58 +0100 )edit

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: 2024-11-19 04:23:22 +0100

Seen: 94 times

Last updated: Dec 01