Posted in Mathematics, Programming

## Generating the Cantor’s Set with Computer

The Cantor’s set is somewhat fascinating fractal, when one gets to more familiar with it.

The basic idea is to handle real number interval [0,1]. This is divided to three parts of same width removing the middle part. The remaining parts are again divided to three parts of same width removing always the middle part. This is continued infinitely.

The Cantor’s set consists of the points that are left in this process.

In the language of the set theory the Cantor’s set can be expressed as follows: The union tells what doesn’t belong to the set.

I have used this formula to implement the Cantor’s set in my program. The idea is to examine the union interval and draw a pixel, when the point does belong to the set.

Below is a picture from the program’s output: Here’s the Java program in full:

```import java.awt.*;
import javax.swing.*;
import java.awt.event.WindowEvent;
import java.lang.Math;

public class Cantor {

private JFrame frame;
private CantorPanel panel;

public Cantor() {
frame = new JFrame("The Cantor's Set");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
initialize();
frame.pack();
frame.setVisible(true);
}

private void initialize() {
panel = new CantorPanel();
}

public static void main(String args[]) {
new Cantor();
}
}

class CantorPanel extends JPanel {

public CantorPanel() {

setBackground(Color.lightGray);
setPreferredSize(new Dimension(1024,100));
}

public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;

drawCantor(g, 7);
}

public void drawCantor(Graphics g, int maxIter) {

int y = 17;

for (int m = 1; m < maxIter + 1; m++) {

for (int x = 0; x < 1024; x++) {

if (belongsToSet(m,x) == true) g.drawOval(x,y,1,1);
}
y = y + 10;
}
}

public boolean belongsToSet(int m, double x) {

double line = 1024;
double x1,x2;

for(int mm = 1; mm < m ; mm++) {

for (int k = 0; k < (int)((Math.pow(3,(mm-1))) - 1 + 1); k++) {

x1 = (3.0*k + 1) / Math.pow(3.0,mm);
x2 = (3.0*k + 2) / Math.pow(3.0,mm);

if ((x > x1 * line) && (x < x2 * line)) return false;

}

}
return true;
}

}
```

Because of the calculation precision with “big” number of iterations drawing accuracy isn’t very good.

The program is free for personal and educational use.

Posted in Mathematics

## The powers of imaginary unit i

I remember the time when I was still studying at lukio (equivalent school is high school in the US, gymnasium in Sweden, Gymnasium in Germany) when there were exercises to determine positive integer powers of imaginary unit i. I invented at that time a method to easily determine the power without using the taught method of grouping the exponent. Later on my university times I invented a formula to determine arbitrary real number power of imaginary unit i.

The method

Complex number z is of form z = a + bi, where the previous is the real part and the latter the imaginary part. Now we’re interested only in imaginary unit i. So we examine complex number z = i, the magnitude of i = 1.

The argument (arg) of imaginary unit i is 90°. From this fact it follows that multiplying with i corresponds 90° rotation on the complex plane. Thus, if the exponent is a positive integer, there’s exactly 4 possibilities for the power of i: 1, -1, i, -i. The power can be determined by dividing the exponent by 4 and examining the decimal part of the division. There are now 4 possibilities: .0; .25; .5; .75. These tell how many percent of unit circle on the complex plane has been rotated.

Based on this the following table can be presented: The first line is the decimal part of division by 4 of the exponent, the second line tells place in the unit circle of the complex plane, the third line tells the the power of imaginary unit i.

For example to determine i12345678 , we first divide the exponent 12345678 by 4, the result is 3086419.5. The decimal part is .5, so we see from the table above, that the power is -1.

The formula for arbitrary real number exponent

I invented this formula myself some time in the year 1997 when I was studying for the second year at the university of Jyväskylä. I thought my formula was too simple, so I didn’t show it to the maths department staff. Anyway, the formula is as follows: Many years ago, I asked on local science magazine’s net forum, that does this kind of formula already exist. The existing formula was a bit different. In the same forum one reader presented a proof to this formula.

Posted in Mathematics

## k base logarithm of negative real number

Many years ago when I was studying for the second year in the university of Jyväskylä in one sleepless night I somehow invented how to determine logarithm of negative real number, although I had only basic knowledge of complex numbers. And yes, the logarithm of negative real number is, of course, a complex number.

Now to the formula…

Let x ∈ ℜ and x < 0 and k > 1. Now

I was able to prove this formula in less than 30 minutes, about one A4 paper of proof. Next morning I showed my proof to one person at staff of department of mathematics at university of Jyväskylä (Finland). He didn’t find anything wrong in my proof. A tricky part was a situation where there was two variables in one equation in my proof, but the other varibale had as coefficient sin π that equals 0, so the other variable was eliminated from the equation. I don’t have the proof anymore and I don’t really remember any relevant details of my proof other than I used Euler’s formula (*) in some part of the proof that I had become familiar with in course of differential equations.

(*) As far I can see, the formula probably was the following:

ex + iy = ex(cos y + i sin y)