Solving an ODE and simplifying the result

27 views
Skip to first unread message

Oscar Alberto Castillo Felisola

unread,
May 13, 2019, 3:44:07 PM5/13/19
to sage-support
This post was prepared to be upload to ask.sagemath.org, but I got a warning "Spam was detected on your post, sorry for if this is a mistake" that forbids me to post the question.

-----------------------------


I'm interested in solving the differential equation $$3 h' + 3 h^2 = c_1,$$ where $c_1$ is a positive real number.

    var('t')
    var('c1', latex_name=r'c_1')
    h = function('h')(t)
    eq = -3*h^2 + c1 - 3*diff(h, t)
    eq_sol = desolve(eq, h, ivar=t, contrib_ode=True)

The above code works, but it's not solved explicitly for $h$, so

    h_sol = solve(eq_sol, h)
    h_sol = h_sol[0]
    h_sol

This gives something like  $$h\left(t\right) = \frac{\sqrt{3} \sqrt{c_{1}} {\left(e^{\left(\frac{2}{3} \, \sqrt{3} C \sqrt{c_{1}} + \frac{2}{3} \, \sqrt{3} \sqrt{c_{1}} t\right)} + 1\right)}}{3 \, {\left(e^{\left(\frac{2}{3} \, \sqrt{3} C \sqrt{c_{1}} + \frac{2}{3} \, \sqrt{3} \sqrt{c_{1}} t\right)} - 1\right)}},$$

in sage notation (non-LaTeX) it starts like

    h(t) == 1/3*sqrt(3)*sqrt(c1)* ...

**Question 1:** Is there a way to assing to the solution (i.e. `h_sol`) the RHS of the above? without the `h(t) == ` part.

I had to assign by hand (it is ease, but it would be nice to automatize the assignation)

    var('C')    # the integration constant introduced above
    h_sol = 1/3*sqrt(3)*sqrt(c1)* ...

Then, by simply looking at the solution it is clear that it can be simplified. I tried things like

    h_sol = h_sol.canonicalize_radical()
    h_sol = h_sol.collect_common_factors()
    h_sol = h_sol.simplify_rectform(complexity_measure = None)

but none of them returns the expected result, which could be obtained from Mathematica's kernel

    mathematica("DSolve[3*h'[t] + 3*h[t]^2 == C[1], h[t], t]//FullSimplify")

$$ \sqrt{\frac{c_1}{3}} \tanh\left( \sqrt{\frac{c_1}{3}} (t - 3 c_2) \right)  $$

**Question 2:** How could the expression `h_sol` be manipulated to obtain the hyperbolic tangent?

slelievre

unread,
May 14, 2019, 2:16:56 AM5/14/19
to sage-support
Mon 2019-05-13 19:44:07 UTC, Oscar Alberto Castillo Felisola:
>
> This post was prepared for ask.sagemath.org, but I got a warning
> "Spam was detected on your post, sorry for if this is a mistake"
> that forbids me to post the question.

Sorry for the inconvenience caused by the spam detection on Ask Sage.
We have to have it, or the level of spam would be unbearable...

I spotted a typo in your post: in one case the word "assign"
is mis-spelled with "g" and "n" swapped, leading to an involuntary
"bad word". Might that be what triggered the spam detection?

Reply all
Reply to author
Forward
0 new messages