Javatpoint Logo
Javatpoint Logo

Generate a Vandermonde Matrix of the Legendre Polynomial with a Float Array of Points in Python using NumPy

Let us know a good approach to generating the Vandermonde Matrix of the Legendre Polynomial with a Float Array of Points in Python using NumPy.

Example:

Results:

[[ 1.00000e+00      -1.670000e+00     3.6833500e+00]
 [ 1.00000e+00       0.81000e+00     0.48415000e+00]
 [ 1.00000e+00      -3.57000e+00    18.61735000e+00]
 [ 1.00000e+00       1.6000e+00      3.34000e+00]
 [ 1.00000e+00       2.8000e+00     11.26000e+00]]

NumPy:

NumPy is a generally valuable display taking care of the pack. It gives a world-class show of complex group things and gadgets for working with these displays, and it is an urgent group for sensible enlisting with Python. Other than its certain intelligent purposes, NumPy can similarly be used as a successful complex holder of nonexclusive data.

A bunch in NumPy is a table of parts (by and large numbers), the total of a comparative sort, recorded by a tuple of positive numbers. In NumPy, various parts of the group are known as the place of the cluster. A tuple of numbers giving the size of the show along every viewpoint is known as the condition of the display. A group class in NumPy is called ndarray. Parts in NumPy shows are gotten to using square segments and can be presented using settled Python Records.

NumPy.legvander():

Suppose we want to generate a pseudo-Vandermonde matrix of the Legendre polynomial with the help of a float array of the points. In that case, the user has to call the NumPy.legvander () method from the Python library NumPy into our program. After calling the method, we will get the results, or it will return the pseudo-Vandermonde matrix with the shape of the returned matrix as a.shape + (deg + 1), here The last index of the matrix is the degree of the corresponding Legendre polynomial.

Syntax:

The syntax to call the method is:

Parameter:

  • a: [ array_like ] Array of the points. The data type is converted to float64 or complex128, depending on whether any elements are complex. If a is scalar, it is converted to a 1-D array.
  • deg: [int] Degree is referred to the degree of the resulting matrix.

Results:

The result of the problem will be the matrix that has the size as the sum of the array size and degree plus one, i.e., a. size+ (degree + 1).

Example:

In the following example below, we are creating an array that contains five elements that are of float data type and other data type, using the NumPy.legvender () method. And using the array data, we will generate a Vandermonde matrix of Legendre polynomial with the degree of 2 in Python.

Output:

The input Array is:
[-1.67  0.81 -3.57  1.6   2.8]
The Dimensions of the array are:
1
The result of the Vandermonde matrix is: 
[[ 1.00000e+00      -1.670000e+00     3.6833500e+00]
 [ 1.00000e+00       0.81000e+00     0.48415000e+00]
 [ 1.00000e+00      -3.57000e+00    18.61735000e+00]
 [ 1.00000e+00       1.6000e+00      3.34000e+00]
 [ 1.00000e+00       2.8000e+00     11.26000e+00]]

Example 2:

In the following example below, we are creating an array that contains ten elements that are of float data type and other data type, using the NumPy.legvender () method. And using the array data, we will generate a Vandermonde matrix of Legendre polynomial with the degree of 5 in Python.

Output:

The input Array is:
[-1.67  0.81 -3.57  1.6   2.8  -7.97  6.45  -0.76  6.45  -0.76  -3.47  2.43]
The Dimensions of the array are:
1
The Result of the Vandermonde matrix is: 
[[ 1.23000000e+00 -1.62000000e+00  3.51735000e+00 -7.50973250e+00
   1.45129525e+01 -3.42010179e+01]
 [ 1.23000000e+00  5.80000000e-01  4.60000000e-03 -3.82220000e-01
  -3.91403300e-01 -1.52849045e-01]
 [ 1.23000000e+00 -3.57000000e+00  1.86173500e+01 -1.08393232e+02
   6.63223708e+02 -5.17516096e+03]
 [ 1.23000000e+00  1.44000000e+00  2.61040000e+00  5.30496000e+00
   1.14106992e+01  3.53325643e+01]
 [ 1.23000000e+00  2.75000000e+00  1.08437500e+01  4.78671875e+01
   2.22228027e+02  2.06173499e+03]
 [ 1.23000000e+00 -8.97000000e+00  1.20191350e+02 -1.79088068e+03
   2.80222060e+04 -3.51013834e+05]
 [ 1.23000000e+00  7.45000000e+00  8.27537500e+01  1.02255906e+03
   1.32695485e+04  2.77126598e+05]
 [ 1.23000000e+00 -5.60000000e-01 -2.96000000e-02  4.00960000e-01
  -3.70740800e-01  4.29387264e-02]
 [ 1.23000000e+00 -4.74000000e+00  3.32014000e+01 -2.59131060e+02
   2.12459109e+03 -1.56197064e+04]
 [ 1.23000000e+00  3.33000000e+00  1.61333500e+01  8.73200925e+01
   4.96757827e+02  2.56771034e+03]]






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA