1 | initial version |

Use `substitute_expression`

as follows:

```
sage: t = var('t')
sage: psi = function('psi',t)
sage: a = 3 * diff(psi)^2 - 2 * diff(psi) + 1
sage: a
3*D[0](psi)(t)^2 - 2*D[0](psi)(t) + 1
sage: a.substitute_expression(diff(psi)==t)
3*t^2 - 2*t + 1
```

2 | No.2 Revision |

~~Use ~~[Edited to answer your second question as well.]

To replace `diff(psi)`

by say `t`

, use `substitute_expression`

as follows:

```
sage: t = var('t')
sage: psi = function('psi',t)
sage: a = 3 * diff(psi)^2 - 2 * diff(psi) + 1
sage: a
3*D[0](psi)(t)^2 - 2*D[0](psi)(t) + 1
sage: a.substitute_expression(diff(psi)==t)
3*t^2 - 2*t + 1
```

To use the result of `solve`

to perform replacement, do as follows:

```
sage: var('V V_f chi l psi')
sage: eq0 = V == V_f * cos(chi)
sage: eq1 = l * psi == V_f * sin(chi)
sage: sol = solve(eq0, V_f)
sage: sol
[V_f == V/cos(chi)]
sage: eq0.subs_expr(sol[0])
V == V
```

(Note that `sol`

is a list with one element, which is an equation, and we want to use that equation for the replacement).

3 | No.3 Revision |

[Edited to answer your second question as well.]

To replace `diff(psi)`

by say `t`

, use `substitute_expression`

as follows:

```
sage: t = var('t')
sage: psi = function('psi',t)
sage: a = 3 * diff(psi)^2 - 2 * diff(psi) + 1
sage: a
3*D[0](psi)(t)^2 - 2*D[0](psi)(t) + 1
sage: a.substitute_expression(diff(psi)==t)
3*t^2 - 2*t + 1
```

To use the result of `solve`

to perform replacement, do as follows:

```
sage: var('V V_f chi l psi')
sage: eq0 = V == V_f * cos(chi)
sage: eq1 = l * psi == V_f * sin(chi)
sage: sol = solve(eq0, V_f)
sage: sol
[V_f == V/cos(chi)]
sage: eq0.subs_expr(sol[0])
V == V
sage: eq1.subs_expr(sol[0])
l*psi == V*sin(chi)/cos(chi)
```

~~(Note ~~Note that `sol`

is a list ~~with ~~containing one ~~element, which is an equation, and we want to ~~equation. We use that equation (item 0 of the list) for the ~~replacement).~~replacement.

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.