Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to compute the numerical solution on the general points #92

Open
ShengChenBNU opened this issue Sep 14, 2022 · 4 comments
Open

How to compute the numerical solution on the general points #92

ShengChenBNU opened this issue Sep 14, 2022 · 4 comments

Comments

@ShengChenBNU
Copy link

I'm wondering how to evaluate the numerical solution at equal-distance points instead of the Gauss quadrature nodes?

@mikaem
Copy link
Member

mikaem commented Sep 14, 2022

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.        ]

@ShengChenBNU
Copy link
Author

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]

@mikaem
Copy link
Member

mikaem commented Sep 14, 2022

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.

@ShengChenBNU
Copy link
Author

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants