P is for Practical | |
PerlMonks |
47. Construct the Cauchy matrixby Ea (Chaplain) |
on May 18, 2018 at 15:32 UTC ( [id://1214858]=note: print w/replies, xml ) | Need Help?? |
PM is a good choice for this project. It's got the discussion of the best solution(s) to the question. Hopefully someone jumps in an offers a better solution than mine. It feels a little ugly explicitly stating the indices.
Given two arrays, X and Y, construct the Cauchy matrix C (Cij =1/(xi - yj))First, what's a Cauchy matrix? Ahh, this question is just how to construct a matrix from 2 arrays, where no elements from one array are in the other. Just create a sequence of number for the first array and then make the second array 0.5 more than the first array to get the inputs. Here's a brute force method.I like the PDL::NiceSlice for indexing. It makes sense to me. I could have also created the matrix with my $C = outer($x, $y); or gotten the size of the arrays with $x->getdim(0) and if I grokked threading rather than just skimming PDL::Threading, this might look way cooler. NB the ".=" in the assignment breaks the link between the matrix and the 2 arrays. It's important. That was just the Cauchy matrix. Some people want the Cauchy determinant (as long as the 2 arrays are the same size). Easy! Just import PDL::MatrixOps
Sometimes I can think of 6 impossible LDAP attributes before breakfast. YAPC::Europe::2018 — Hmmm, need to talk to work about sending me.
In Section
Meditations
|
|