I am seeking to plot the solutions that HomotopyContinuation.jl returns in case of multiple solution branches.
Same question reformulated: I am seeking to reproduce BifurcationKit: Duffing Equation: Time-Harmonic: Single Harmonic with HomotopyContinuation.jl
Below are two MWEs. The first is linear and works fine. The second is non-linear and fails (likely to my erroneous post-processing). The correct solution is provided by HarmonicBalance.jl by redefining the plot function (details sadly missing).
First MWE
1/ Define linear and non-linear system
@var A B p
m=1; freq = .5; om0=2*π*freq; ga=0.1; stiffnlin=1e-3; F0 = 1.;
Flin = System(
[
m*(om0^2-p[1]^2)*A + ga*p[1]*B,
-ga*p[1]*A + m*(om0^2-p[1]^2)*B - F0,
];
parameters = [p]
)
F = System(
[
m*(om0^2-p[1]^2)*A + ga*p[1]*B + stiffnlin*.75*(A^3 + A*B^2),
-ga*p[1]*A + m*(om0^2-p[1]^2)*B + stiffnlin*.75*(B^3 + A^2*B) - F0,
];
parameters = [p]
)
2/ Solve and plot the linear system
# solve system for multiple values of driving frequency using start_parameters and target_parameters
omdvec = Vector(0:0.01:10.)
Avec = zeros(length(omdvec))
Bvec = zeros(length(omdvec))
for (i,p) in enumerate(omdvec)
# Compute all solutions for F_p
results = solve(Flin, target_parameters = [p])
Avec[i] = real_solutions(results)[1][1]
Bvec[i] = real_solutions(results)[1][2]
end
plot(omdvec,Avec)
plot!(omdvec,Bvec)
plot!(omdvec,sqrt.(Avec.^2+Bvec.^2))
Second MWE
3/ Solve and plot the non-linear system
Replace “Flin” by “F” in solve function above.
PS (for what it is worth): The page How to solve a system of polynomial equations contains a tiny typo as realsolutions (without hyphen) should be real_solutions (with hyphen) instead.