Terrible python code from the "bubble that breaks maths" video.

Overview

bubble-cosh

This repository contains the code used for Matt's bubble calculations, as featured in "The bubble that breaks maths.". https://www.youtube.com/watch?v=31Om4VrSzb8

bubble-cosh.py is the original source code from the video. Code in the community folder has been provided by other contributors!

Usage

Run bubble-cosh.py. The values of d and l can be changed in the script.

Contributing

You're welcome to contribute! There are a few different places that your PR could target:

  • Bug fixes will be accepted directly in to the original code.

  • The community folder has been created as a place for any further scripts.

  • If you've done a bigger bit of work, consider keeping this in your own repository, and opening a PR to update the Further Work section below.

Further Work

Links to larger projects based on this one

You might also like...
The repository for my video "Playing MINECRAFT with a WEBCAM"

This is the official repo for my video "Playing MINECRAFT with a WEBCAM" on YouTube Original video can be found here: https://youtu.be/701TPxL0Skg Red

Allows you to purge all reply comments left by a user on a YouTube channel or video.
Allows you to purge all reply comments left by a user on a YouTube channel or video.

YouTube Spammer Purge Allows you to purge all reply comments left by a user on a YouTube channel or video. Purpose Recently, there has been a massive

A Bot that adds YouTube views to your video of choice

YoutubeViews Free Youtube viewer bot A Bot that adds YouTube views to your video of choice Installation git clone https://github.com/davdtheemonk/Yout

GEGVL: Google Earth Based Geoscience Video Library

Google Earth Based Geoscience Video Library is transforming to Server Based. The

A Blender addon for VSE that auto-adjusts video strip's length, if speed effect is applied.

Blender VSE Speed Adjust Addon When using Video Sequence Editor in Blender, the speed effect strip doesn't auto-adjusts clip length when changing its

This is a library which aiming to save all my code about cpp. It will help me to code conveniently.

This is a library which aiming to save all my code about cpp. It will help me to code conveniently.

Py-Parser est un parser de code python en python encore en plien dévlopement.

PY - PARSER Py-Parser est un parser de code python en python encore en plien dévlopement. Une fois achevé, il servira a de nombreux projets comme glad

inverted pendulum fuzzy control python code (python 2.7.18)
inverted pendulum fuzzy control python code (python 2.7.18)

inverted-pendulum-fuzzy-control- inverted pendulum fuzzy control python code (python 2.7.18) We have 3 general functions for 3 main steps: fuzzificati

Research using python - Guide for development of research code (using Anaconda Python)

Guide for development of research code (using Anaconda Python) TL;DR: One time s

Comments
  • I felt compelled to point this out... (SciPy!!!)

    I felt compelled to point this out... (SciPy!!!)

    So I just had to get involved here... I couldn't leave the chaos I saw untouched.

    The reason I'm posting this issue (which really is just a message, do with it what you see fit) is because I needed to point out that you're coding in Python! Always assume something is done for you already! And that something is SciPy which has a huge number of different optimization functions (and yes I'm spelling that optimization despite being English... I spotted that maths, but programming is written in "American", no matter how much I disagree)

    I'm not even 100% sure what the code is minimizing! I just recognised that it was trying to do that. So below is the same code modified to use the scipy library to solve the problem with minimal effort.

    Note some subtle changes:

    1. error now takes one argument which is a list of both values. That's just how optimize works.
    2. The error function returns the sum of squares rather than the absolutes. You get best results when your function is differentiable within the bounds that you care about (because ScyPy tries to be smart rather than brute force things). There are ways to handle the other situation, but this works better.
    import math as maths
    from scipy.optimize import minimize
    
    d = 1.068
    l = 0.6
    
    def total_area(a, l):
        return maths.pi * (a ** 2) * (maths.sinh(l / a) + (l / a))
    
    def error(args):
        a, b = args
        try:
            x1 = 0
            y1 = d / 2
            e1 = a * maths.cosh((x1 - b) / a) - y1
            x2 = l
            y2 = d / 2
            e2 = a * maths.cosh((x2 - b) / a) - y2
            error = e1**2 + e2**2
            return error
        except:
            return float("inf")
    
    # Use SciPy to minimize our error function with minimal effort
    # Note: The (1, 1) represents the starting values for the search
    results = minimize(error, (1, 1))
    
    # Extract out the two final results
    a, b = results.x
    
    print("for diameters of {0} and length of {1}".format(d, l))
    print("a={0}, b={1}".format(a, b))
    
    mid_radius = a * maths.cosh(((l / 2) - b) / a)
    
    print("Area of {0}".format(total_area(a, l)))
    print("mid dip of {0}".format((d / 2) - mid_radius))
    print("mid gap of {0}".format(mid_radius * 2))
    

    For reference, this gives an area 99.999999% of the original code. So... it's totally more accurate.


    And to be clear, I have other issues with coding style... but I can forgive those of mathematicians. I didn't want to change the code too much in a random issue being posted on GitHub.

    opened by Pluckerpluck 1
  • Refactor the main script

    Refactor the main script

    I was unsure what you intended with the community folder, so maybe this PR isn't in line with that. It certainly isn't a bug fix. I'm happy to move this improved script to the community folder if you want to retain authenticity from the video. (That said, I didn't change the algorithm, and I signed any comments I wrote with -N.)

    The following is a list of stuff I did. Probably not exhaustive.

    • Add type hints
    • Add optional arguments
    • Allow the file to be an importable module for further work (I just separated out the script portion).
    • Use command line arguments
    • Format with black
    • File name uses underscores (necessary for importability)
    • Add very simple testing
    • Update README accordingly
    • Use break in while loop
    opened by nfitzen 1
