Generate a Pseudo Vandermonde matrix of the Legendre polynomial and x, y, z array of points in Python

PythonNumpyServer Side ProgrammingProgramming

<p>To generate a pseudo Vandermonde matrix of the Legendre polynomial with x, y, z sample points, use the legendre.legvander3d() method in Python Numpy. Returns the pseudo-Vandermonde matrix of degrees deg and sample points (x, y, z).</p><p>The parameters, x, y ,z are arrays of point coordinates, all of the same shape. The dtypes will be converted to either float64 or complex128 depending on whether any of the elements are complex. Scalars are converted to 1-D arrays. The parameter, deg is a list of maximum degrees of the form [x_deg, y_deg, z_deg].</p><h2>Steps</h2><p>At first, import the required library &minus;</p><pre class="prettyprint notranslate">import numpy as np from numpy.polynomial import legendre as L</pre><p>Create arrays of point coordinates, all of the same shape using the numpy.array() method &minus;</p><pre class="prettyprint notranslate">x = np.array([1, 2]) y = np.array([3, 4]) z = np.array([5, 6])</pre><p>Display the arrays &minus;</p><pre class="prettyprint notranslate">print(&quot;Array1... &quot;,x) print(&quot; Array2... &quot;,y) print(&quot; Array3... &quot;,z)</pre><p>Display the datatype &minus;</p><pre class="prettyprint notranslate">print(&quot; Array1 datatype... &quot;,x.dtype) print(&quot; Array2 datatype... &quot;,y.dtype) print(&quot; Array3 datatype... &quot;,z.dtype)</pre><p>Check the Dimensions of both the arrays &minus;</p><pre class="prettyprint notranslate">print(&quot; Dimensions of Array1... &quot;,x.ndim) print(&quot; Dimensions of Array2... &quot;,y.ndim) print(&quot; Dimensions of Array3... &quot;,z.ndim)</pre><p>Check the Shape of both the arrays &minus;</p><pre class="prettyprint notranslate">print(&quot; Shape of Array1... &quot;,x.shape) print(&quot; Shape of Array2... &quot;,y.shape) print(&quot; Shape of Array3... &quot;,z.shape)</pre><p>To generate a pseudo Vandermonde matrix of the Legendre polynomial with x, y, z sample points, use the legendre.legvander3d() method in Python &minus;</p><pre class="prettyprint notranslate">x_deg, y_deg, z_deg = 2, 3, 4 print(&quot; Result... &quot;,L.legvander3d(x,y,z, [x_deg, y_deg, z_deg]))</pre><h2>Example</h2><pre class="demo-code notranslate language-numpy" data-lang="numpy">import numpy as np from numpy.polynomial import legendre as L # Create arrays of point coordinates, all of the same shape using the numpy.array() method x = np.array([1, 2]) y = np.array([3, 4]) z = np.array([5, 6]) # Display the arrays print(&quot;Array1... &quot;,x) print(&quot; Array2... &quot;,y) print(&quot; Array3... &quot;,z) # Display the datatype print(&quot; Array1 datatype... &quot;,x.dtype) print(&quot; Array2 datatype... &quot;,y.dtype) print(&quot; Array3 datatype... &quot;,z.dtype) # Check the Dimensions of both the arrays print(&quot; Dimensions of Array1... &quot;,x.ndim) print(&quot; Dimensions of Array2... &quot;,y.ndim) print(&quot; Dimensions of Array3... &quot;,z.ndim) # Check the Shape of both the arrays print(&quot; Shape of Array1... &quot;,x.shape) print(&quot; Shape of Array2... &quot;,y.shape) print(&quot; Shape of Array3... &quot;,z.shape) # To generate a pseudo Vandermonde matrix of the Legendre polynomial with x, y, z sample points, use the legendre.legvander3d() method in Python Numpy x_deg, y_deg, z_deg = 2, 3, 4 print(&quot; Result... &quot;,L.legvander3d(x,y,z, [x_deg, y_deg, z_deg]))</pre><h2>Output</h2><pre class="result notranslate">Array1... &nbsp; &nbsp;[1 2] Array2... &nbsp; &nbsp;[3 4] Array3... &nbsp; &nbsp;[5 6] Array1 datatype... int64 Array2 datatype... int64 Array3 datatype... int64 Dimensions of Array1... 1 Dimensions of Array2... 1 Dimensions of Array3... 1 Shape of Array1... (2,) Shape of Array2... (2,) Shape of Array3... (2,) Result... [[1.00000000e+00 5.00000000e+00 3.70000000e+01 3.05000000e+02 2.64100000e+03 3.00000000e+00 1.50000000e+01 1.11000000e+02 9.15000000e+02 7.92300000e+03 1.30000000e+01 6.50000000e+01 4.81000000e+02 3.96500000e+03 3.43330000e+04 6.30000000e+01 3.15000000e+02 2.33100000e+03 1.92150000e+04 1.66383000e+05 1.00000000e+00 5.00000000e+00 3.70000000e+01 3.05000000e+02 2.64100000e+03 3.00000000e+00 1.50000000e+01 1.11000000e+02 9.15000000e+02 7.92300000e+03 1.30000000e+01 6.50000000e+01 4.81000000e+02 3.96500000e+03 3.43330000e+04 6.30000000e+01 3.15000000e+02 2.33100000e+03 1.92150000e+04 1.66383000e+05 1.00000000e+00 5.00000000e+00 3.70000000e+01 3.05000000e+02 2.64100000e+03 3.00000000e+00 1.50000000e+01 1.11000000e+02 9.15000000e+02 7.92300000e+03 1.30000000e+01 6.50000000e+01 4.81000000e+02 3.96500000e+03 3.43330000e+04 6.30000000e+01 3.15000000e+02 2.33100000e+03 1.92150000e+04 1.66383000e+05] [1.00000000e+00 6.00000000e+00 5.35000000e+01 5.31000000e+02 5.53537500e+03 4.00000000e+00 2.40000000e+01 2.14000000e+02 2.12400000e+03 2.21415000e+04 2.35000000e+01 1.41000000e+02 1.25725000e+03 1.24785000e+04 1.30081312e+05 1.54000000e+02 9.24000000e+02 8.23900000e+03 8.17740000e+04 8.52447750e+05 2.00000000e+00 1.20000000e+01 1.07000000e+02 1.06200000e+03 1.10707500e+04 8.00000000e+00 4.80000000e+01 4.28000000e+02 4.24800000e+03 4.42830000e+04 4.70000000e+01 2.82000000e+02 2.51450000e+03 2.49570000e+04 2.60162625e+05 3.08000000e+02 1.84800000e+03 1.64780000e+04 1.63548000e+05 1.70489550e+06 5.50000000e+00 3.30000000e+01 2.94250000e+02 2.92050000e+03 3.04445625e+04 2.20000000e+01 1.32000000e+02 1.17700000e+03 1.16820000e+04 1.21778250e+05 1.29250000e+02 7.75500000e+02 6.91487500e+03 6.86317500e+04 7.15447219e+05 8.47000000e+02 5.08200000e+03 4.53145000e+04 4.49757000e+05 4.68846262e+06]]</pre>
raja
Updated on 09-Mar-2022 06:51:06

Advertisements