@@ -596,15 +596,15 @@ <h1>Singular value decomposition (Shanti Rao)</h1>
596
596
< h1 > Sparse linear algebra</ h1 >
597
597
Sparse linear algebra is available in the sparse module:
598
598
< pre >
599
- > sparse.identity (3)
599
+ > numeric.sidentity (3)
600
600
[[1],
601
601
[ ,1],
602
602
[ , ,1]]
603
- > sparse.transpose ([[1],[2,3],[4,5,6]])
603
+ > numeric.stranspose ([[1],[2,3],[4,5,6]])
604
604
[[1,2,4],
605
605
[ ,3,5],
606
606
[ , ,6]]
607
- > A = [[2,-1],[-1,2,-1],[,-1,2]]; lup = sparse.LUP (A)
607
+ > A = [[2,-1],[-1,2,-1],[,-1,2]]; lup = numeric.sLUP (A)
608
608
{L: [[ 1],
609
609
[-0.5, 1],
610
610
[ ,-0.6667, 1]],
@@ -613,36 +613,36 @@ <h1>Sparse linear algebra</h1>
613
613
[ , , 1.333]],
614
614
P: [0,1,2],
615
615
Pinv: [0,1,2]}
616
- > sparse.dot (lup.L,lup.U)
616
+ > numeric.sdot (lup.L,lup.U)
617
617
[[ 2, -1],
618
618
[ -1, 2, -1],
619
619
[ , -1, 2]]
620
- > x = [3,1,7]; b = sparse.dot (A,x);
620
+ > x = [3,1,7]; b = numeric.sdot (A,x);
621
621
[5,-8,13]
622
- > sparse.LUPsolve (lup,b)
622
+ > numeric.sLUPsolve (lup,b)
623
623
[3,1,7]
624
624
</ pre >
625
625
626
626
<!--
627
627
Some more tests.
628
628
<pre>
629
- > sparse.dot ([1,2,3],[,4,5])
629
+ > numeric.sdot ([1,2,3],[,4,5])
630
630
23
631
- > sparse.dot ([1, ,3],[[4,5,],[,6,7],[1,,8]])
631
+ > numeric.sdot ([1, ,3],[[4,5,],[,6,7],[1,,8]])
632
632
[7,5,24]
633
- > sparse.dot ([[3,1],[4,5,9],[,3,2]],[7,3])
633
+ > numeric.sdot ([[3,1],[4,5,9],[,3,2]],[7,3])
634
634
[24,43,9]
635
635
</pre>
636
636
-->
637
637
638
- The < tt > sparse.scatter ()</ tt > and < tt > sparse.gather ()</ tt > functions can be used to convert between
638
+ The < tt > numeric.sscatter ()</ tt > and < tt > numeric.sgather ()</ tt > functions can be used to convert between
639
639
sparse matrices and the coordinate encoding:
640
640
< pre >
641
- > A = sparse.scatter ([[0,0,1,1,1,2,2],[0,1,0,1,2,1,2],[1,2,3,4,5,6,7]])
641
+ > A = numeric.sscatter ([[0,0,1,1,1,2,2],[0,1,0,1,2,1,2],[1,2,3,4,5,6,7]])
642
642
[[1,2],
643
643
[3,4,5],
644
644
[ ,6,7]]
645
- > sparse.gather (A)
645
+ > numeric.sgather (A)
646
646
[[0,0,1,1,1,2,2],
647
647
[0,1,0,1,2,1,2],
648
648
[1,2,3,4,5,6,7]]
@@ -656,35 +656,35 @@ <h1>Coordinate matrices</h1>
656
656
657
657
LU decomposition:
658
658
< pre >
659
- > lu = coord.LU ([[0,0,1,1,1,2,2],[0,1,0,1,2,1,2],[2,-1,-1,2,-1,-1,2]])
659
+ > lu = numeric.cLU ([[0,0,1,1,1,2,2],[0,1,0,1,2,1,2],[2,-1,-1,2,-1,-1,2]])
660
660
{U:[[ 0, 0, 1, 1, 2 ],
661
661
[ 0, 1, 1, 2, 2 ],
662
662
[ 2, -1, 1.5, -1, 1.333]],
663
663
L:[[ 0, 1, 1, 2, 2 ],
664
664
[ 0, 0, 1, 1, 2 ],
665
665
[ 1, -0.5, 1,-0.6667, 1 ]]}
666
- > coord.LUsolve (lu,[5,-8,13])
666
+ > numeric.cLUsolve (lu,[5,-8,13])
667
667
[3,1,7]
668
668
</ pre >
669
- Note that < tt > coord.LU ()</ tt > does not have any pivoting.
669
+ Note that < tt > numeric.cLU ()</ tt > does not have any pivoting.
670
670
671
671
< h1 > Solving PDEs</ h1 >
672
672
673
- The functions < tt > coord.grid ()</ tt > and < tt > coord.delsq ()</ tt > can be used to obtain a
673
+ The functions < tt > numeric.cgrid ()</ tt > and < tt > numeric.cdelsq ()</ tt > can be used to obtain a
674
674
numerical Laplacian for a domain.
675
675
676
676
< pre >
677
- > g = coord.grid (5)
677
+ > g = numeric.cgrid (5)
678
678
[[-1,-1,-1,-1,-1],
679
679
[-1, 0, 1, 2,-1],
680
680
[-1, 3, 4, 5,-1],
681
681
[-1, 6, 7, 8,-1],
682
682
[-1,-1,-1,-1,-1]]
683
- > coordL = coord.delsq (g)
683
+ > coordL = numeric.cdelsq (g)
684
684
[[ 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8],
685
685
[ 1, 3, 0, 0, 2, 4, 1, 1, 5, 2, 0, 4, 6, 3, 1, 3, 5, 7, 4, 2, 4, 8, 5, 3, 7, 6, 4, 6, 8, 7, 5, 7, 8],
686
686
[-1,-1, 4,-1,-1,-1, 4,-1,-1, 4,-1,-1,-1, 4,-1,-1,-1,-1, 4,-1,-1,-1, 4,-1,-1, 4,-1,-1,-1, 4,-1,-1, 4]]
687
- > L = sparse.scatter (coordL); // Just to see what it looks like
687
+ > L = numeric.sscatter (coordL); // Just to see what it looks like
688
688
[[ 4, -1, , -1],
689
689
[ -1, 4, -1, , -1],
690
690
[ , -1, 4, , , -1],
@@ -694,9 +694,9 @@ <h1>Solving PDEs</h1>
694
694
[ , , , -1, , , 4, -1],
695
695
[ , , , , -1, , -1, 4, -1],
696
696
[ , , , , , -1, , -1, 4]]
697
- > lu = coord.LU (coordL); x = coord.LUsolve (lu,[1,1,1,1,1,1,1,1,1]);
697
+ > lu = numeric.cLU (coordL); x = numeric.cLUsolve (lu,[1,1,1,1,1,1,1,1,1]);
698
698
[0.6875,0.875,0.6875,0.875,1.125,0.875,0.6875,0.875,0.6875]
699
- > coord.dotMV (coordL,x)
699
+ > numeric.cdotMV (coordL,x)
700
700
[1,1,1,1,1,1,1,1,1]
701
701
> G = numeric.rep([5,5],0); for(i=0;i< 5 ;i++) for(j =0;j < 5 ;j++) if(g[i][j] > =0) G[i][j] = x[g[i][j]]; G
702
702
[[ 0 , 0 , 0 , 0 , 0 ],
@@ -710,14 +710,14 @@ <h1>Solving PDEs</h1>
710
710
711
711
You can also work on an L-shaped or arbitrary-shape domain:
712
712
< pre >
713
- > coord.grid (6,'L')
713
+ > numeric.cgrid (6,'L')
714
714
[[-1,-1,-1,-1,-1,-1],
715
715
[-1, 0, 1,-1,-1,-1],
716
716
[-1, 2, 3,-1,-1,-1],
717
717
[-1, 4, 5, 6, 7,-1],
718
718
[-1, 8, 9,10,11,-1],
719
719
[-1,-1,-1,-1,-1,-1]]
720
- > coord.grid (5,function(i,j) { return i!==2 || j!==2; })
720
+ > numeric.cgrid (5,function(i,j) { return i!==2 || j!==2; })
721
721
[[-1,-1,-1,-1,-1],
722
722
[-1, 0, 1, 2,-1],
723
723
[-1, 3,-1, 4,-1],
0 commit comments