How to compute the numerical solution on the general points
ShengChenBNU opened this issue · comments
I'm wondering how to evaluate the numerical solution at equal-distance points instead of the Gauss quadrature nodes?
Hi
You can do something like this last line, with keyword mesh="uniform"
>>> from shenfun import *
>>> L = FunctionSpace(4, 'Legendre')
>>> u = Function(L)
>>> u[1] = 1 # This creates the function u(x) = x
>>> print(u.backward()) # Get u on quadrature points
[-0.86113631 -0.33998104 0.33998104 0.86113631]
>>> print(u.backward(mesh='uniform')) # Get u on uniform mesh
[-1. -0.33333333 0.33333333 1. ]
Thanks for the prompt reply! It works very well!
Additional questions:
(1) Is it possible to obtain the function's value on the mesh which is defined by ourselves?
(2) Does it have the operator to obtain the matrix whose columns or rows are the basis \phi_k(x), k=0,1,..n on a given mesh x=[x0,x1,..xm]
Additional questions:
(1) Is it possible to obtain the function's value on the mesh which is defined by ourselves?
Yes. Use Function evaluation
>>> x = np.linspace(-0.5, 0.5, 5)
>>> u(x)
array([-0.5 , -0.25, 0. , 0.25, 0.5 ])
(2) Does it have the operator to obtain the matrix whose columns or rows are the basis \phi_k(x), k=0,1,..n on a given mesh x=[x0,x1,..xm]
Yes.
>>> print(L.vandermonde(x))
[[ 1. -0.5 -0.125 0.4375 ]
[ 1. -0.25 -0.40625 0.3359375]
[ 1. 0. -0.5 -0. ]
[ 1. 0.25 -0.40625 -0.3359375]
[ 1. 0.5 -0.125 -0.4375 ]]
Or
>>> print(L.evaluate_basis_all(x))
[[ 1. -0.5 -0.125 0.4375 ]
[ 1. -0.25 -0.40625 0.3359375]
[ 1. 0. -0.5 -0. ]
[ 1. 0.25 -0.40625 -0.3359375]
[ 1. 0.5 -0.125 -0.4375 ]]
The vandermonde
function only computes the orthogonal basis, which here is the Legendre basis functions. evaluate_basis_all
works for any basis.
Awesome!