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/usinginterpolatedcurveonparametricplot/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(1x)`, that has a similar shape.
th = var('theta')
z = log(1x)
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/howtojoinfunctionswithanintermediatefittoobtainsmoothderivatives/), 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?cav_rtThu, 04 Feb 2021 23:24:29 +0100https://ask.sagemath.org/question/55581/Spline interpolation varies hugely when variables are rescaled in 3dlists ?https://ask.sagemath.org/question/52429/splineinterpolationvarieshugelywhenvariablesarerescaledin3dlists/Dear all,
Here is a short script:

(nbx, nby) = (74, 90)
def fx(x):
return (0.5 + x/2.5)
def fy(y):
return (40*y)
zetaPlot = list_plot3d([(30 * (fx(x/nbx)1/2)+1/2 , fy(y/nby), 5 * abs(zeta(fx(x/nbx) + I*fy(y/nby))))
for x in range(nbx, nbx+1) for y in range(nby, nby+1)],
interpolation_type = 'spline')
zetaPlot.show()

Now modify the zcoordinate: replace "5 * abs(zeta...)" by "abs(zeta...)"
The resulting graph is essentially flat. Can anyone tell me what is happening there?
Also, I would like to get rid of my scaling parameters 30 and 5 by using frame_aspect_ratio, to get cleaner code and a better annoted frame, but I don't seem to understand how to do it.
A great many thanks for anyone who would take the time to teach me that, it is some hours that I'm struggling with some docs and examples without having reached much 
Best, OlivierOlivier R.Sat, 11 Jul 2020 15:05:32 +0200https://ask.sagemath.org/question/52429/Correct input for list_plot3d(..., interpolation='spline')https://ask.sagemath.org/question/42020/correctinputforlist_plot3dinterpolationspline/I'm trying to construct smooth surfaces from lists of points in 3space using `list_plot3d` and the `spline` option, but without success. For example, the input
> list_plot3d ([(1, 2, 3), (2, 1, 3), (3, 1, 2), (1 ,3 ,2), (2, 3, 1), (3, 2, 1)], interpolation_type='spline')
returns the error
>TypeError: m >= (kx+1)(ky+1) must hold
The following returns the expected piecewise linear surface suggesting that there is a special restriction on the input when using the `spline` option.
> list_plot3d ([(1, 2, 3), (2, 1, 3), (3, 1, 2), (1 ,3 ,2), (2, 3, 1), (3, 2, 1)])
**Question**: What is the correct input to obtain a best fit polynomial surface going through the six points in $\mathbb{R}^3$?
**Edit**: As pointed out by @slelievre, since these six points lie in a common plane, the corresponding surface should be the plane containing the points. So why does `Sage` throw an error instead of this plane?amdallSun, 15 Apr 2018 20:05:24 +0200https://ask.sagemath.org/question/42020/How to plot Bspline basis functionshttps://ask.sagemath.org/question/25898/howtoplotbsplinebasisfunctions/Given a degree d and knot sequence t[i] I would like to be able to generate plots of all the Bspline basis functions corresponding to the specified d and t[i]. Is there a straightforward way to do this in Sage?rdfuhrMon, 23 Feb 2015 04:48:02 +0100https://ask.sagemath.org/question/25898/spline smoothing parameterhttps://ask.sagemath.org/question/10499/splinesmoothingparameter/Apparently, [there is this thing called a spline smoothing parameter](http://www.mathworks.com/help/curvefit/csaps.html). Needless to say, our native spline support doesn't seem to have this. Is there any subpart of Sage that does? (E.g., R, Scipy, etc.)kcrismanTue, 03 Sep 2013 00:26:19 +0200https://ask.sagemath.org/question/10499/How to plot derivative and antiderivative of a splinehttps://ask.sagemath.org/question/9491/howtoplotderivativeandantiderivativeofaspline/Suppose I have a spline like that:
from sage.gsl.all import spline
values = [(3,2),(2,0),(1,2),(3,1),(4,5)]
interpolation = spline(values)
plot(interpolation,(3,5)) + list_plot(values)
![output](/upfiles/1351772799931024.png)
What's the easiest way to plot the derivative and the antiderivative functions of the spline?
Note that I want just the plot, not a symbolic expression of both, so numerical methods should apply. However getting a symbolic expression would be the best.
How can I find maxima, minima and roots of the spline? Numerically would be good enough.sagefanThu, 01 Nov 2012 06:20:14 +0100https://ask.sagemath.org/question/9491/how to convert Spline to Piecewise?https://ask.sagemath.org/question/9458/howtoconvertsplinetopiecewise/I want to get the result analytic expression of a spline. How to get it?
Thanks for help.zasdfgbnmTue, 23 Oct 2012 02:20:06 +0200https://ask.sagemath.org/question/9458/spline representation of a spiralhttps://ask.sagemath.org/question/9351/splinerepresentationofaspiral/Hello all, I'm new to this forum. :)
I'm trying to represent a spiral as a spline and was wondering how I could do it. My spiral has very specific properties which may make the representation easier (or not?)
At the bottom of this post is a representation of Euclidean 2D space with numbers ranging from 1 to C (hex numbers). These are the points, numbered in order, that the spiral must go through. Each + is separated by 4 (i.e. these are 1/4th divisions) for convenience and is to scale.
Does anyone have any idea how I would represent this using a spline? Your help is much appreciated.
Maxx
<pre>
+ + + + + + + + +


A
+ + + + + + + + +


6
+ + + + + + + + +


2
+ + + + + + + + +



+B+7+3+159+



+ + + + + + + + +


4
+ + + + + + + + +


8
+ + + + + + + + +


C
+ + + + + + + + +
</pre>MaxxWed, 26 Sep 2012 12:45:58 +0200https://ask.sagemath.org/question/9351/how to find root of a splinehttps://ask.sagemath.org/question/9329/howtofindrootofaspline/Basicaly the title says it: I have data points for which i need to find the x value where y is a known value. I tried it like this, but it seems that it should be done differently:
from sage.gsl.all import spline
data=[[0,1],[1,2],[2,2.2],[3,2.4],[4,0.4],[5,0.1],[6,0.5]]
func=spline(data)
x=var('x')
find_root(func(x),0,6)
..[Error message with main idea  TypeError: unable to simplify to float approximation]wizulisTue, 18 Sep 2012 04:41:52 +0200https://ask.sagemath.org/question/9329/