def extend_solutions(sols): """ To each solution in sols, adds L1 and L2 with values 1, and zz2 and zz3 with values zero. """ from phcpy.solutions import make_solution, coordinates result = [] for sol in sols: (vars, vals) = coordinates(sol) vars = vars + ['L1', 'L2', 'zz2', 'zz3'] vals = vals + [1, 1, 0, 0] extsol = make_solution(vars, vals) result.append(extsol) return result
def solution_plane(rows, cols, sol): """ Returns a sympy matrix with as many rows as the value of rows and with as many columns as the value of columns, using the string represention of a solution in sol. """ from phcpy.solutions import coordinates result = zeros((rows, cols), dtype=complex) for k in range(cols): result[k][k] = 1 (vars, vals) = coordinates(sol) for (name, value) in zip(vars, vals): i, j = indices(name) result[i - 1][j - 1] = value return result
def solution_plane(rows, cols, sol): """ Returns a sympy matrix with as many rows as the value of rows and with as many columns as the value of columns, using the string represention of a solution in sol. """ from phcpy.solutions import coordinates result = zeros((rows, cols), dtype=complex) for k in range(cols): result[k][k] = 1 (vars, vals) = coordinates(sol) for (name, value) in zip(vars, vals): i, j = indices(name) result[i-1][j-1] = value return result
def plot(self): """ Plots a coordinate of the list of solutions. """ from phcpy.solutions import coordinates dim = self.dim self.cnv.create_line(0, dim / 2, dim, dim / 2) # x coordinate axis self.cnv.create_line(dim / 2, 0, dim / 2, dim) # y coordinate axis (realmin, realmax, imagmin, imagmax) = windowsize(self.sols, self.idx) dimreal = max(abs(realmin), abs(realmax)) dimimag = max(abs(imagmin), abs(imagmax)) factor = dim / 2 - 10 # the origin is at (dim/2, dim/2) for sol in self.sols: (names, values) = coordinates(sol) val = values[self.idx] xpt = dim / 2 + (val.real / dimreal) * factor ypt = dim / 2 + (val.imag / dimimag) * factor self.cnv.create_oval(xpt-3, ypt-3, \ xpt+3, ypt+3, fill='red')
def plot(self): """ Plots a coordinate of the list of solutions. """ from phcpy.solutions import coordinates dim = self.dim self.cnv.create_line(0, dim/2, dim, dim/2) # x coordinate axis self.cnv.create_line(dim/2, 0, dim/2, dim) # y coordinate axis (realmin, realmax, imagmin, imagmax) = windowsize(self.sols, self.idx) dimreal = max(abs(realmin), abs(realmax)) dimimag = max(abs(imagmin), abs(imagmax)) factor = dim/2 - 10 # the origin is at (dim/2, dim/2) for sol in self.sols: (names, values) = coordinates(sol) val = values[self.idx] xpt = dim/2 + (val.real/dimreal)*factor ypt = dim/2 + (val.imag/dimimag)*factor self.cnv.create_oval(xpt-3, ypt-3, \ xpt+3, ypt+3, fill='red')
def windowsize(sols, idx): """ Returns the minimal and maximal value of the real and imaginary parts of the coordinate with index idx of the list of solutions in sols, as a tuple of 4 values: (realmin, realmax, imagmin, imagmax). """ from phcpy.solutions import coordinates (realmin, realmax, imagmin, imagmax) = (0, 0, 0, 0) for sol in sols: (names, values) = coordinates(sol) val = values[idx] if val.real < realmin: realmin = val.real if val.real > realmax: realmax = val.real if val.imag < imagmin: imagmin = val.imag if val.imag > imagmax: imagmax = val.imag return (realmin, realmax, imagmin, imagmax)
def special_solutions(pols, slope): """ Given in pols the polynomials for the line intersecting a circle for a general slope s, solves the problem for a special numerical value for s, given in the slope. The value of the slope is added as last coordinate to each solution. """ from phcpy.solver import solve from phcpy.solutions import make_solution, coordinates special = [] for pol in pols: rpl = pol.replace('s', '(' + str(slope) + ')') special.append(rpl) sols = solve(special, silent=True) result = [] for sol in sols: (vars, vals) = coordinates(sol) vars.append('s') vals.append(slope) extsol = make_solution(vars, vals) result.append(extsol) return result