File: solve.asy

package info (click to toggle)
texlive-bin 2012.20120628-4
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 240,500 kB
  • sloc: ansic: 890,229; cpp: 469,960; perl: 73,550; sh: 47,106; makefile: 16,643; python: 8,657; lisp: 6,684; xml: 3,926; lex: 3,791; java: 3,569; pascal: 3,569; yacc: 2,460; exp: 2,031; ruby: 1,415; objc: 1,362; tcl: 631; sed: 522; asm: 435; csh: 46; awk: 30
file content (35 lines) | stat: -rw-r--r-- 966 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import TestLib;

StartTest("solve");
real[][] a=new real[][] {{1,1,1},{1,2,2},{0,0,1}};
real[][] b=new real[][] {{3,9},{5,11},{1,3}};
real[][] x=new real[][] {{1,7},{1,-1,},{1,3}};
real[][] c=solve(a,b);
for(int i=0; i < c.length; ++i)
  for(int j=0; j < c[i].length; ++j)
    assert(close(c[i][j],x[i][j]));

real[][] a={{1,-2,3,0},{4,-5,6,2},{-7,-8,10,5},{1,50,1,-2}};
real[] b={7,19,33,3};
real[] x=solve(a,b);
real[] c=a*x;
for(int i=0; i < c.length; ++i)
  assert(close(c[i],b[i]));
EndTest();

StartTest("inverse");
real[][] a=new real[][] {{1,1,1},{1,2,2},{0,0,1}};
real[][] ainverse=new real[][] {{2,-1,0},{-1,1,-1},{0,0,1}};
real[][] d=inverse(a);
real[][] l=d*a;
real[][] r=a*d;
real[][] I=identity(a.length);
for(int i=0; i < d.length; ++i) {
  for(int j=0; j < d[i].length; ++j) {
    assert(close(d[i][j],ainverse[i][j]));
    assert(I[i][j] == (i == j ? 1 : 0));
    assert(close(l[i][j],I[i][j]));
    assert(close(r[i][j],I[i][j]));
  }
}
EndTest();