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.Thu, 04 Feb 2021 23:24:29 +0100Using interpolated curve on parametric plothttps://ask.sagemath.org/question/55581/using-interpolated-curve-on-parametric-plot/Hi,
my skills in numerics are very limited, thus maybe this is a silly question. Is it possible, in sage or python, to interpolate a numerical solution of a differential equation and use it as a symbolic expression? Let me explain my problem.
I have the following differential equation and numerical solution
z = function('z')(x)
de = diff(z,x) == sqrt(-36*(2*x/sqrt(x^2 + 5) - (x^2 - 1)*x/(x^2 + 5)^(3/2))^2 + (x^2 + 5)/(x^2 - 1)^2)
var('nz')
de_sol = desolve_rk4(de.rhs(),dvar=nz,ics=[0,0],ivar=x,end_points=.93, step=.01)
I would like to use the above solution as z(x) and (at first) plot a parametric surface. For illustrating, I will use `z = -log(1-x)`, that has a similar shape.
th = var('theta')
z = -log(1-x)
r = -6*(x^2 - 1)/sqrt(x^2 + 5)
parametric_plot3d([r*cos(th),r*sin(th),z],(th,0,2*pi), (x,0,.93))
I tried:
- [spline](https://doc.sagemath.org/html/en/reference/calculus/sage/calculus/interpolation.html?highlight=spline): it fits greatly, but the output cannot be used as symbolic. Parametric plot is not allowed.
- [lagrange_polynomial](https://doc.sagemath.org/html/en/reference/polynomial_rings/sage/rings/polynomial/polynomial_ring.html?highlight=lagrange_polynomial#sage.rings.polynomial.polynomial_ring.PolynomialRing_field.lagrange_polynomial): it gives me a polynomial fit that can be used for parametric plot, but the interpolation fails "close" to the divergence at x=1.
- I've tried to follow [this post](https://ask.sagemath.org/question/53909/how-to-join-functions-with-an-intermediate-fit-to-obtain-smooth-derivatives/), but 1) I didn't find out how to pass my `de_sol` to maxima (`maxima('p:de_sol')` doesn't work) and 2) I don't know how to turn the maxima `charfun` into sage `piecewise`. Maxima [documentation](https://maxima.sourceforge.io/docs/manual/maxima_257.html#cspline) doesn't help that much.
Any idea?Thu, 04 Feb 2021 23:24:29 +0100https://ask.sagemath.org/question/55581/using-interpolated-curve-on-parametric-plot/