Opened 9 years ago

Closed 5 years ago

# improve desolve_system initial condition documentation

Reported by: Owned by: rhinton burcin major sage-6.5 calculus calculus, maxima, symbolics, beginner robert.marik Sergey Bykov Karl-Dieter Crisman N/A dfbad1c (Commits) dfbad1c4ffbd6ea02985e76e4fe33a4278badb2a

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 9 years ago by robert.marik

• Status changed from new to 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 9 years ago by rhinton

• Status changed from needs_info to 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 9 years ago by kcrisman

• Description modified (diff)
• Summary changed from desolve_system ignores initial conditions to 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 6 years ago by jdemeyer

• Milestone changed from sage-5.11 to sage-5.12

### comment:6 Changed 6 years ago by vbraun_spam

• Milestone changed from sage-6.1 to sage-6.2

### comment:7 Changed 6 years ago by vbraun_spam

• Milestone changed from sage-6.2 to sage-6.3

### comment:8 Changed 5 years ago by vbraun_spam

• Milestone changed from sage-6.3 to sage-6.4

### comment:9 Changed 5 years ago by captaintrunky

• Branch set to u/captaintrunky/improve_desolve_system_initial_condition_documentation

### comment:10 Changed 5 years ago by captaintrunky

• Authors set to Sergey Bykov
• Status changed from needs_work to needs_review

New commits:

 ​dfbad1c `Fixed bug with incomplete initial conditions`

### comment:11 Changed 5 years ago by kcrisman

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 5 years ago by kcrisman

• Milestone changed from sage-6.4 to sage-6.5
• Reviewers set to Karl-Dieter Crisman
• Status changed from needs_review to positive_review