Double scalars

Résolu/Fermé
an_1314 Messages postés 5 Date d'inscription vendredi 14 mai 2021 Statut Membre Dernière intervention 14 mai 2021 - Modifié le 14 mai 2021 à 16:26
yg_be Messages postés 22728 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 26 avril 2024 - 15 mai 2021 à 09:34
Bonjour,
Je rencontre un petit soucis, je ne vois pas quelle erreur je commets dans mon code. Python me dit : FloatingPointError: overflow encountered in double_scalars
En espérant que vous réussirez à m'aider. Merci !

def evolution (T0, Ta0, iterations) :
    n = len(T0)
    Ta = np.copy(T0)
    for k in range (0, n) :
        Ta[k] = Ta0[k][0]
    for k in range (1, iterations +1) :
        T1 = np.copy(T0)
        Ta1 = np.copy(Ta)
        for i in range (1, n-1) :
            dTa = (Ta[i+1]-Ta[i])/dtheta
            d2Ta = (Ta[i+1]-2*Ta[i]+Ta[i-1])/((dtheta)**2)
            Ta1[i] = (((l*((np.cos(angles[i]))*d2Ta - (np.sin(angles[i]))*dTa)+2*(1-            A(T0[i]))*phi0*np.cos(angles[i])/np.pi)/(sigma*(1+epsilon))) - (1-A(T0[i]))*phi0*np.cos(angles[i])/(sigma*np.pi))**1/4
            T1[i] = ((Ta1[i]**4)+((1-A(T0[i]))*phi0*np.cos(angles[i])/(sigma*np.pi)))**1/4
        T0 = T1
        Ta = Ta1
    plt.plot(angles, T0)
    plt.show()
A voir également:

1 réponse

yg_be Messages postés 22728 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 26 avril 2024 1 476
14 mai 2021 à 17:35
bonjour, à quelle ligne?
es-tu certain d'avoir partagé un code complet et testable?
moi je n'ai pas d'erreur quand j'exécute ton code.
0
an_1314 Messages postés 5 Date d'inscription vendredi 14 mai 2021 Statut Membre Dernière intervention 14 mai 2021
14 mai 2021 à 17:56
Bonjour, oui effectivement mon code n’est pas bien indenté. plt.plot et plt.show sont alignés avec les lignes précédentes ...
0
yg_be Messages postés 22728 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 26 avril 2024 1 476 > an_1314 Messages postés 5 Date d'inscription vendredi 14 mai 2021 Statut Membre Dernière intervention 14 mai 2021
14 mai 2021 à 18:24
il manque peut-être un appel à la fonction?
0
an_1314 Messages postés 5 Date d'inscription vendredi 14 mai 2021 Statut Membre Dernière intervention 14 mai 2021 > yg_be Messages postés 22728 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 26 avril 2024
Modifié le 14 mai 2021 à 18:36
Voici le code entier (très long) ... Peut-être que j'ai omis quelque chose ?
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import odeint
import copy

 
np.seterr(all='raise')

 
subdivision = 1000
a = 0.3
sigma = 5.67*(10**(-8))
phi0 = 1360
epsilon = 0.25
l = 40
dtheta = (np.pi)/(2*subdivision)
 

angles = np.linspace(0, np.pi/2, num=subdivision)
 

def phi(y0, theta) :
    x, xp = y0
    xpp = (np.tan(theta))*xp + \
        ((x**4)*sigma*(1+epsilon)/(l*(np.cos(theta)))) \
            - ((1-a)*(1-epsilon)*phi0/((np.pi)*l))
    return(xp, xpp)

 
x0 = 229.11

x = odeint(phi, [x0,0], angles)

T = (x[::,0]**4 + ((np.cos(angles))*phi0*(1-a)/((np.pi)*sigma)))**(1/4)

 

def A (temp) :
    if temp<273.15 :
        return (0.8)
    else :
        return (0.3)

 

def phi2(y0, theta) :
    i = int(theta/(np.pi/(2*subdivision)))
    x, xp = y0
    xpp = (np.tan(theta))*xp + \
        ((x**4)*sigma*(1+epsilon)/(l*(np.cos(theta)))) \
            - ((1-A(T[i]))*(1-epsilon)*phi0/((np.pi)*l))
    return(xp, xpp)
 

Ta0 = odeint(phi2, [x0,0], angles)
 
T0 = (Ta0[::,0]**4 + ((np.cos(angles))*phi0*(1-a)/((np.pi)*sigma)))**(1/4)

def lissage (T) :
    j = 1
    for i in range (1, len(T)-1) :
        d2T = (T[i+1]-2*T[i]+T[i-1])/((dtheta)**2)
        if j==1 and d2T >= 0 :     
            j = i
    deltaT = T[j] - T[j+1]
    for i in range (j, len(T)) :
        T[i] = T[i-1] - deltaT
    return(T,j)


(T,j) = lissage(T0)
Ta = np.copy(T)
for i in range(0, subdivision):
    Ta[i]=((T[i]**4)-np.cos(angles[i])*phi0*(1-a)/((np.pi)*sigma))**(1/4)
    
    
def evolution (T0, Ta, iterations) :
    for k in range (1, iterations +1) :
        T1 = np.copy(T0)
        Ta1 = np.copy(Ta)
        for i in range (1, subdivision-1) :
            dTa = (Ta[i+1]-Ta[i])/dtheta
            d2Ta = (Ta[i+1]-2*Ta[i]+Ta[i-1])/((dtheta)**2)
            Ta1[i] = (((l*((np.cos(angles[i]))*d2Ta - (np.sin(angles[i]))*dTa)+2*(1-A(T0[i]))*phi0*np.cos(angles[i])/np.pi)/(sigma*(1+epsilon))) - (1-A(T0[i]))*phi0*np.cos(angles[i])/(sigma*np.pi))**(1/4)
            T1[i] = ((Ta1[i]**4)+((1-A(T0[i]))*phi0*np.cos(angles[i])/(sigma*np.pi)))**(1/4)
        T0 = T1
        Ta = Ta1
        plt.plot(angles, T0)
        plt.show()

evolution(T, Ta, 100)
0
yg_be Messages postés 22728 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 26 avril 2024 1 476 > an_1314 Messages postés 5 Date d'inscription vendredi 14 mai 2021 Statut Membre Dernière intervention 14 mai 2021
14 mai 2021 à 19:34
c'est très simple:
ton programme arrive à une valeur négative pour
((l*((np.cos(angles[i]))*d2Ta - (np.sin(angles[i]))*dTa)+2*(1-A(T0[i]))*phi0*np.cos(angles[i])/np.pi)/(sigma*(1+epsilon))) - (1-A(T0[i]))*phi0*np.cos(angles[i])/(sigma*np.pi)

il ne peut donc pas, évidemment, en calculer la racine quatrième.
0
an_1314 Messages postés 5 Date d'inscription vendredi 14 mai 2021 Statut Membre Dernière intervention 14 mai 2021 > yg_be Messages postés 22728 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 26 avril 2024
14 mai 2021 à 21:35
Ah, oui en effet ... Merci énormément pour ton aide !
0