Exemplo n.º 1
0
// Compute rational approximation backward
func rationalBackward(z, delta *cmat.FloatMatrix, start, end int) (float64, float64) {
	var val, dval float64
	val, dval = 0.0, 0.0
	for i := end - 1; i >= start; i-- {
		dj := delta.GetAtUnsafe(i)
		zj := z.GetAtUnsafe(i)
		tval := zj / dj
		val = val + zj*tval
		dval = dval + tval*tval
	}
	return val, dval
}
Exemplo n.º 2
0
/*
 * Bidiagonal bottom to top implicit zero shift QL sweep
 */
func bdQLzero(D, E, Cr, Sr, Cl, Sl *cmat.FloatMatrix, saves bool) int {
	var d1, e1, d2, cosr, sinr, cosl, sinl, r float64
	N := D.Len()

	d1 = D.GetAtUnsafe(N - 1)
	cosr = 1.0
	cosl = 1.0
	for k := N - 1; k > 0; k-- {
		e1 = E.GetAtUnsafe(k - 1)
		d2 = D.GetAtUnsafe(k - 1)
		cosr, sinr, r = ComputeGivens(d1*cosr, e1)
		if k < N-1 {
			E.SetAtUnsafe(k, sinl*r)
		}
		cosl, sinl, r = ComputeGivens(cosl*r, sinr*d2)
		D.SetAtUnsafe(k, r)
		d1 = d2
		if saves {
			Cr.SetAtUnsafe(k-1, cosr)
			Sr.SetAtUnsafe(k-1, -sinr)
			Cl.SetAtUnsafe(k-1, cosl)
			Sl.SetAtUnsafe(k-1, -sinl)
		}
	}
	d2 = cosr * D.GetAtUnsafe(0)
	D.SetAtUnsafe(0, d2*cosl)
	E.SetAtUnsafe(0, d2*sinl)
	return N - 1
}
Exemplo n.º 3
0
/*
 * Bidiagonal bottom to top implicit QL sweep
 */
func bdQLsweep(D, E, Cr, Sr, Cl, Sl *cmat.FloatMatrix, f0, g0 float64, saves bool) int {
	var d1, e1, d2, e2, f, g, cosr, sinr, cosl, sinl, r float64
	N := D.Len()

	d1 = D.GetAtUnsafe(N - 1)
	e1 = E.GetAtUnsafe(N - 2)
	f = f0
	g = g0
	for k := N - 1; k > 0; k-- {
		d2 = D.GetAtUnsafe(k - 1)
		cosr, sinr, r = ComputeGivens(f, g)
		if k < N-1 {
			E.SetAt(k, r)
		}
		f, e1 = RotateGivens(d1, e1, cosr, sinr)
		g, d2 = RotateGivens(0.0, d2, cosr, sinr)
		cosl, sinl, r = ComputeGivens(f, g)
		d1 = r
		f, d2 = RotateGivens(e1, d2, cosl, sinl)
		if k > 1 {
			e2 = E.GetAtUnsafe(k - 2)
			g, e2 = RotateGivens(0.0, e2, cosl, sinl)
			E.SetAtUnsafe(k-2, e2)
		}
		D.SetAtUnsafe(k, d1)
		//D.SetAtUnsafe(k-1, d2)
		d1 = d2
		e1 = e2
		if saves {
			Cr.SetAtUnsafe(k-1, cosr)
			Sr.SetAtUnsafe(k-1, -sinr)
			Cl.SetAtUnsafe(k-1, cosl)
			Sl.SetAtUnsafe(k-1, -sinl)
		}
	}
	D.SetAtUnsafe(0, d1)
	E.SetAt(0, f)
	return N - 1
}
Exemplo n.º 4
0
/*
 * Tridiagonal bottom to top implicit QL sweep
 */
func trdQLsweep(D, E, Cr, Sr *cmat.FloatMatrix, f0, g0 float64, saves bool) int {
	var d0, e0, e1, d1, e0r, e0c, w0, f, g, cosr, sinr, r float64
	N := D.Len()

	d0 = D.GetAtUnsafe(N - 1)
	e0 = E.GetAtUnsafe(N - 2)
	f = f0
	g = g0
	for k := N - 1; k > 0; k-- {
		d1 = D.GetAtUnsafe(k - 1)
		cosr, sinr, r = ComputeGivens(f, g)
		if k < N-1 {
			E.SetAtUnsafe(k, r)
		}
		d0, e0c = RotateGivens(d0, e0, cosr, sinr)
		e0r, d1 = RotateGivens(e0, d1, cosr, sinr)
		d0, e0r = RotateGivens(d0, e0r, cosr, sinr)
		e0c, d1 = RotateGivens(e0c, d1, cosr, sinr)
		// here: e0c == e0r
		if k > 1 {
			e1 = E.GetAtUnsafe(k - 2)
			w0, e1 = RotateGivens(0.0, e1, cosr, sinr)
		}
		D.SetAtUnsafe(k, d0)
		d0 = d1
		e0 = e1
		f = e0r
		g = w0
		if saves {
			Cr.SetAtUnsafe(k-1, cosr)
			Sr.SetAtUnsafe(k-1, -sinr)
		}
	}
	D.SetAtUnsafe(0, d0)
	E.SetAtUnsafe(0, e0c)
	return N - 1
}