# Super Code from Digital Knife Monkey Productions

## Digital Knife Monkeys at Keyboards...Will Eventually Program Everything.

### Blog

#### Equation of the Week #9: Calculus and why you should know it

 Posted by DarthWho on November 24, 2011 at 9:35 AM comments (0)

Now this is not really a true "equation of the week" entry as it features no equations;

Now why should you as a programmer know calculus? Is it the only path to being a great Programmer? Well no it is not some magical pathway leading to you becoming one of the pantheon of programming gods; there are many paths to being a great programer; Here is why I think you should have some understanding of calculus under your belt: you will be better equipped to solve any problems that may come your way. however there are several other reasons to study calculus. (which will be covered later in this post)

now before we really get into actually doing calculus let's talk about the history behind this branch of mathematics;

Some of the earliest pressure came from the field of astronomy/astrology (in ancient times they were one and the same), people kept records to predict the phases of the moon, the movement of the planets;and records of the constellations; the constellations were simple the stars seemed to stay in place the phases of the moon were easy to predict as well as was the movement of the moon; but planets were tough eventually a system arose known as the Ptolemaic system to describe why the planets often seemed to stop or reverse direction it relied on a system of nested spheres with the largest one being called it's deferent and the smaller ones called the epicycles which ended up with people who still thought that the earth was the center of the universe believing that the planets followed unbelievably complex paths:

[image courtesy of Wikimedia Commons]

ironically enough the above image only describes the positions of Mercury and Venus as the Ptolemaic astronomer knew them for 7 an 8 years respectively; later on the heliocentric view was developed by  Nicolaus Copernicus  unfortunately this system was no more accurate than the Ptolemaic system and conflicted with among other things scripture and Natural Philosophy (IE what we know know as the hard sciences) the reason why is because it still postulated circular orbits and it was not until Johannes Kepler posited that the orbits of the planets were elliptical that heliocentrism started to gain ground;kepler came up with three laws:

the orbits are ellipses, with the sun at one focus

the velocity of a planet varies in such a way that thearea swept out by the line between planet and sun is increasingat a constant rate

the square of the orbital period of a planet is directly proportional to the  planet's average distance from the sun cubed.

Another area that helped lead to calculus was the concept of falling masses; Aristotle observed that a rock falls faster than a feather and concluded that heavier objects fall faster; Galileo later experimentally proved that the weight of the object does not effect the rate at which an object falls.

But it wasn't until Sir Issac Newton and Gottfried Leibniz independently developed Calculus Newton called his work "the science of fluents and fluxions". while Leibniz gave it the name we are familiar with.

Well a derivative gives us the exact equation slope of a curve; In terms of physics this means tht if we have an equation that describes the position of an object as a function of time then taking the derivative gives you the velocity of the object as a function of time; while integration gives you the relative area under a curve (the reason why is that there is a constant added that is only defined by supplying a point for the equation to fit to) this means that from the equation for the velocity you can work out the equation for position. now why bother with this when there are methods such as rise over run and summation? because these are exact solutions and minimize or eliminate the build up of errors where approximate solutions fail to minimize the errors. differentiation and integration are essentially inverse processes  (part of the reason that the integral is also called the Antiderivative).

next week Polynomial Differentiation

#### Equation of the Week #8: Complex Exponentiation

 Posted by DarthWho on November 23, 2011 at 11:45 PM comments (1)

Sorry for the huge delay in getting this one up my bad.

anyway:

how fo we calculate a^b when both A and B are complex numbers?

well this is where the complex exponentiation formula comes into play (this is a long one so hold onto your hats!

well first we have the formula:

E+Fi=(A+Bi)^(C+Di)

how do we work that out you ask? well it just so happens that that formula is equal to:

E+Fi=(A^2+B^2)^(C/2)*e^(-D*ARG(A+Bi))*(COS(C*ARG(A+Bi)+D*ln(A^2+B^2)/2)+i*SIN(C*ARG(A+Bi)+D*ln(A^2+B^2)/2))

or to split it up into components

G=(A^2+B^2)^(C/2)*e^(-D*ARG(A+Bi))

E=G*COS(C*ARG(A+Bi)+D*ln(A^2+B^2)/2)

F=G*SIN(C*ARG(A+Bi)+D*ln(A^2+B^2)/2)

I will try to update more regularly in the future;

this sunday: Calculus and why programmers should have some basic understanding of the subject. this will kick off a new seried which will focus on educating self professed math dummies on the mysteries of basic calculus.

#### Equation of the Week #7: The Complex Argument

 Posted by DarthWho on May 22, 2011 at 12:00 AM comments (1)

the complex argument is a function which is comonly used in functions such as complex exponentiation; it is a function which takes a Complex number and returns a real number to put it into easy to understand terms:

ARG(X + i * Y) = ARCTAN(Y / X)

Or to put it in terms of qb64 code:

ARG(X + i * Y) = ATN(Y / X)

NEXT WEEK: COMPLEX EXPONENTIATION

#### Equation of the Week #6: an introduction to math with Complex Numbers

 Posted by DarthWho on May 15, 2011 at 12:00 AM comments (0)

Complex numbers are not as difficult as they may first appear to be; this numeric system which is traditionally written in the form of:

A + B * i

Is the second of the division maths to be discovered; this is because like the real numbers the complex numbers are capable of being divided: however the complex numbers could also be written as

(A, B)

which brings us to a rather interesting point where it comes to these complex numbers: they form a twodimensional plane similar to the X,Y plane which is commonly used in programming.

now onto the basic mathematic operations:

(A + B * i) + (C + D * i) = (A + C) + (B + D) * i

Subtration

(A + B * i) - (C + D * i) = (A - C) + (B - D) * i

Multiplication:

(A + B * i) * (C + D * i) = (A * C - B * D) + (A * D + B * C) * i

and Division:

(A + B * i)/(C + D * i) = ((A * C + B * D) + (B * C + A * D) * i)/(C ^ 2 + d ^ 2)

NEXT WEEK: the Complex Argument. (ARG(z))

#### Equation of the Week #5: Squareroots of complex numbers

 Posted by DarthWho on May 8, 2011 at 12:00 AM comments (1)

Any one who is sufficiently well versed in number theory understands that the squareroot of a negative number produces what is known as an imaginary number:designated by the symbol i but then what is the squareroot of i or for that matter any of the general group of the complex numbers (a+b*i)?

√(A+B*i)=√((A + √(A2 + B2))/2) + SGN(B) * √((-A + √(A2 + B2))/2) * i

which for i produces about 0.707106781 + 0.707106781 * i

Next Week: Basic Complex Number Rules (addition subtration multiplication and division)

#### Equation Of the Week #1 Making a Splash

 Posted by DarthWho on April 10, 2011 at 12:00 AM comments (1)

Well the first equation of the week these will come out every Sunday that I have time to actually put these in place (there may be some gaps and I apologize ahead of time for that.)

P = ( ρ g^2 T H^2 L ) / ( 32 π )

P power in the wave measured in Watts

ρ the desity of the liquid medium (1025kg/m3 for seawater and 1000kg/m3)

g gravitational acceleration (9.8m/s2 on earth)

T wave period (time between sucessive waves in seconds)

H wave height (distance from peak to trough in meters)

L length of wavefront in meters (wavefront is perpendicular to direction of travel

π If you do not know what this is it makes me sad

NEXT WEEK: TIME DILATION