ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 14 May 2019 02:41:24 -0500Solving an ODE and simplifying the resulthttp://ask.sagemath.org/question/46517/solving-an-ode-and-simplifying-the-result/ 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 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")
$$ \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?DoxTue, 14 May 2019 02:41:24 -0500http://ask.sagemath.org/question/46517/.canonicalize_radical() produces incorrect resulthttp://ask.sagemath.org/question/44414/canonicalize_radical-produces-incorrect-result/I'm trying to simplify some trigonometric expressions using sage, and I noticed that .simplify_full() doesn't optimize those, unless a .canonicalize_radical() is used (thanks slelievre for [the hint](https://ask.sagemath.org/question/44391/simplify_full-doesnt-simplify-an-obvious-trigonometric-expression/?answer=44392#post-id-44392)). But that yields incorrect results for some expressions. For example:
sage: y = sqrt(sin(x)^2 + 4*sin(x) + 4) - sqrt(sin(x)^2 - 4*sin(x) + 4)
sage: y.simplify_full()
sqrt(sin(x)^2 + 4*sin(x) + 4) - sqrt(sin(x)^2 - 4*sin(x) + 4)
.canonicalize_radical() simplifies it further:
sage: y.canonicalize_radical()
4
But that is wrong! The answer should be `2*sin(x)`. Obviously it selected an incorrect sign for the second sqrt(...).
Is there a way to make .canonicalize_radical() smarter? Or any other way to simplify an expression like this correctly?sagenoviceSat, 24 Nov 2018 09:01:17 -0600http://ask.sagemath.org/question/44414/How to keep 1/sqrt(2) as 1/sqrt(2) ? [the canonical form is not canonical]http://ask.sagemath.org/question/36944/how-to-keep-1sqrt2-as-1sqrt2-the-canonical-form-is-not-canonical/ Hi all
Using sagetex to make computaion, I would like it to keep radical in the denominator (though I remember my 8 th grade course viewing the canonical form today in a pdf file seems odd )
so something like
1/sqrt(2) would not be written as
sqrt(2)/2 as it is normally.
I saw this related link : https://ask.sagemath.org/question/35236/simplify-an-expression-of-square-roots/
but for me the command
1/sqrt(2).maxima_methods().rootscontract().simplify()
gives also a "canonical" result.
Cheers,
Laurent BTue, 14 Mar 2017 12:20:00 -0500http://ask.sagemath.org/question/36944/canonicalize_radical for matrices.http://ask.sagemath.org/question/34302/canonicalize_radical-for-matrices/The following all works
sage: a = sqrt(2)*sqrt(3)*sqrt(6)
sage: v = vector([a])
sage: M = Matrix([v, v])
sage: a.canonicalize_radical()
6
sage: v.canonicalize_radical()
(6)
However the following doesn't work:
sage: M = Matrix([v, v])
sage: M.canonicalize_radical()
EDIT: Could somebody please tell me the right place to ask for "vectorization of canonicalize_radical for matrices" as a new feature of sage?Saul SchleimerTue, 02 Aug 2016 13:46:22 -0500http://ask.sagemath.org/question/34302/