This example looks at a use of rootfinders
View output (PDF) | source (python)
- See also
CASADI_EXPORT Function rootfinder(const std::string &name, const std::string &solver, const SXDict &rfp, const Dict &opts=Dict())
45 alpha = SX.sym(
"alpha")
47 sigma = SX.sym(
"sigma")
48 params = [eps,mu,alpha,k,sigma]
53 gamma = SX.sym(
"gamma")
57 res0 = mu*a+1.0/2*k*a*sin(gamma)
58 res1 = -sigma * a + 3.0/4*alpha*a**3+k*a*cos(gamma)
65 params_ = [0.1,0.1,alpha_,k_,sigma_]
69 f=Function(
"f", [vertcat(a, gamma), vertcat(*params)], [vertcat(res0, res1)])
71 opts[
"nlpsol"] =
"ipopt"
72 opts[
"nlpsol_options"] = {
"ipopt.tol":1e-14}
77 x_ = s([1,-1], params_)
78 print(
"Solution = ", x_)
82 x = [sqrt(4.0/3*sigma_/alpha_),-0.5*pi]
83 print(
"Reference solution = ", x)
87 residual = f(x_, params_)
88 print(
"residual = ", residual)
91 assert(abs(x_[i]-x[i])<1e-6)