Showing posts with label jagged. Show all posts
Showing posts with label jagged. Show all posts

Saturday, 29 March 2025

Smooth Versus Jagged

I need to make more use of AI in my blog posts and to this end I wanted to replace the jagged lines in Figure 3 of my previous post with one continuous smooth line. The graph in question looked as shown in Figure 1 below:


Figure 1

The data being plotted were the numbers from 395 to 425 and their corresponing sigma values:

[(395, 480), (396, 1092), (397, 398), (398, 600), (399, 640), (400, 961), (401, 402), (402, 816), (403, 448), (404, 714), (405, 726), (406, 720), (407, 456), (408, 1080), (409, 410), (410, 756), (411, 552), (412, 728), (413, 480), (414, 936), (415, 504), (416, 882), (417, 560), (418, 720), (419, 420), (420, 1344), (421, 422), (422, 636), (423, 624), (424, 810), (425, 558)]

I asked Google Gemini to put a smooth curve through these points and Figure 2 shows what it came up with when I pasted the code into SageMathCell.


Figure 2: permalink

This is a satisfying output and is just an alternative way to display the data. There may well be a way to implement this using SageMath code alone but this approach using Python was quick and easy. It also creates a title and legends for the point and curve. I can use this code in future when needed. Here is the code that Gemini created:

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

data = [(395, 480), (396, 1092), (397, 398), (398, 600), (399, 640), (400, 961), (401, 402), (402, 816), (403, 448), (404, 714), (405, 726), (406, 720), (407, 456), (408, 1080), (409, 410), (410, 756), (411, 552), (412, 728), (413, 480), (414, 936), (415, 504), (416, 882), (417, 560), (418, 720), (419, 420), (420, 1344), (421, 422), (422, 636), (423, 624), (424, 810), (425, 558)]

# Extract x and y values
x = [point[0] for point in data]
y = [point[1] for point in data]

# Create a cubic spline interpolation
cs = CubicSpline(x, y)

# Generate smoother x values for plotting the curve
x_smooth = np.linspace(min(x), max(x), 500)  # Adjust 500 for more/less smoothness
y_smooth = cs(x_smooth)

# Plot the original points and the smooth curve
plt.figure(figsize=(10, 6))
plt.plot(x, y, 'o', label='Original Points')
plt.plot(x_smooth, y_smooth, '-', label='Smooth Curve (Cubic Spline)')
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Smooth Curve Through Points')
plt.legend()
plt.grid(True)
plt.show()

Of course, Gemini provides a full explanation of the code that it created:

Explanation:

  1. Import Libraries:
    • numpy for numerical operations (especially for generating smoother x-values).
    • matplotlib.pyplot for plotting the graph.
    • scipy.interpolate.CubicSpline for creating the smooth curve.

  2. Extract Data: The x and y values are extracted from the data list into separate lists.

  3. Cubic Spline Interpolation:
    • CubicSpline(x, y) creates a cubic spline object that represents the smooth curve passing through the given data points. Cubic splines are chosen as they offer a good balance between smoothness and accuracy.

  4. Generate Smooth x-Values:
    • np.linspace(min(x), max(x), 500) creates an array of 500 evenly spaced x-values between the minimum and maximum x-values of the original data. This is used to generate a smoother curve for plotting. Adjust the 500 for a curve with more or less detail.

  5. Calculate Smooth y-Values:
    • cs(x_smooth) calculates the corresponding y-values for the smoother x-values using the cubic spline interpolation.

  6. Plotting:
    • plt.plot(x, y, 'o', label='Original Points') plots the original data points as circles.
    • plt.plot(x_smooth, y_smooth, '-', label='Smooth Curve (Cubic Spline)') plots the smooth curve.
    • The rest of the code sets up the plot's labels, title, legend, and grid.
    • plt.show() displays the plot.

  7. How to Run:
    • Make sure you have numpy, matplotlib, and scipy installed (pip install numpy matplotlib scipy).
    • Save the code as a Python file (e.g., smooth_curve.py).
    • Run the file from your terminal: python smooth_curve.py.

Friday, 19 July 2024

Another Mid-Millenium Number

On Saturday 23rd of October 2021, I made a post titled Counting People with Mid-Millennium Numbers in which I examined my diurnal age of 26500 on that date. Now, almost three years later, I've reached another "milestone": 27500.


As I said in that post, mid-millennial numbers are popular rounding numbers for populations of towns and islands or communities with common interests or characteristics. These are to be preferred to millennium numbers such as 27,000 or 28000 that appear a little too "approximate" (having only two significant figures as opposed to the three of 27,500). Such numbers are also popular with a wide variety of quantities such as tonnage, money and distances.

