Solving an ODE and simplifying the result
I'm interested in solving the differential equation 3h′+3h2=c1, where c1 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(t)=√3√c1(e(23√3C√c1+23√3√c1t)+1)3(e(23√3C√c1+23√3√c1t)−1),
in sage notation (non-LaTeX) it starts like
h(t) == 1/3*sqrt(3)*sqrt(c1)* ...
Question 1: Is there a way to allocate to the solution (i.e. h_sol
) the RHS of the above? without the h(t) ==
part.
I had to set by hand (it is ease, but it would be nice to automatize the allocation)
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")
√c13tanh(√c13(t−3c2))
Question 2: How could the expression h_sol
be manipulated to obtain the hyperbolic tangent?