What's new

Maximum Point from CubicSpline for Excel or Alibre Script

GIOV

Alibre Super User
Hi Guys
I have a big questions:
1.-How run a scipy CubicSpline in Alibre Script or Excel?

import numpy as np
from scipy.interpolate import CubicSpline
import matplotlib.pyplot as plt
x = np.arange(10)
y = np.sin(x)
cs = CubicSpline(x, y)
xs = np.arange(-0.5, 9.6, 0.1)
fig, ax = plt.subplots(figsize=(6.5, 4))
ax.plot(x, y, 'o', label='data')
ax.plot(xs, np.sin(xs), label='true')
ax.plot(xs, cs(xs), label="S")
ax.plot(xs, cs(xs, 1), label="S'")
ax.plot(xs, cs(xs, 2), label="S''")
ax.plot(xs, cs(xs, 3), label="S'''")
ax.set_xlim(-0.5, 9.5)
ax.legend(loc='lower left', ncol=2)
plt.show()

2,0 How find the Maximum Point of a CubicSpline?

from scipy.interpolate import InterpolatedUnivariateSpline
f = InterpolatedUnivariateSpline(x_axis, y_axis, k=4)
cr_pts = f.derivative().roots()
cr_pts = np.append(cr_pts, (x_axis[0], x_axis[-1])) # also check the endpoints of the interval
cr_vals = f(cr_pts)
min_index = np.argmin(cr_vals)
max_index = np.argmax(cr_vals)
print("Maximum value {} at {}\nMinimum value {} at {}".format(cr_vals[max_index], cr_pts[max_index], cr_vals[min_index], cr_pts[min_index]))

Uff, it is so difficult for me this issue.
Ref.:
 
Last edited:

stepalibre

Alibre Super User
These projects are Python 3, numpy and scipy can be pip or conda installed in them.


They use PythonNet which can talk to AD (Alibre Script and AlibreX) from .NET several ways.

You can export coordinates and geometry info to csv or text from Python to use in Excel or Alibre Script.

Excel has Python support now so if you can get it up and running it might be the easy way to answer both questions:

1726201122683.png
1726201322077.png

min_index = np.argmin(cr_vals)
max_index = np.argmax(cr_vals)

What is the issue? You can review numpy documentation for max and min.
 

GIOV

Alibre Super User
Hi Stepalibre,
Thanks for your answer.
I like to try in Alibre:
So I will import a CubicSpline curve from my old excel and try to apply the above "from scipy.interpolate import CubicSpline" code that I find.
Is it correct?
If correct, library resources are enormous.
1726208021190.png
 
Last edited:
Top