The 30 divisors of 27500 are 1, 2, 4, 5, 10, 11, 20, 22, 25, 44, 50, 55, 100, 110, 125, 220, 250, 275, 500, 550, 625, 1100, 1250, 1375, 2500, 2750, 5500, 6875, 13750 and 27500. It's special in the sense that all the digits (apart from 0) are prime. This won't occur again until 30500. As with the previous mid-millennial number, the number appears frequently in population statistics. Here are some examples:
  • Published today, the NHS Workforce Race Equality Standard shows Black and minority ethnic (BME) staff make up almost a quarter of the workforce overall (24.2% or 383,706 staff) – an increase of 27,500 people since 2021 (22.4% of staff).

  • The Portuguese Grand Prix of Formula 1, which will be played between Friday and Sunday, will have a maximum capacity of 27,500 spectators, according to the government dispatch published today, October 21, in Diário da República.

  • More than 27,500 people in Gaza have already been killed over the past four months, according to Gaza’s Ministry of Health. Further fighting in Rafah risks claiming the lives of even more people. It also risks further hampering a humanitarian operation already limited by insecurity, damaged infrastructure and access restrictions.

  • The anonymous online study, ‘The Global Brain Health Survey’, involved more than 27,500 people worldwide and was led by the Norwegian Institute of Public Health in collaboration with the University of Oslo. 

  • Kirchberg’s resident population is expected to grow almost six-fold over the next 20 years, according to projections from the Fonds Kirchberg.The body responsible for coordinating the development of one of the capital’s business districts forecasts that there will be 23,700 people living in the area by 2040, up from 4,000 in 2020. It suggests that the district’s maximum capacity would be capped at 27,500 beyond 2040.

  • The Kenyan government says it has set up more than 100 camps to house over 27,500 people displaced by flooding.According to government data, more than 190,000 people have so far been affected by the floods and at least 210 are known to have died.
The aliquot sequence for 27500 has a length of 206 steps which are:

[27500, 38104, 40016, 40708, 30538, 15272, 14968, 13112, 13888, 18624, 31160, 44440, 65720, 89800, 119450, 102820, 119444, 105760, 144476, 121804, 97380, 198552, 297888, 518592, 909904, 998456, 889384, 795416, 774784, 768986, 444454, 261146, 141274, 100934, 52186, 27194, 13600, 21554, 13306, 6656, 7666, 3836, 3892, 3948, 6804, 13580, 19348, 19404, 42840, 125640, 283860, 633420, 1562004, 2535180, 5206260, 9371436, 12495276, 20190804, 26921100, 55087540, 60803732, 56587948, 45117684, 69280236, 116780184, 208518216, 312777384, 469166136, 772745304, 1187955816, 1781933784, 2716157736, 4851795384, 8337024936, 14614443864, 27722614536, 48023931924, 82013245164, 134692975476, 205780934846, 107492498242, 53746249124, 42348933724, 35852825156, 27118586620, 29830445324, 24116652916, 18087489694, 10639699874, 5379726934, 2706299954, 1471210894, 735605450, 632620780, 816656420, 898322104, 809756216, 781610824, 685415096, 602212744, 711287846, 355643926, 246590714, 123608986, 61804496, 72770224, 68943920, 91350880, 128146160, 170324320, 242956688, 264953512, 248965388, 248965444, 290225852, 310243108, 343261436, 345226084, 363478556, 363478612, 383892908, 438979156, 520540076, 520540132, 539131250, 616169806, 498886994, 249443500, 314159540, 346712980, 406492340, 486797260, 537866996, 403400254, 201700130, 166294750, 145009490, 131361862, 68478170, 54782554, 27444794, 17643046, 8821526, 6384874, 3696566, 1888594, 944300, 1555540, 2282924, 2282980, 3442460, 4965604, 5062876, 6042092, 6693988, 8128904, 9877396, 8355308, 7779412, 5834566, 2942234, 1471120, 2600048, 3337072, 3287504, 3661456, 3432646, 2557142, 1826554, 1027814, 519394, 259700, 408226, 345758, 246994, 164846, 111634, 55820, 61444, 46090, 44630, 35722, 19034, 10534, 6026, 3478, 1994, 1000, 1340, 1516, 1144, 1376, 1396, 1054, 674, 340, 416, 466, 236, 184, 176, 196, 203, 37, 1, 0]

With a logarithmic vertical axis, the trajectory has a pleasing mountain-like appearance. See Figure 1.


Figure 1

The Collatz trajectory of 27500 has 90 steps and, with a logarithmic vertical axis, its trajectory has a noticeably jagged appearance (see Figure 2):

[27500, 13750, 6875, 20626, 10313, 30940, 15470, 7735, 23206, 11603, 34810, 17405, 52216, 26108, 13054, 6527, 19582, 9791, 29374, 14687, 44062, 22031, 66094, 33047, 99142, 49571, 148714, 74357, 223072, 111536, 55768, 27884, 13942, 6971, 20914, 10457, 31372, 15686, 7843, 23530, 11765, 35296, 17648, 8824, 4412, 2206, 1103, 3310, 1655, 4966, 2483, 7450, 3725, 11176, 5588, 2794, 1397, 4192, 2096, 1048, 524, 262, 131, 394, 197, 592, 296, 148, 74, 37, 112, 56, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]


Figure 2

Here are some other interesting facts about the number:
  • The Anti-Divisors of 27500 are [3, 7, 8, 9, 21, 27, 40, 63, 81, 88, 97, 189, 200, 291, 440, 567, 679, 873, 1000, 2037, 2200, 2619, 5000, 6111, 7857, 11000, 18333]

  • The Arithmetic Derivative of 27500 is 52000

  • The Maximum - Minimum Recursive Algorithm for 27500 produces [27500, 74943, 62964, 71973, 83952, 74943]

  • The Minimal Goldbach decomposition of 27500 is 13 and 27487

  • The number of steps required is to reach home prime is 7:
    [27500, 22555511, 1110511951, 3313355021, 31337105733, 3373163729137, 4936768328311, 101312973757451]

  • 27500 has Odds and Evens Trajectory of length 12 and is [27500, 27510, 27521, 27530, 27543, 27552, 27565, 27574, 27587, 27596, 27609, 27617, 27624, 27617]
For the previous mid-millennial day see Counting People with Mid-Millennium Numbers.