Linear Algebra and the C Language/a0du
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as : c00a.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
void fun(int r,int c)
{
double **A = r_mR( i_mR(r,c),9.);
double **A_T = transpose_mR(A, i_mR(c,r));
double **S = svds_mR(A_T, i_mR(r,C1));
double **U = svd_U_Cn_mR(A, i_mR(r,r));
double **V = svd_V_Cn_mR(A, i_mR(c,c));
clrscrn();
printf(" Copy/Paste into the octave windows \n\n\n");
p_Octave_mR(A,"A",P2);
printf(" [U, S, V] =svd (A,10)\n\n\n");
stop();
clrscrn();
printf(" U :");
p_mR(U,S5,P5,C10);
printf(" S :");
p_mR(S,S5,P5,C10);
printf(" V:");
p_mR(V,S5,P5,C10);
f_mR(A);
f_mR(A_T);
f_mR(S);
f_mR(U);
f_mR(V);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
int i;
do
{
i = rp_I(R3)+R1;
fun(i,i+C3);
} while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Screen output example:
Copy/Paste into the octave windows
A=[
+6.00,-1.00,-4.00,-7.00,-6.00,+3.00,-3.00;
-8.00,+6.00,+6.00,-2.00,-6.00,-5.00,+3.00;
+1.00,+5.00,-8.00,+5.00,+4.00,-4.00,-3.00;
+5.00,+2.00,-9.00,-6.00,+1.00,-6.00,-6.00]
[U, S, V] =svd (A,10)
Press return to continue.
U :
+0.37689 +0.69249 +0.20960 +0.57834
-0.49239 -0.09377 +0.85656 +0.12272
+0.37992 -0.71337 +0.05633 +0.58617
+0.68641 -0.05265 +0.46818 -0.55396
S :
+19.41205
+13.61295
+12.61236
+4.44843
V:
-0.51579 -0.28858 -0.25353 -0.06848 +0.67372 -0.00000 +0.00000
+0.00303 +0.36195 +0.48744 -0.44530 +0.00000 +0.60229 -0.00000
+0.70467 -0.20923 -0.02881 +0.28791 +0.41039 +0.14578 -0.41589
+0.19948 +0.58113 -0.45256 -0.44079 +0.35254 -0.39662 -0.22749
-0.14935 +0.47737 -0.45221 +0.54303 -0.23401 +0.49583 +0.10232
+0.10537 -0.41987 -0.53031 -0.47219 -0.44569 +0.46135 -0.00615
+0.40522 -0.00714 -0.08224 -0.04460 +0.00000 +0.00000 +0.87452
Press return to continue
Press X return to stop