示例#1
0
void real_inverse(const Matrix& A, Matrix& invA) {
	int n = (A.nb_rows());

	Matrix LU(n,n);
	int* p= new int[n];

	try {
		real_LU(A, LU, p);

		Vector b(n,0.0);
		Vector x(n);

		for (int i=0; i<n; i++) {
			b[i]=1;
			real_LU_solve(LU, p, b, x);
			invA.set_col(i, x);
			b[i]=0;
		}
	}
	catch(SingularMatrixException& e) {
		delete[] p;
		throw e;
	}
	delete[] p;
}
BoolInterval PdcHansenFeasibility::test(const IntervalVector& box) {

	int n=f.nb_var();
	int m=f.image_dim();
	IntervalVector mid=box.mid();

	/* Determine the "most influencing" variable thanks to
	 * the pivoting of Gauss elimination */
	// ==============================================================
	Matrix A=f.jacobian(mid).mid();
	Matrix LU(m,n);
	int pr[m];
	int pc[n]; // the interesting output: the variables permutation

	try {
		real_LU(A,LU,pr,pc);
	} catch(SingularMatrixException&) {
		// means in particular that we could not extract an
		// invertible m*m submatrix
		return MAYBE;
	}
	// ==============================================================


	PartialFnc pf(f,pc,m,mid);

	IntervalVector box2(pf.chop(box));
	IntervalVector savebox(box2);

	if (inflating) {
		if (inflating_newton(pf,box2)) {
			_solution = pf.extend(box2);
			return YES;
		}
	}
	else {
		try {
			newton(pf,box2);
			if (box2.is_strict_subset(savebox)) {
				_solution = pf.extend(box2);
				return YES;
			}
		} catch (EmptyBoxException& ) {	}
	}

	_solution.set_empty();
	return MAYBE;

}
示例#3
0
VarSet get_newton_vars(const Fnc& f, const Vector& pt, const VarSet& forced_params) {
	int n=f.nb_var();
	int m=f.image_dim();

	if (forced_params.nb_param==n-m)
		// no need to find parameters: they are given
		return VarSet(forced_params);

	Matrix A=f.jacobian(pt).mid();
	Matrix LU(m,n);
	int *pr = new int[m];
	int *pc = new int[n]; // the interesting output: the variables permutation

	// To force the Gauss elimination not to choose
	// the "forced" parameters, we fill their respective
	// column with zeros
	for (int i=0; i<n; i++) {
		if (!forced_params.is_var[i]) {
			A.set_col(i,Vector::zeros(m));
		}
	}

	try {
		real_LU(A,LU,pr,pc);
	} catch(SingularMatrixException& e) {
		// means in particular that we could not extract an
		// invertible m*m submatrix
		delete [] pr;
		delete [] pc;
		throw e;
	}
	// ==============================================================

	BitSet _vars=BitSet::empty(n);

	for (int i=0; i<m; i++) {
		_vars.add(pc[i]);
	}

	for (int j=0; j<n; j++) {
		assert(!(!forced_params.is_var[j] && _vars[j]));
	}

	delete [] pr;
	delete [] pc;
	return VarSet(f.nb_var(),_vars);
}
BoolInterval PdcHansenFeasibility::test(const IntervalVector& box) {

	int n=f.nb_var();
	int m=f.image_dim();
	IntervalVector mid=box.mid();

	/* Determine the "most influencing" variable thanks to
	 * the pivoting of Gauss elimination */
	// ==============================================================
	Matrix A=f.jacobian(mid).mid();
	Matrix LU(m,n);
	int *pr = new int[m];
	int *pc = new int[n]; // the interesting output: the variables permutation
	BoolInterval res=MAYBE;

	try {
		real_LU(A,LU,pr,pc);
	} catch(SingularMatrixException&) {
		// means in particular that we could not extract an
		// invertible m*m submatrix
		delete [] pr;
		delete [] pc;
		return MAYBE;
	}
	// ==============================================================


//	PartialFnc pf(f,pc,m,mid);

	BitSet _vars=BitSet::empty(n);
	for (int i=0; i<m; i++) _vars.add(pc[i]);
	VarSet vars(f.nb_var(),_vars);

	IntervalVector box2(box);

	// fix parameters to their midpoint
	vars.set_param_box(box2, vars.param_box(box).mid());

	IntervalVector savebox(box2);

	if (inflating) {
		if (inflating_newton(f,vars,box2)) {
			_solution = box2;
			res = YES;
		} else {
			_solution.set_empty();
		}
	}
	else {
		// ****** TODO **********
			newton(f,vars,box2);

			if (box2.is_empty()) {
				_solution.set_empty();
			} else if (box2.is_strict_subset(savebox)) {
				_solution = box2;
				res = YES;
			}
	}

	delete [] pr;
	delete [] pc;
	return res;

}