Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
|
|
@ -0,0 +1,64 @@
|
|||
#include once "g:\FreeBASIC\inc\gsl\gsl_linalg.bi"
|
||||
|
||||
Sub MatrixPrint(r As Integer, c As Integer, m() As Double)
|
||||
For i As Integer = 0 To r - 1
|
||||
Print "|";
|
||||
For j As Integer = 0 To c - 1
|
||||
Print Using "#############.########## "; m(i * c + j);
|
||||
Next j
|
||||
Print Chr(8); "|"
|
||||
Next i
|
||||
Print
|
||||
End Sub
|
||||
|
||||
Dim As Integer r = 2
|
||||
Dim As Integer c = 2
|
||||
Dim As Integer l = r * c
|
||||
|
||||
Dim As Double a(l - 1)
|
||||
a(0) = 3: a(1) = 0: a(2) = 4: a(3) = 5
|
||||
Dim As Double v(l - 1)
|
||||
v(0) = 0: v(1) = 0: v(2) = 0: v(3) = 0
|
||||
Dim As Double s(c - 1)
|
||||
s(0) = 0: s(1) = 0
|
||||
|
||||
Dim As gsl_matrix Ptr a_mat = gsl_matrix_alloc(r, c)
|
||||
Dim As gsl_matrix Ptr v_mat = gsl_matrix_alloc(c, c)
|
||||
Dim As gsl_vector Ptr s_vec = gsl_vector_alloc(c)
|
||||
Dim As gsl_vector Ptr work = gsl_vector_alloc(c)
|
||||
|
||||
Dim As Integer i, j
|
||||
For i = 0 To r - 1
|
||||
For j = 0 To c - 1
|
||||
gsl_matrix_set(a_mat, i, j, a(i * c + j))
|
||||
Next j
|
||||
Next i
|
||||
|
||||
gsl_linalg_SV_decomp(a_mat, v_mat, s_vec, work)
|
||||
|
||||
For i = 0 To r - 1
|
||||
For j = 0 To c - 1
|
||||
a(i * c + j) = gsl_matrix_get(a_mat, i, j)
|
||||
v(i * c + j) = gsl_matrix_get(v_mat, i, j)
|
||||
Next j
|
||||
Next i
|
||||
|
||||
For i = 0 To c - 1
|
||||
s(i) = gsl_vector_get(s_vec, i)
|
||||
Next i
|
||||
|
||||
Print "U:"
|
||||
MatrixPrint(r, c, a())
|
||||
|
||||
Print "S:"
|
||||
MatrixPrint(1, c, s())
|
||||
|
||||
Print "VT:"
|
||||
MatrixPrint(r, c, v())
|
||||
|
||||
gsl_matrix_free(a_mat)
|
||||
gsl_matrix_free(v_mat)
|
||||
gsl_vector_free(s_vec)
|
||||
gsl_vector_free(work)
|
||||
|
||||
Sleep
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# 20240920 Perl programming solution
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Math::GSL::Matrix;
|
||||
use Math::GSL::Linalg qw/gsl_linalg_SV_decomp/;
|
||||
|
||||
my $M = Math::GSL::Matrix->new(2, 2);
|
||||
$M->set_elem(0,0,3)->set_elem(0,1,0)->set_elem(1,0,4)->set_elem(1,1,5);
|
||||
|
||||
my $V = Math::GSL::Matrix->new(2, 2);
|
||||
my ($S, $work) = ( Math::GSL::Vector->new(2), Math::GSL::Vector->new(2) );
|
||||
|
||||
gsl_linalg_SV_decomp($M->raw, $V->raw, $S->raw, $work->raw);
|
||||
|
||||
print "U factor:\n";
|
||||
for my $i (0 .. $M->rows - 1) { print join(", ",$M->row($i)->as_list),"\n" }
|
||||
print "singular values:\n";
|
||||
print join(", ", map { sprintf("%.10g", $_) } $S->as_list), "\n";
|
||||
print "Vt factor:\n";
|
||||
for my $i (0 .. $V->rows - 1) { print join(", ",$V->row($i)->as_list),"\n" }
|
||||
Loading…
Add table
Add a link
Reference in a new issue