Home > Blockchain >  Make a parabola steeper at both sides while keeping both ends
Make a parabola steeper at both sides while keeping both ends

Time:05-26

I'm having a parabola with both axes being from 0 to 1 as follows:

enter image description here

The parabola is created and normalized with the following code:

import matplotlib.pyplot as plt
import numpy as np

# normalize array
def min_max_scale_array(arr):
    arr = np.array(arr)
    return (arr - arr.min())/(arr.max()-arr.min())

x = np.linspace(-50,50,100)
y = x**2

x = min_max_scale_array(x)
y = min_max_scale_array(y)

fig, ax = plt.subplots()
ax.plot(x, y)

I want to create another one with both ends being the same but both sides become steeper like this:

enter image description here

I thought of joining an exponential curve and its reflection but that would make the resulting parabola looks pointy at the bottom.

Can you show me how to achieve this? Thank you!

CodePudding user response:

If you want to modify any arbitrary curve, you can change the x values, for example taking a power of it:

# x and y are defined

for factor in [1.1, 1.5, 2, 3, 4]:
    x2 = 2*x-1
    x3 = (abs(x2)**(1/factor))*np.sign(x2)/2 0.5
    ax.plot(x3, y, label=f'{factor=}')

output:

enter image description here

CodePudding user response:

You can change the exponent to get a steeper curve with the same value at the extremes. You need to pick a larger value that is an even integer (odd numbers won't give a parabola).

y = x**4

y = x**4

  • Related