import math
import plotly.graph_objects as go
import numpy as np
def regions(K, x):
if x < 0:
return math.e ** ((100 - K**2) ** 0.5) * x
elif 0 < x < 1:
return (math.cos(K * x)) + (math.sqrt(100 - K**2) / K) * math.sin(K * x)
else:
return K
if __name__ == "__main__":
# Generates an array of 100 x values between -2 and 2
x = np.linspace(-2, 2, 100)
# Allows us to evaluate the regions function over the whole range of x values
regionsVec = np.vectorize(regions)
# Apply the regions function to the range.
# I assume K is a constant. Using 9.9 for illustration purposes.
y = regionsVec(9.9, x)
# Make a graph with plotly
fig = go.Figure(data=go.Scatter(x=x, y=y, mode="lines"))
fig.show()
Click Run or press shift + ENTER to run code