Hi,
I usually use symbols first, and only substitute into the final
result, that way I can see what's going on under the hood:
In [8]: var("a b c d")
Out[8]: (a, b, c, d)
In [9]: Eq4=a*A(t)-b*A(t).diff(t)-c*A(t).diff(t,2)+d
In [10]: Eq4
Out[10]:
2
d d
a⋅A(t) - b⋅──(A(t)) - c⋅───(A(t)) + d
dt 2
dt
In [11]: soln = dsolve(Eq4)
In [12]: soln
Out[12]:
⎛ ____________⎞ ⎛ ____________⎞
⎜ ╱ 2 ⎟ ⎜ ╱ 2 ⎟
t⋅⎝-b - ╲╱ 4⋅a⋅c + b ⎠ t⋅⎝-b + ╲╱ 4⋅a⋅c + b ⎠
──────────────────────── ────────────────────────
2⋅c 2⋅c d
A(t) = C₁⋅ℯ + C₂⋅ℯ - ─
a
In [13]: soln.rhs
Out[13]:
⎛ ____________⎞ ⎛ ____________⎞
⎜ ╱ 2 ⎟ ⎜ ╱ 2 ⎟
t⋅⎝-b - ╲╱ 4⋅a⋅c + b ⎠ t⋅⎝-b + ╲╱ 4⋅a⋅c + b ⎠
──────────────────────── ────────────────────────
2⋅c 2⋅c d
C₁⋅ℯ + C₂⋅ℯ - ─
a
In [14]: soln.rhs.subs({a: -123456.78, b: -9876.54, c: -0.00032, d:
1357908.64})Out[14]:
12.4999979732365⋅t -30864199.999998⋅t
C₁⋅ℯ + C₂⋅ℯ + 10.999060885923
Is the [14] what you wanted to get?
Ondrej
On Sat, Apr 4, 2015 at 10:27 PM, G B <[email protected]> wrote:
> Still wrestling with dsolve... Below is a call with an arbitrary
> differential equation. Any idea why dsolve is returning terms with these
> enormous integers? All of the coefficients are floats in this case. The
> expression is impervious to .n() (as mentioned in my earlier question).
> Converting to a numpy function to evaluate the results works, but throws an
> exception when called.
>
> I can't seem to get past this point in the analysis. Any idea how I can get
> this into a form I can continue working with?
>
> A=symbols(r'A',cls=Function)
> t=symbols(r't')
> Eq4=-123456.78*A(t)-9876.54*A(t).diff(t)-0.00032*A(t).diff(t,2)+1357908.64
> soln=dsolve(Eq4)
> print(soln.n())
>
> A(t) == C1*exp(125*t*(-33935533038108675 -
> sqrt(1151618536954453541512853661417481))/274877906944) +
> C2*exp(125*t*(-33935533038108675 +
> sqrt(1151618536954453541512853661417481))/274877906944) + 10.999060885923
>
>
> fn=lambdify(t,soln.rhs,'numpy')
>
>
> fn(3.2)
>
>
> ---------------------------------------------------------------------------
> AttributeError Traceback (most recent call last)
> <ipython-input-42-bde0572cbbe1> in <module>()
> ----> 1 fn(3.2)
>
> //anaconda/lib/python3.4/site-packages/numpy/__init__.py in
> <lambda>(_Dummy_73)
>
> AttributeError: 'int' object has no attribute 'sqrt'
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/88a9432e-a322-460b-9556-ddd85cdad519%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/CADDwiVBZWzJ4kTk0xGwRY7aQyyc6LExUv1AoC3vgr2S5EaB%2BEg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.