Home > Enterprise >  Does anyone know why exactly I get this error in my python code and how to correct it?
Does anyone know why exactly I get this error in my python code and how to correct it?

Time:12-30

When I run the code below, I get this error:

yr = solve_ivp(sec_lotes,t_sim,V_inicial[0],V_inicial[1],V_inicial[2],V_inicial[3],method='RK45')
TypeError: solve_ivp() got multiple values for argument 'method' 

Here's the code:

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
#When I run this code I get this error
#yr=
#solve_ivp(sec_lotes,t_sim,V_inicial[0],V_inicial[1],V_inicial[2],V_inicial[3],method='RK45')
#TypeError: solve_ivp() got multiple values for argument 'method' 
###Parámetros y constantes del modelo
kg = (0.00626 * 60) / ((1000) / (60 ** 2))  # coeficiente de transferencia de masa en 
kg/m2*s*kpa
pws = 12.352 * ((1000) / (60 ** 2))  # a 50°C presión de vapor de saturación del agua en kpa
pwinf = 2.33 * ((1000) / (60 ** 2))  # presión de vapor del agua en kpa
h = 0.0718 * 60  # coeficiente de transferencia de calor convectivo en kw/m2*°C
pa = 1.092  # densidad del aire en kg/m3
ps = 530  # densidad del sólido en kg/m3
Cpha = 1.006 * ((1000) / (60 ** 2))  # calor del aire húmedo en kj/kg*°C
k = 0.0005641 * 60  # conductividad térmica de la papa en kw/m*°C
Lc = 0.05  # espesor de la papa en m
delta_Hw = 2382 * ((1000) / (60 ** 2))  # calor de vaporización en kj/kg
V = 0.00000392  # volumen real en m3
V1o = 0.000549  # volumen de lecho inicial en m3
avo = 200  # área de la partícula/ volumen inicial (rodaja de papa) en m-1
c1 = 0.0267  # constante adimensional
c3 = -1.656  # constante adimensional
q1 = 0.0107  # constante adimensional
q2 = 1.287  # constante adimensional
q3 = -1.513  # constante adimensional
A = 1.612  # constante adimensional
B = 3.114  # constante adimensional
C = 2.175  # constante adimensional
D = -3.194  # constante adimensional
E = 3.661  # constante adimensional
F = -1.661  # constante adimensional
G = 0.339  # constante adimensional
H = 1.246  # constante adimensional
J = -1.385  # constante adimensional
K = 0.792  # constante adimensional
Bio = 0.291
Gs = 0.0183 * 60  # flujo de aire kg/s
Lo = 0.035  # longitud del lecho inicial en m
S = 0.07625  # área de sección transversal
pso = 500  # densidad del sólido inicial
eo = 0.9  # porisidad inicial
# nodos de ***delta_A***
M = 100
# FRONTERAS : 1s=inicial     2s=final
# Condiciones de frontera de y
Y0 = 0.01578
# Condiciones de frontera de Tg
Tg0 = 50

# Condición inicial de x
x0 = 1
# Condición inicial de Ts
Ts0 = 25
# *******************************************************************************
#*********************************Ecuaciones adicionales*********************************

def sec_lotes(t,Y,x,Ts,Tg):
# *********************************Ecuaciones derivadas*********************************
    for i in range(0, M):
        plt.clf()
        delta_A = i / M

        if i == 0:
            Y = Y0
            Tg= Tg0
            x=x0
            Ts=Ts0
        else:
            ##Ecuaciones adicionales
            aw = np.exp(-c1 * x[i] ** (c3))   np.exp(q1 * np.exp(-q2 * x[i]) * x[i] ** (q3) * 
            np.log(pws))
            fi = 0.00532 * ((x[i] / x0) ** -1.079)
            nw = (kg * (aw * pws * (Ts) - pwinf)) / ((1   (fi / x0) * Bio))
            delta_Hs = (1   q1 * np.exp(-q2 * x[i]) * x[i] ** (q3)) * delta_Hw
            Cphs = A   B * (x[i] / (1   x[i]))
            av = (C   D * (x[i] / x0)   E * (x[i] / x0) ** (2)   F * (x[i] / x0) ** (3)) * avo
            e = 1 - V / ((G   H * (x[i] / x0)   J * (x[i] / x0) ** (2)   K * (x[i] / x0) ** (3)) * V1o)
        ###############################
            dYdt = ((nw * aw * (1 - e)) / (pa * e)) - (1 / (S * Lo)) * (Gs / (pa * e)) * ((ps * (1 - e)) / (pso * (1 - eo))) * ((Y[i] - Y[i - 1]) / delta_A)
            dxdt = -((nw * av) / ps)

            dTsdt= ((av / (ps * (1   x[i]) * Cphs)) * (h * (Tg - Ts) - nw * delta_Hs))

            dTgdt = -(((h * av * (1 - e)) / (pa * e * Cpha)) * (Tg - Ts)) - (1 / S * Lo) * (Gs / (pa * e)) * (ps * (1 - e) / pso * (1 - e)) * ((Tg[i] - Tg[i - 1]) / delta_A)

            sol = [dYdt, dxdt, dTsdt, dTgdt]

            return sol


Y0 = 0.01578  # Humedad del sólido
x0 = 1.0  # Humedad del aire
Ts0 = 20.0  # Temperatura inicial del sólido en °C
Tg0 = 50.0  # Temperatura inicial del aire en °C
V_inicial = [Y0, x0, Ts0, Tg0]
# Intervalo de tiempo para la simualción (min)
t_sim = np.linspace(0, 1000, 5)  # 10000,10
# Integración del modelo

yr = solve_ivp(sec_lotes,t_sim,V_inicial[0],V_inicial[1],V_inicial[2],V_inicial[3],method='RK45')

CodePudding user response:

V_inicial[0],V_inicial[1],V_inicial[2],V_inicial[3] should be an array, I have never use that function but I have been looking to the docummentation that you can read here:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_ivp.html

The function identifies V_inicial[0] as the y0 param and V_inicial[1] as the method param and when you write method='RK45' you are defining another value to method param. Try to use an array, and tell me about :)).

yr = solve_ivp(sec_lotes,t_sim,{V_inicial[0],V_inicial[1],V_inicial[2],V_inicial[3]},method='RK45')
  • Related