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[
"strategy"] =
"linesearch"
72 opts[
"abstol"] = 1e-14
76 opts[
"constraints"] = [2,-2]
81 x_ = s([1,-1], params_)
82 print(
"Solution = ", x_)
86 x = [sqrt(4.0/3*sigma_/alpha_),-0.5*pi]
87 print(
"Reference solution = ", x)
91 residual = f(x_, params_)
92 print(
"residual = ", residual)
95 assert(abs(x_[i]-x[i])<1e-6)