# Issues with: Solving a polynomial equation with multiple variables

It's probably very simple but I'm completely new to Sage and could not find a definitive answer. So here's the problem. I have a polynomial equation like this:

v**6 + a(k)*v**4 + b(k)*v**2 + c(k) == 0


For simple forms of a(k), b(k), c(k) etc. solve works like a charm and gives me a solution v(k) very quickly. When a(k), b(k), c(k) become very complicated e.g.

b(k) = e + f/(1+g*k**2) + (1+(h*k**2)/(1+g*k**2))/(1+g*k**2)


solve function chokes for long time. In such situations I would like to revert to some numerical solution because my final goal is to get numerical values for v(k).

I'm in the very early stages of learning sage and python so have no idea about how to proceed. I have copied my existing code below for your reference. For the parameters Ca, Cak etc. given right now, solve works fine. When I start giving non-zero values of Cak: a(k), b(k), c(k) become complicated functions as described above and I start getting into trouble.

from sage.all import *
import numpy as np

v,k=var('v, k')

Ca=4.; Cs=sqrt(6.0); di=1; de=0.04; Cak=0.;

dx=0.05; L=12.8;

kmin=2*pi/L;
kmax=pi/dx;

def DDe(k):
return 1+k**2*de**2

def Cmk(k):
return sqrt((Ca**2/DDe(k))+Cs**2)

def f(v,k):
return v**6-((Cmk(k)**2)+(Cak**2/DDe(k))*(1+(k**2*di**2)/DDe(k)))*v**4\
+ (1/DDe(k))((Cmk(k)**2*Cak**2)+(Cs**2*Cak**2)*(1+(k**2*di**2)/DDe(k)))*v**2\
- Cs**2*Cak**4/(DDe(k)**2)

sol=solve(f(v,k) == 0, v)

for i in range(0,len(sol)):
print 'Solution ', i, ': '; show(sol[i])
#    plot(sol[i].rhs(),kmin,kmax)

show(plot(sol.rhs(),kmin,kmax)+plot(sol.rhs(),kmin,kmax)+\
plot(sol.rhs(),kmin,kmax)+plot(sol.rhs(),kmin,kmax))


Any help, pointers on how to proceed would be of great help.

EDIT

I just compared the output of the code with a similar code in Mathematica from which I'm trying to translate the code and found that the numbers in the simpler cases are wrong too. So it seems I'm doing more than a few things wrong. :(

Thanks!

edit retag close merge delete

Sort by » oldest newest most voted

For numerical solutions, I would suggest find_root or minimize. See the links for examples and usage.

more