Saturday, October 11, 2025

Some_Math

 DAY 1

Been chatting with chatGpt4, hoping for the inside track on smooth curves. Ended

up asking for an example problem which - in desperation - I asked DeepSeek to solve.

They did an appreciable job, with a quadratic.Then went back to ChatGpt and asked for the 

expected solution!! Had to giggle, ChatGpt had python code do the job.Below: 

DeepSeek:

                                                                              


Python Code:
                                 
import numpy as np
import matplotlib.pyplot as plt

def f(x):
    return 0.5*x**2 - 0.5*x + 2
def fp(x):
    return x - 0.5
def fpp(x):
    return 1.0

x = np.linspace(0.5, 3.5, 400)

plt.figure(figsize=(9,7))

# Position
plt.subplot(3,1,1)
plt.plot(x, f(x), 'b', label='Quadratic interpolant')
plt.scatter([1,2,3],[2,3,5], color='k', zorder=5, label='Data points')
plt.ylabel('f(x)')
plt.legend(loc='upper left')
plt.grid(True, alpha=0.3)

# First derivative (slope)
plt.subplot(3,1,2)
plt.plot(x, fp(x), 'g', label="f'(x)")
plt.axhline(0, color='k', lw=0.7)
plt.ylabel("f'(x)")
plt.legend(loc='upper left')
plt.grid(True, alpha=0.3)

# Second derivative (curvature)
plt.subplot(3,1,3)
plt.plot(x, fpp(x)*np.ones_like(x), 'r', label="f''(x)=1")
plt.ylabel("f''(x)")
plt.xlabel('x')
plt.legend(loc='upper left')
plt.grid(True, alpha=0.3)

plt.tight_layout()
plt.show()

*     *     *

ChatGpt:

                                                                                       

Python Code:

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import CubicSpline

# Given data points
x = np.array([1, 2, 3])
y = np.array([2, 3, 5])

# Create a cubic spline interpolation of the data
cs = CubicSpline(x, y, bc_type='natural')

# Generate points for plotting
x_new = np.linspace(1, 3, 100)
y_new = cs(x_new)

# Plotting
plt.figure(figsize=(8, 5))
plt.plot(x, y, 'o', label='Data Points', color='red')  # original data points
plt.plot(x_new, y_new, label='Cubic Spline', color='blue')  # spline curve
plt.title('Cubic Spline Interpolation')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.grid()
plt.legend()
plt.show()

                                                                       *     *     *

In DeepSeek's defense, I just asked for a smooth curve...


DAY 2

Decided I needed to learn some math!!

Copilot:








                                                             *     *     *

                                                                                





           

No comments: