Let's say that I have a quartic equation of the form:
a0x^4+a1x^3+a2x^2+a3x+a4=0
I know I can use numpy
roots method to solve for a quartic equations, but I want the coefficients to change according to a rule, let's say that they depend on a parameter x
, which takes values 1,2,...,10.
For example we have the coefficients
a0=1, a1=3q^2, a2=4q, a3=sqrt(q), a4=q
and want to obtain the solutions, in 8 columns, four real parts and four imaginary parts for each value of q, as q is changing, form 1 to 10.
For example, for x=1,
import numpy as np
q=1
a0=1
a1=3*q^2
a2=4*q
a3=np.sqrt(q)
a4=q
coeff=[a0, a1, a2, a3, a4]
np.roots(coeff)
The output would be:
array([-0.39002422+1.84237253j, -0.39002422-1.84237253j,
-0.10997578+0.51949688j, -0.10997578-0.51949688j])
Is it possible to get the solutions, for all ranges of q, into a .csv
format, in 9 columns, the first one for the value of q and than for each solution, a column for the real and imaginary part?