import sympy as sp
from scipy.special import gamma
Define variables and functions
t, x, alpha, s = sp.symbols(‘t x alpha s’, positive=True)
n = sp.symbols(‘n’, integer=True)
f = sp.Function(‘f’) # f_n(x, t) will be defined iteratively
alpha = 1.0
Define Elzaki Transform
def elzaki_transform(func, var, transform_var):
return sp.integrate(transform_var*func * sp.exp(-var / transform_var), (var, 0, sp.oo))
Define Inverse Elzaki Transform
def inverse_elzaki_transform(transform_func, transform_var):
return sp.inverse_laplace_transform(transform_func, transform_var, t)
Define the functional correction method
def correction_functional(f_prev, x, t, alpha):
# Define the delay term
delay_term = f_prev.subs(t, t - 1)
# Define the RHS of the equation
rhs = x**2 * t - delay_term
# Apply Elzaki Transform to RHS
transformed_rhs = elzaki_transform(rhs, t, s)
# Multiply by s^alpha for fractional derivative correction
corrected_transform = s**alpha * transformed_rhs
# Apply inverse Elzaki transform to get back to time domain
corrected_function = inverse_elzaki_transform(corrected_transform, s)
# Add the initial condition x^2
return corrected_function
Example: Initialize f_0(x, t)
f_0 = x2
#f_1 = x2
Compute f_1(x, t) using correctional functional
#f_1 = correction_functional(f_0, x, t, alpha)
#print(“First Iteration f_1(x, t):”)
#sp.pprint(f_1)
Optional: Perform more iterations for better accuracy
iterations = 3
f_previous = f_0
for i in range(iterations):
f_current = correction_functional(f_previous, x, t, alpha)
print(f"\nIteration {i + 1}:")
sp.pprint(f_current)