Opened 12 years ago

Closed 8 years ago

# improve desolve_system initial condition documentation

Reported by: Owned by: Ryan Hinton Burcin Erocal major sage-6.5 calculus calculus, maxima, symbolics, beginner Robert Marik Sergey Bykov Karl-Dieter Crisman N/A dfbad1c dfbad1c4ffbd6ea02985e76e4fe33a4278badb2a

### Description (last modified by Karl-Dieter Crisman)

Edit: See comments for the actual issue.

desolve_system apparently ignores initial conditions. Notice the identical results in the two calls in the following example.

```sage: t = var('t')
sage: epsilon = var('epsilon')
sage: x1 = function('x1', t)
sage: x2 = function('x2', t)
sage: de1 = diff(x1,t) == epsilon
sage: de2 = diff(x2,t) == -2
sage: desolve_system([de1, de2], [x1, x2], ivar=t)
[x1(t) == epsilon*t + x1(0), x2(t) == -2*t + x2(0)]
sage: desolve_system([de1, de2], [x1, x2], ics=[1,1], ivar=t)
[x1(t) == epsilon*t + x1(0), x2(t) == -2*t + x2(0)]
```

### comment:1 follow-up:  2 Changed 12 years ago by Robert Marik

Status: new → needs_info

As I observed from documentation, the ics have to be in the form [x0,x1(x0),x2(x0)]

The following works.

```sage: t = var('t')
sage: epsilon = var('epsilon')
sage: x1 = function('x1', t)
sage: x2 = function('x2', t)
sage: de1 = diff(x1,t) == epsilon
sage: de2 = diff(x2,t) == -2
sage: desolve_system([de1, de2], [x1, x2], ivar=t)
[x1(t) == epsilon*t + x1(0), x2(t) == -2*t + x2(0)]
sage: desolve_system([de1, de2], [x1, x2], ics=[0,1,1], ivar=t)
[x1(t) == epsilon*t + 1, x2(t) == -2*t + 1]
```

O.K. what to do with this?

Update documentation to mention this explicitly?

Assume (silently or with a warning) that ivar=0 for initial condition whenever the number of dependent variables equals the number of initial conditions?

### comment:2 in reply to:  1 Changed 12 years ago by Ryan Hinton

Status: needs_info → needs_work

Thanks for pointing out my mistake!

I think updating the documentation is a great idea. I think we should raise a ValueError? exception if `ics` is incomplete. Assuming an initial value of 0 is not horrible, but Python and Sage seem to prefer explicit-ness.

As I observed from documentation, the ics have to be in the form [x0,x1(x0),x2(x0)]

The following works.

```sage: t = var('t')
sage: epsilon = var('epsilon')
sage: x1 = function('x1', t)
sage: x2 = function('x2', t)
sage: de1 = diff(x1,t) == epsilon
sage: de2 = diff(x2,t) == -2
sage: desolve_system([de1, de2], [x1, x2], ivar=t)
[x1(t) == epsilon*t + x1(0), x2(t) == -2*t + x2(0)]
sage: desolve_system([de1, de2], [x1, x2], ics=[0,1,1], ivar=t)
[x1(t) == epsilon*t + 1, x2(t) == -2*t + 1]
```

O.K. what to do with this?

Update documentation to mention this explicitly?

Assume (silently or with a warning) that ivar=0 for initial condition whenever the number of dependent variables equals the number of initial conditions?

### comment:3 Changed 12 years ago by Karl-Dieter Crisman

Description: modified (diff) desolve_system ignores initial conditions → improve desolve_system initial condition documentation

I agree that we should be explicit here. There is no obvious default for a diffeq; initial condition of zero is not the same as starting to count at 0 or 1. Yes, updating the documentation would be great for this.

### comment:5 Changed 9 years ago by Jeroen Demeyer

Milestone: sage-5.11 → sage-5.12

### comment:6 Changed 9 years ago by For batch modifications

Milestone: sage-6.1 → sage-6.2

### comment:7 Changed 8 years ago by For batch modifications

Milestone: sage-6.2 → sage-6.3

### comment:8 Changed 8 years ago by For batch modifications

Milestone: sage-6.3 → sage-6.4

### comment:9 Changed 8 years ago by Sergey Bykov

Branch: → u/captaintrunky/improve_desolve_system_initial_condition_documentation

### comment:10 Changed 8 years ago by Sergey Bykov

Authors: → Sergey Bykov → dfbad1c4ffbd6ea02985e76e4fe33a4278badb2a needs_work → needs_review

New commits:

 ​dfbad1c `Fixed bug with incomplete initial conditions`

### comment:11 Changed 8 years ago by Karl-Dieter Crisman

This looks good.

While testing this (it doesn't always work, but only in cases of user error like not specifying each function as also a variable to be solved for (at least, I think that is user error?)), I got the following mysterious error.

```sage:         sage: t = var('t')
sage:         sage: u = var('u')
sage:         sage: x = function('x', t)
sage:         sage: y = function('y', t)
sage:         sage: de1 = diff(x,t) + y - 1 == 0
sage:         sage: de2 = diff(y,t) - x + u == 0
sage:         sage: des = [de1,de2]
sage:         sage: ics = [0,1,-1]
sage:         sage: vars = [x,y]
sage:         sage: sol = desolve_system(des, vars, ics, u); sol
TypeError: ECL says: Error executing code in Maxima:
```

I get similar errors if Maxima just can't solve the system, but with a message. While it's true that `u` isn't one of the variables differentiated by or of the functions `u`, at least it should give an error message that the system doesn't make sense; this could easily happen as a typo for something that works fine.

```sage:         sage: sol = desolve_system(des, vars, ics, t); sol
[x(t) == -(u - 1)*cos(t) + u + 2*sin(t),
y(t) == -(u - 1)*sin(t) - 2*cos(t) + 1]
```

Perhaps for another ticket.

### comment:12 Changed 8 years ago by Karl-Dieter Crisman

Milestone: sage-6.4 → sage-6.5 → Karl-Dieter Crisman needs_review → positive_review

### comment:13 Changed 8 years ago by Volker Braun

Branch: u/captaintrunky/improve_desolve_system_initial_condition_documentation → dfbad1c4ffbd6ea02985e76e4fe33a4278badb2a → fixed positive_review → closed
Note: See TracTickets for help on using tickets.