import numpy as np
import [Link] as plt
from [Link] import curve_fit
# Provided data
X = [Link]([9.92, 9.24, 9.73, 14.01, 18.37, 23.23, 27.9, 34.17,
41.45, 53.38, 67.2, 79.03, 87.58, 99.51, 113.18, 130.29])
Y = [Link]([61.99, 77.98, 99.43, 100.04, 100.05, 100.04, 100.07, 100.05,
100.05, 100.07, 100.07, 100.05, 100.06, 100.06, 100.06, 100.05])
# Define the sigmoid (logistic) function
def sigmoid(x, L, k, x0):
return L / (1 + [Link](-k * (x - x0)))
# Define the fit range: only use data with X between 10 and 100
fit_lower_bound = 0
fit_upper_bound = 100
# Create a boolean mask for the specified range
mask = (X >= fit_lower_bound) & (X <= fit_upper_bound)
# Extract the subset of data for fitting
X_fit = X[mask]
Y_fit = Y[mask]
# Initial guess for parameters: [L, k, x0]
p0 = [100, 0.1, 20]
# Fit the sigmoid model to the subset of data
popt, pcov = curve_fit(sigmoid, X_fit, Y_fit, p0=p0)
print("Fitted parameters:", popt)
# Generate fitted values for plotting over the entire range of X
x_plot = [Link]([Link](X), [Link](X), 100)
y_plot = sigmoid(x_plot, *popt)
# Plot the data points, the data used for fitting, and the fitted sigmoid curve
[Link](figsize=(8, 5))
[Link](X, Y, color='blue', label='All Data Points')
[Link](X_fit, Y_fit, color='green', label='Fit Range Data', marker='o')
[Link](x_plot, y_plot, color='red', label='Sigmoid Fit')
[Link]('X')
[Link]('Y')
[Link]('Sigmoid Fit over Specified Fit Range')
[Link]()
[Link](True)
[Link]()