test_Matrix_solve.praat 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # test_Matrix_solve.praat
  2. # djmw 20031020, 20171211,20180918
  3. appendInfoLine: "test_Matrix_solve.praat"
  4. procedure matrix_solve: .ncol
  5. for .i to 4
  6. .nrow = .i * .ncol
  7. appendInfoLine: tab$, "nrow = ", .nrow, ", ncol = ", .ncol
  8. .eps = .nrow * 1e-7
  9. .m = Create simple Matrix: string$(.i), .nrow, .ncol+1, "0.0"
  10. Formula: "if (col <= ((row - 1) mod .ncol)+1) then 1 else 0 fi"
  11. Formula: "if col = 1 then self + ((row-1) div .ncol) else self fi"
  12. Formula: "if col = .ncol+1 then (row-1) mod .ncol + 1 + ((row-1) div .ncol) else self fi"
  13. .ms = Solve equation: 0
  14. # solution must be all ones.
  15. for .j to .ncol
  16. .s = Get value in cell: 1, .j
  17. assert abs(.s - 1.0) < .eps ; nowsr = '.nrow' ncols = '.ncol'
  18. endfor
  19. removeObject: .m, .ms
  20. endfor
  21. endproc
  22. # test for several dimensions
  23. @solve2by3
  24. @matrix_solve: 1
  25. @matrix_solve: 10
  26. @matrix_solve: 100
  27. procedure solve2by3
  28. .nrow = 2
  29. .ncol = 3
  30. appendInfoLine: tab$, "nrow = ", .nrow, ", ncol = ", .ncol
  31. .m = Create simple Matrix: "2x3", .nrow, .ncol, "0"
  32. Set value: 1, 1, 1
  33. Set value: 1, 2, 2
  34. Set value: 1, 3, 3
  35. Set value: 2, 1, 3
  36. Set value: 2, 2, 5
  37. Set value: 2, 3, 8
  38. .eps = 1.2e-7
  39. .solution = Solve equation: .eps
  40. .s1 = Get value in cell: 1, 1
  41. .s2 = Get value in cell: 1, 2
  42. assert .s1-.eps < 1 and .s1+.eps > 1; '.s1'
  43. assert .s2-.eps < 1 and .s2+.eps > 1; '.s2'
  44. removeObject: .m, .solution
  45. endproc
  46. appendInfoLine: "test_Matrix_solve.praat OK"