ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 23 Dec 2015 09:19:49 +0100Setting the conditions at t=0 for laplace transform with sage (instead of maxima)https://ask.sagemath.org/question/31713/setting-the-conditions-at-t0-for-laplace-transform-with-sage-instead-of-maxima/Hallo,
I am trying to calculate the laplace transform for the following differential equation with sage instead of maxima.
"m*'diff(x_f(t)+x_d(t),t,2)+d*'diff(x_d(t),t,1)+c*x_d(t)+Fext(t)=0"
But I do not find how to set the values in sage at t=0 for the functions x_d(t) and x_f(t). Before I did set it with maxima with
```
maxima.eval("atvalue(x_d(t), t=0, 0)$ atvalue('diff(x_d(t),t), t=0, 0)$");
maxima.eval("atvalue(x_f(t), t=0, 0)$ atvalue('diff(x_f(t),t), t=0, 0)$");
```
Basically, I am trying to use the sage laplace transfrom function instead of the sage-maxima function resulting in a nicer notebook without all the maxima.eval add maxima.-commands. I know that sage is using maxima for the transformation in the background.
BR Howil
Sun, 20 Dec 2015 16:56:36 +0100https://ask.sagemath.org/question/31713/setting-the-conditions-at-t0-for-laplace-transform-with-sage-instead-of-maxima/Answer by calc314 for <p>Hallo,
I am trying to calculate the laplace transform for the following differential equation with sage instead of maxima.
"m<em>'diff(x_f(t)+x_d(t),t,2)+d</em>'diff(x_d(t),t,1)+c*x_d(t)+Fext(t)=0"</p>
<p>But I do not find how to set the values in sage at t=0 for the functions x_d(t) and x_f(t). Before I did set it with maxima with
<code>
maxima.eval("atvalue(x_d(t), t=0, 0)$ atvalue('diff(x_d(t),t), t=0, 0)$");
maxima.eval("atvalue(x_f(t), t=0, 0)$ atvalue('diff(x_f(t),t), t=0, 0)$");
</code></p>
<p>Basically, I am trying to use the sage laplace transfrom function instead of the sage-maxima function resulting in a nicer notebook without all the maxima.eval add maxima.-commands. I know that sage is using maxima for the transformation in the background.</p>
<p>BR Howil</p>
https://ask.sagemath.org/question/31713/setting-the-conditions-at-t0-for-laplace-transform-with-sage-instead-of-maxima/?answer=31724#post-id-31724You can use `desolve_laplace` to do this. The initial conditions are given as `ics=[0,1,7]` meaning $y(0)=1$ and $y'(0)=7$.
var('y,t,s')
y=function('y',t)
ode=diff(y,t,2)-6*diff(y,t)-27*y==0
desolve_laplace(ode,y,ics=[0,1,7])
For teaching purposes, II've often not set the conditions up front, but will substitute for them later in the computation. For example,
var('y,t,s')
y=function('y',t)
ode=diff(y,t,2)-6*diff(y,t)-27*y==0
transformed=laplace(ode,t,s)
ans=solve(transformed,laplace(y,t,s))
f=ans[0].rhs()
y0=1
yprime0=7
f=f.subs(y(t=0)==y0)
f=f.subs(diff(y,t)(t=0)==yprime0)
inverse_laplace(f,s,t)
Mon, 21 Dec 2015 01:49:12 +0100https://ask.sagemath.org/question/31713/setting-the-conditions-at-t0-for-laplace-transform-with-sage-instead-of-maxima/?answer=31724#post-id-31724Comment by howil for <p>You can use <code>desolve_laplace</code> to do this. The initial conditions are given as <code>ics=[0,1,7]</code> meaning $y(0)=1$ and $y'(0)=7$.</p>
<pre><code>var('y,t,s')
y=function('y',t)
ode=diff(y,t,2)-6*diff(y,t)-27*y==0
desolve_laplace(ode,y,ics=[0,1,7])
</code></pre>
<p>For teaching purposes, II've often not set the conditions up front, but will substitute for them later in the computation. For example,</p>
<pre><code>var('y,t,s')
y=function('y',t)
ode=diff(y,t,2)-6*diff(y,t)-27*y==0
transformed=laplace(ode,t,s)
ans=solve(transformed,laplace(y,t,s))
f=ans[0].rhs()
y0=1
yprime0=7
f=f.subs(y(t=0)==y0)
f=f.subs(diff(y,t)(t=0)==yprime0)
inverse_laplace(f,s,t)
</code></pre>
https://ask.sagemath.org/question/31713/setting-the-conditions-at-t0-for-laplace-transform-with-sage-instead-of-maxima/?comment=31784#post-id-31784Thank you calc314, that was exactly what I was looking for.Wed, 23 Dec 2015 09:19:49 +0100https://ask.sagemath.org/question/31713/setting-the-conditions-at-t0-for-laplace-transform-with-sage-instead-of-maxima/?comment=31784#post-id-31784