Project Euler: Problem 9

That is the problem: We can solve the problem by writing a Python code. Let’s start with a function that checks if the three numbers , with , are a Pythagorean triplet. Now, let’s move on to defining the main function: and then, the main program: This is the answer:

Continua a leggere →

The square root of 2…

The square root of 2 (approximately 1.4142) is a positive real number that, when multiplied by itself, equals the number 2.  There are a number of algorithms for approximating √2 as a ratio of integers or as a decimal. The most common algorithm for this, which is used as a basis in many computers and calculators, is the Babylonian method for computing square roots, which is…

Continua a leggere →

gnuplot for dummies…

At first glance, it might seem that Gnuplot is more difficult to use for plotting than MS Excel. But it only seems that way, the entry threshold is a little higher (you can’t use a mouse to click it, you need to read the documentation here), but in practice, it comes out much easier and…

Continua a leggere →

PyFiglet…

FIGlet – as you can read here – is a program for making large letters out of ordinary text. A very quick note on how to add FontArt to Python’s output view.I will give a few tips on how to add FontArt to the python output display. The method is quite easy, the first thing…

Continua a leggere →

The Fibonacci sequence…

The Fibonacci sequence is one of the most well known mathematical sequences and is the most basic example of recurrence relations. Each number in the sequence consists of the sum of the previous two numbers and the starting two numbers are and . It goes something like this: We will go through a few different…

Continua a leggere →

Basic Plotting with matplotlib

The Python ecosystem gives us the option of visualizing relationships between numbers via matplotlib, a plotting library (i.e., not part of core Python) which can produce quality figures. Inside the matplotlib package is the matplotlib.pyplot module, which is used to produce figures in a MATLAB-like environment. Here a simple example code for the matplotlib.pyplot module.…

Continua a leggere →

1-D Linear Convection

The 1-D Linear Convection equation is the simplest, most basic model that can be used to learn something about CFD. With given initial conditions (understood as a wave), the equation represents the propagation of that initial wave with speed , without change of shape. Let the initial condition be . Then the exact solution of…

Continua a leggere →

Basic data manipulation in Python…

In this post, we will deal with data from ECDC and we will explain basic data manipulation in Python with the Pandas package. In our day, data is everywhere in enormous size and depth. Data science is an emerging field that penetrates every aspect of our life and, lately, it has proved to be an…

Continua a leggere →

A spiral of first 10k prime numbers…

A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. Euclid proved the infinity of primes by contradiction. Assume there are a finite number, n , of primes , the largest being ; Consider the number that is the product of these, plus one: By…

Continua a leggere →