Mar-24-2022, 09:05 AM
(This post was last modified: Mar-24-2022, 12:10 PM by alexfrol86.)
I transfer a solved physics problem to python. Its task is to solve a system of differential equations with conditions (the Cauchy problem) in a cycle for different vectors of initial values (y0 in solve_ivp). After this, I have to define the optimal solution among these obtained - i.e. the one that satisfies the optimality condition.
What I am doing now: I applied basics conditions for variables and I have collected all possible variables' values for t0 - i.e. a set of values for each variable (these combinations are a set of y0 vectors that can be provided in solve_ivp, but these are many that aren't solution). Now, in order to form vectors y0 that will be provided to solve_ivp, I need to apply the condition that ht is equal to zero (this is the main condition of the problem) and to collect (in list format) only these combinations of elements that satisfy the condition. There are indeed combinations of elements that will ensure that ht is equal to zero (with a given accuracy).
I have the following difficulty: each set of variable' values is a list or an array and I have to iterate each variable through the elements i.e. through the values. Otherwise, the function try to accept lists or arrays instead of one value and this leads to an error. So I made this mistake with function definition.
My updated code is below, it seems to work, but takes a really long time.
What I am doing now: I applied basics conditions for variables and I have collected all possible variables' values for t0 - i.e. a set of values for each variable (these combinations are a set of y0 vectors that can be provided in solve_ivp, but these are many that aren't solution). Now, in order to form vectors y0 that will be provided to solve_ivp, I need to apply the condition that ht is equal to zero (this is the main condition of the problem) and to collect (in list format) only these combinations of elements that satisfy the condition. There are indeed combinations of elements that will ensure that ht is equal to zero (with a given accuracy).
I have the following difficulty: each set of variable' values is a list or an array and I have to iterate each variable through the elements i.e. through the values. Otherwise, the function try to accept lists or arrays instead of one value and this leads to an error. So I made this mistake with function definition.
My updated code is below, it seems to work, but takes a really long time.
def function_gam(et, y3, phb, kj, y7): ht = kj[0] * et * cos(y3) / sqrt(phb) + kj[1] * -et0 * sin(y3) / sqrt(phb) + y7 * sqrt(1 / phb) * et0 * sin(y3) + funct_labt(y3, kj[1], y7, kj[0]) * (sqrt(1 / phb) * (1 + et * cos(y3) * (1 + et * cos(y3)**2) / phb**2)) return ht for i in z30: # iteratation through values for variable z30 for o in zres: # iteratation through values for array zres which includes 2 interconnected variales. The values of the first are in zres[0], for the other - in zres[1] for l in z70: # iteratation through values for variable z70 ht0 = function_gam(et0, i, ph0b, o, l) if isclose(ht0, 0, abs_tol=1.0e-9): # only these combinations of variables values are collected that satisfy the condition ht == 0 lh0 = i, o[0], o[1], l print(lh0)