Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show singularities at endpoints #21

Closed
CheapMeow opened this issue Mar 1, 2023 · 1 comment
Closed

Show singularities at endpoints #21

CheapMeow opened this issue Mar 1, 2023 · 1 comment

Comments

@CheapMeow
Copy link

CheapMeow commented Mar 1, 2023

I use this to test:

import numpy as np
import differint.differint as df
import matplotlib.pyplot as plt

def f(t):
    return np.power(t, 3)

alpha = 0.6

t_1 = np.linspace(-1, 1, 100)
t_2 = np.linspace(0, 1, 100)
GL_1 = df.GL(alpha, f, -1, 1, 100)
GL_2 = df.GL(alpha, f, 0, 1, 100)

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(t_1, GL_1, marker='o', markevery=5)
ax.plot(t_2, GL_2, marker='x', markevery=5)

plt.show()

And this is result. Obviously, 0.6 derivative of the function y = x^3 shouldn't be so low at endpoint.

In particular, its fractional derivative should be 0 at zero, but if you give differint to sovle [0,1], it would be wrong at x = 0.

image

@cooperhatfield
Copy link
Collaborator

Hello @CheapMeow, the asymptotic behavior at the left endpoint is a side effect of how the Grunwald-Letnikov differintegral is implemented. Comparing to the result gained from the Riemann-Liouville differintegral and the expected results, we see that it much more accurate.
image

These results were obtained using the following code:

import numpy as np
import differint.differint as df
import matplotlib.pyplot as plt

def f(t):
    return np.power(t, 3)
def neg_f(t):
    return f(-1 * t)


alpha = 0.6

t_2 = np.linspace(0, 1, 100)
GL_2 = df.GL(alpha, f, 0, 1, 100)

GL_2_rev = df.RL(alpha, f, 0, 1, 100)

expected = lambda t: 6/(df.Gamma(3-alpha+1)) * t ** (3 - alpha)


fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(t_2, GL_2, label='GL')
ax.plot(t_2, GL_2_rev, marker='o', markevery=5, label='RL')
ax.plot(t_1, expected(t_1), label='expected')
ax.legend()

plt.show()

Another thing to point out, is that to conserve many of the properties one might expect from the fractional derivative of polynomials, the left endpoint should be kept to 0; I only included that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants