Der folgende Python-Code dauert lange Zeit, um die Ausführung zu erledigen, und gibt den folgenden Fehler und gibt niemals eine Ausgabe an: < /p> >>[code]/usr/local/lib/python3.11/dist-packages/scipy/integrate/_quadpack_py.py:1260: IntegrationWarning: The integral is probably divergent, or slowly convergent. quad_r = quad(f, low, high, args=args, full_output=self.full_output, /usr/local/lib/python3.11/dist-packages/scipy/integrate/_quadpack_py.py:1260: IntegrationWarning: The maximum number of subdivisions (50) has been achieved. If increasing the limit yields no improvement it is advised to analyze the integrand in order to determine the difficulties. If the position of a local difficulty can be determined (singularity, discontinuity) one will probably gain from splitting up the interval and calling the integrator on the subranges. Perhaps a special-purpose integrator should be used. quad_r = quad(f, low, high, args=args, full_output=self.full_output, < /code> Es wird also jede Hilfe geschätzt, um den Code zu optimieren und ihn wahrscheinlich ausgeführt zu machen. < /p> Hier ist der Code: < /p> from functools import partial import numpy as np import scipy.special as special from scipy import integrate from scipy.special import kn, hyp1f1 # Import hyp1f1 import matplotlib.pyplot as plt import math import time, sys from scipy.integrate import nquad from functools import partial
def parf(t1,t2,m,mu,a,k): # Avoid division by zero by adding a small value (epsilon) to t1 and t2 epsilon = 1e-10 # A small value to avoid division by zero return (H * a)**2 * k**3 * m**3 *(1/(t1*H)) * (1/(t2*H)) * (4/9)**2 * nab**2 * (1/kz)*0.2 * (1 - 2 * mu**2 + mu**4) * (1/(k**2 - 2 * k * mu * m + m**2)**(3/2))
def p21(a, k): """ Calculates the integral of p(t, y, s) with respect to s from 1 to 2. """ # Use quad to integrate p with respect to s integral_result, error = nquad(rho,[[-H, a] ,[-H, a] ,[0.1, 1],[-1,1]],args=(a,k) ) return integral_result
def p22(a, k): """ Calculates the integral of p(t, y, s) with respect to s from 1 to 2. """ # Use quad to integrate p with respect to s epsilon = 1e-10 integral_result1, error1 = nquad(rho,[[-ti + epsilon, a] ,[-ti + epsilon, a] ,[0.1, 1],[-1,1]],args=(a,k) ) return integral_result1
def F1(x): # Initialize res with the same shape as x to store results res = np.zeros_like(x, dtype=float) epsilon = 1e-10 for i,val in enumerate(x): y,err = nquad(p21, [[H, a]] ,args=(val/(2*np.pi),)) res[i]= y / delta_t1 return res
def F2(x): # Initialize res with the same shape as x to store results res1 = np.zeros_like(x, dtype=float) epsilon = 1e-10 for i,val in enumerate(x): y,err = nquad(p22, [[ti + epsilon, a]] ,args=(val/(2*np.pi),)) res1[i]= y / delta_t2 return res1
X2=X/H
# Convert X2 to a NumPy array if it's not already X2 = np.asarray(X2)
# Replace NaN or Inf values in F(X), F2(X), and F3(X) with 0 F1X = np.nan_to_num(F1(X)) F2X = np.nan_to_num(F2(X))
########################################## plt.plot(X,F1X, color='b', label='$\eta_a=-H$') # Plot using FX plt.plot(X,F2X, color='red', label='$\eta_a=-tf$') # Plot using FX plt.xlabel(" $f~ Hz$ ") plt.ylabel(r"$\rho_h(k,\tau \rightarrow 0)$") # Use raw string and correct LaTeX syntax plt.xscale('log') plt.yscale('log') plt.legend() plt.savefig('Pi-k.png') [/code]
Ich bemerke ein seltsames Verhalten mit CancellationTokenSource wob p> Ich bin mir nicht sicher, ob dies die Ursache ist, aber für den Fall, dass es relevant ist, wird es in Bezug auf eine...
Nehmen wir an, ich möchte eine sehr kleine Konsolenanwendung senden (50 Codezeilen auch ich verwende das System. Ich möchte die Anwendung tragbar machen, daher sende ich ihm nur die Ausgabe des Bin...
Ich drucke nur
print ( Hallo Welt !!! )
Aber das Debugging dauert so lange (wie 30 Sekunden) und ich weiß, dass dies nur eine Sekunde dauern sollte.
Was könnte das Problem sein?
Im Moment verwende ich Materialsymbole für meine Website. Es funktioniert großartig! Es ist hübsch, einfach zu bedienen und passt hervorragend zu meinem Design. Allerdings fällt mir auf, dass das...
Ich versuche, ein 3D -Doppelpendel mit Python, Sympy und Scipy zu simulieren. Ziel ist es, die LaGrange -Gleichungen zu lösen und die Ergebnisse zu belasten. Das Skript wird jedoch auf unbestimmte...