Owner
Stand-up Maths
Various bits of code from Matt Parker's projects
Stand-up Maths
A very terrible python-based programming language that uses folders instead of text files

PYFolders by Lewis L. Foster PYFolders is a very terrible python-based programming language that uses folders instead of regular text files. In this r

Lewis L. Foster 5 Jan 8, 2022
Video Stream is an Advanced Telegram Bot that's allow you to play Video & Music on Telegram Group Video Chat

Video Stream is an Advanced Telegram Bot that's allow you to play Video & Music on Telegram Group Video Chat ?? Stats ?? Get SESSION_NAME from below:

dark phoenix 12 May 8, 2022
Todos os exercícios do Curso de Python, do canal Curso em Vídeo, resolvidos em Python, Javascript, Java, C++, C# e mais...

Exercícios - CeV Oferecido por Linguagens utilizadas atualmente O que vai encontrar aqui? ?? Esse repositório é dedicado a armazenar todos os enunciad

Coding in Community 43 Nov 10, 2022
About A python based Apple Quicktime protocol,you can record audio and video from real iOS devices

介绍 本应用程序使用 python 实现,可以通过 USB 连接 iOS 设备进行屏幕共享 高帧率(30〜60fps) 高画质 低延迟(<200ms) 非侵入性 支持多设备并行 Mac OSX 安装 python >=3.7 brew install libusb pkg-config 如需使用 g

YueC 124 Nov 30, 2022
Donatus Prince 6 Feb 25, 2022
Exercicios de Python do Curso Em Video, apresentado por Gustavo Guanabara.

Exercicios Curso Em Video de Python Exercicios de Python do Curso Em Video, apresentado por Gustavo Guanabara. OBS.: Na data de postagem deste repo já

Lorenzo Ribeiro Varalo 0 Oct 21, 2021
These are After Effects and Python files that were made in the process of creating the video for the contest.

spirograph These are After Effects and Python files that were made in the process of creating the video for the contest. In the python file you can qu

null 91 Dec 7, 2022
All exercises done during the Python 3 course in the Video Course (World 1, 2 and 3)

Python3-cursoemvideo-exercises - All exercises done during the Python 3 course in the Video Course (World 1, 2 and 3)

Renan Barbosa 3 Jan 17, 2022
a pull switch (or BYO button) that gets you out of video calls, quick

zoomout a pull switch (or BYO button) that gets you out of video calls, quick. As seen on Twitter System compatibility Tested on macOS Catalina (10.15

Brian Moore 422 Dec 30, 2022
Vehicle Identification Speed Detection (VISD) extracts vehicle information like License Plate number, Manufacturer and colour from a video and provides this data in the form of a CSV file

Vehicle Identification Speed Detection (VISD) extracts vehicle information like License Plate number, Manufacturer and colour from a video and provides this data in the form of a CSV file. VISD can also perform vehicle speed detection on a video. All these features of VSID are provided to the user using a Web Application which is created using Flask

null 6 Feb 22, 2022