Esempio n. 1
0
func show() {
	if len(os.Args) < 4 {
		fmt.Println("Not enough arguments: show <input> <range>")
		return
	}
	r, err := parseRange(os.Args[3])
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	m, err := matlib.Load(os.Args[2])
	if err != nil {
		fmt.Println("Failed to read matrix from", os.Args[2], err.Error())
		return
	}

	err = r.apply(m)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	for row := r.startRow; row < r.endRow; row++ {
		line := ""
		for col := r.startCol; col < r.endCol; col++ {
			val := m.Get(row, col)
			line = line + strconv.FormatFloat(val, 'E', 4, 64) + "\t"
		}
		fmt.Println(line)
	}
}
Esempio n. 2
0
func invert() {
	if len(os.Args) < 4 {
		fmt.Println("Not enough arguments: invert <input> <output>")
		return
	}
	m, err := matlib.Load(os.Args[2])
	if err != nil {
		fmt.Println("Failed to read matrix from", os.Args[2], err.Error())
		return
	}
	err = m.InvertInPlace()
	if err != nil {
		fmt.Println("Failed to invert matrix", os.Args[2], err.Error())
		return
	}
	err = matlib.Save(m, os.Args[3])
	if err != nil {
		fmt.Println("Failed to write inverse to", os.Args[3], err.Error())
	}
}