Friday, April 25, 2014

The Crank-Nicolson Method for finite-difference of Parabolic Problems.

This is the last section we covered in Numerical Analysis class.

This is the heat distribution over time of a thin heated rod along the x-axis.  The approximation works by taking evenly spaced points along the length of the rod, over the time-axis.

The code is here:  Parabolic_FinDiff_Final02.c
Using this library: matrix.c  matrix.h

Compiled with the following command:
gcc  matrix.c Parabolic_FinDiff_Final02.c -lm -o prog02
The problem required that the step spacing along the x-axis be .2 and once that was working I tried .1, then .01 which works with 400x400 matrices and 400x1 vectors. At .2 and .1 the program ran in about 25ms.  At .01 step size the program took 9 seconds to write the results to a file.  Running the program at .002, which works with 2000x2000 matrices takes 18 minutes and 43 seconds and takes up 9% of system memory.

I am currently running  at .001 step size which will create 4000x4000 matrices to see if that breaks my matrix library. This only took 4 hours to run.  At a matrix size of 4000, the program takes up 36% of system memory.

Step, estimated result, and actual results.
Last section of results at .01 step size.

Wednesday, April 23, 2014

I destroyed a friend's thumb drive tonight.

In class a friend gave me a thumb drive so I could edit a file, because the email system hadn't sent an email to me after 20 minutes despite us sitting 5 feet from each other.  The huge cases are mounted flush with the front of the desks and the place where you plug the thumb drive in is right at the front center, middle of the case.  I was in editing and he asked me to look at something and I rolled my chair over about a foot and broke the thumb drive connector about 90% off, just thin bit of metal on one side was holding it and ground, d+, d-, and power pins were all ripped right off the board.

Since there is just 2 days before finals begins, of course he has projects due and his only copy is on the thumb drive.  I felt so horrible, like a total clumsy oaf.  But I am good with electronics and the board wasn't cracked, so I thought I had a good shot at recovering the information.

I took all the parts home. Put together my solder station, scrapped that tough green stuff they put on the mother board traces in 4 spots.  The power connection was the weak one, it came up through the board from underneath and only had a tiny little spot left to connect to.  It ended up looking like this:

Thumb drive with connector mostly ripped off
and 4 wires soldered in place.

I checked for continuity a dozen times, using 2 different meters, paranoid that I was going to short out something and blow the whole thing up. Just what I needed to do.  Not bad enough to destroy the drive, but I had to fry it as well.  I would have felt really bad if that happened.

But when I plugged it in the LED turned on, started flashing and the folder popped up.  I quickly made a copy of the drive to the hard drive.  And an hour after that the power wire popped loose when I handled the drive just a little bit. :D

Emailing my friend the files he needs tonight, and will hand him another thumb drive with everything saved in the morning.  I feel better now, even though I am a clumsy oaf, at least I am good with fixing electronic things, at least long enough to save the data.

I found a better point on the back to solder the power connector.  I think if I had some more hacker putty I could encase this whole thing and keep it working for good.

Tuesday, April 22, 2014

Partial Differential equations

Last homework for the class.  Just have a test left. :D
PartDiffEq.c       -  Example from book 
PartDiffEq_HW1.c    -   Problem 1 from handout.
Really bad picture, until I scan in the page, problem 1 layout and actual results

Obligatory use of my matrix library:
matrix.c  matrix.h
Compile like this:
gcc  matrix.c PartDiffEq_HW1.c -lm 
Save the results to a text file:
./a.out  > PartDiffEq.results.txt
Not sure I have this down pat yet.  When the equation is not equal to 0, I am not sure what to do, the HW1 I had a formula to get the exact answer, and I calculated back to figure out what to subtract from the output vector to compensate for that.

What we used the formula for was to find the temperature of an insulated thin rectangular plate that had reached a stable temperature. You have to figure out the formula for the temperature of the edges, make a grid of points inside and create a matrix for the points, then create a vector of the outputs, find the inverse of the matrix and then calculate the solution vector.

Sunday, April 20, 2014

Why the military tribunals should scare the hell out of us all.

I promised politics with this blog, so here I go.

Over the centuries governments were always held to a just standard in the ways they dispensed justice by the people that system represented.  Even serfs were only treated so badly by their lords, and the lords had responsibilities that they were held to in protecting and feeding their subjects.  And too capricious dispensing of cruel punishments could result in his own people dispensing the same justice back on a lord.   So in order to game the system the wise power brokers realized that they need to turn the public against who they desired to throw down before they moved against those people.

Politicians have always been good at reducing their enemies from human beings to some lesser outsiders that are not as deserving of justice as we good people are.  Strangely these evil people always seemed to have possessions that the politicians and their powerful friends coveted. In ancient Greece the charge was corruption of the youth.  In the middle ages it was the Inquisition.  Just before and during WWII it was the final solution.  In the 50's just being accused of being a communist was enough to destroy a person.   And today it is terrorism.  The common thread in all these atrocities is that the mere accusation of a crime is all that is required.  The accusation reclassifies the accused from a human being to something lesser.  Only then are their rights and possessions stripped from them.

In a just system the accused has the right to a fair trial with an impartial jury.  They have the right to mount a defense and there is a presumption of innocence.  Often during a trial the accused is free on bond while they organize a defense and clear up their personal affairs.  Only if there is a conviction of a crime is the person stripped of their rights and only to the extent that is required for their rehabilitation back into the mainstream of society.  

These military tribunals that began under Bush, and continue under Obama, are solely to be used to convict "terrorists." Who is a terrorist?  Why anyone the American government accuses of being a terrorist. Certainly terrorists are all guilty of the crime of terrorism, that is just assumed, otherwise why would the government accuse them?  So because they are guilty already we can hold them in inhumane conditions and treat them as less than human.  We can torture them and force confessions from them.  Just as witches confessed to consorting with demons during the the Inquisition. These kangaroo courts reduce the rights ahead of the crime, eliminating the presumption of innocence based on an arbitrary designation of terrorist being assigned to a human being.   This reclassification from human being to something lesser precedes the automatic assumption of guilt. 

Make no mistake, being a terrorist is something that any of us can be _accused_ of being at will by anyone in the government. But they would never accuse Americans of being terrorists and take their rights away without a trial, you say. 

Like the right to life?  

How about the right of liberty?   

How about the right to travel?  

How about the right to own things?

Surely they would only target the criminals?  It amazes me how people that don't trust the government to pour piss out of a boot with the instructions on the heel will trust the government to know who a criminal is 100% of the time. 

No, you cannot trust the government to do anything right.  The government is as good at accusing people of crimes as they are at balancing the budget. Or in other words, horribly bad at it.  That is why we have courts and juries and appeals. Because the government gets things wrong in a surprisingly high number of court cases. 

We need to end the travesty of the Military Tribunals.  We need to allow the human beings that are accused of terrorism the same rights that you and I expect if we were accused of a crime.  Or when we are finally accused then we will find out that we have no more rights than those we allowed to be persecuted before us in our names.

Saturday, April 19, 2014

I made a cup of brownie.

4 tablespoons of brownie mix
4 tablespoons of baking mix
1 tablespoon of butter
an 1/8 cup of water
one egg

In a large cup or bowl, combine the water and butter.
Heat the water and butter to melt the butter, 30 seconds on high in the microwave.
Add powdered mix to heated water and melted butter, mix evenly.
Add egg, mix thoroughly.
Microwave until the brownie mix rises to the top of the cup, about 60 seconds in my case.

I waited a couple of minutes and microwaved the cup another 30 seconds.

I waited a couple of minutes and then started eating it.

The brownie mix is about half strength, and has a mild, chocolate taste.

Saturday, April 5, 2014

Linux has just passed the tipping point.

It was funny to watch MS try to fight the Linux Hydra. For every head they chopped off, 3 more heads popped out. But right now it is all over but the crying. Linux has won on servers, on low end netbooks, on phones, on embedded devices, and on all the new low end micro controllers that are currently taking over the desktop.  Every attempt by Windows to enter new markets has failed, with their foray into gaming costing them much more than they made from gamers. (

MS clusters on have 2 out of the top 500 super computers ( Most cloud systems run Linux with about 80% of web/cloud service traffic on the Internet run on Linux. One service, Netflix on Linux, take up about 1/3 of all Internet traffic alone (  Every time you use Google, you are using one of the largest Linux clusters in the world with 25% of daily traffic ( 

MS was forced to keep XP alive for 5 years longer than they had planned to fight off Linux on netbooks. And even this didn't work because there are chrome books from many vendors that do not run Windows and many people are very happy with these small, low cost, full featured netbooks.

MS lost the mobile/embedded market before they even got started, with all the flavors of Android overwhelming even the former market leader iPhone like an avalanche. You can't compete against 100 low cost competitors each advancing some aspect of Android and having to share that with everyone else. The only way to compete is to join.  Zune was a horrible loss (,28804,1898610_1898625_1898633,00.html).

Android and other flavors of Linux run on most embedded devices, because of the low cost, ease of porting to new micro controllers, and full features. If your TV can play videos, it is probably running some flavor of Linux. If you have a stand alone media player, it is probably running Linux (

Now single board computer like the Beaglebone Black and Raspberry Pi cost less than $50; to put a MS OS on those boards would more than triple the cost, and quite frankly these boards are just about more computer than the average person actually needs. With Moore's law every 2 years these kind of boards will only get faster and cheaper. Many routers even run Linux.

In 20 years you will be able to buy a $5 computer that is as powerful as the average desktop machine today. Is MS Windows still going to cost $100 then? I'm going to guess that to stay relevant and competitive MS will have to be priced at about 50 cents per machine at that point. Can they stay in business at that price point?

The Steam Box running Linux is going to do to gaming what Android did to the mobile phone market ( Even I am planning on buying one. Goodbye PS4 and Xbox one. You can already emulate most games older than about 5 years old on the Raspberry Pi.

The only place that Windows still has a major market share is on the desktop, and only because they were convicted of illegally using monopoly powers to maintain that share. They are currently trying to convert 500 million XP users, an OS that came out in 2001 over to Windows 8.  In fact, the 40% of desktops in both corporate and home are still running XP.  (

I don't believe that the conversion rate is going to be very high. I foresee at least half of these users upgrading their machines to running Linux, instead of having to buy a new machine to run the latest version of windows.  The only thing keeping Microsoft afloat right now is the little bit it is making from Windows 8, which is their least popular operating system they have ever released (  

So all in all, Microsoft is pretty much running on empty right now.  Only the billions they have in the bank are keeping them rolling along, but that is going to run out in just a few more years.

Goodbye Microsoft.

Solving Systems of Non-Linear Equations.

Got Newton's method working with the guess given to it by Steepest Descent.

I had to extend the matrix library to add 2norm and transpose functions.
matrix.c    matrix.h

The code for the new library is here:06_SystemsNonLinearEq.c    06_SystemsNonLinearEq.h

Finally the example program to define the function is here:  06_SystemsNonLinearEq_HW.c

The system of 3 equations with three unknowns.  Followed by 9 derivatives with respect to X1, X2, and X3.
Steepest Descent gets close globally, but then only converges linearly, it would take hundreds or thousands of iterations to find the value to a few decimal places:
initial 0               0                     00  0.0112181743 0.0100963569 -0.5227407743 1 -0.0392975036 0.0960761555 -0.5230125588 

Once you have that initial guess then you can use Newtons method which converges in just a few iterations:
0 0.5002972122  0.0144515939 -0.5210250069 1 0.5000081616  0.0009138476 -0.5235749873 2 0.5000000378  0.0000041458 -0.5235986672 3 0.5000000000  0.0000000001 -0.5235987756 4 0.5000000000 -0.0000000000 -0.5235987756
If you aren't close with the initial value on Newton's method it may never converge to a value.

Most of the time in books for class the initial guess is just provided for you, our teacher went that extra 2 days of work to let us figure out the guess ourselves. Because nobody will give you that initial guess in the real world.

What I need to do now is to find the error and only stop once I have met the required accuracy.


I fixed a couple of issues with symbols in converting from math to the c programming language.  It wasn't clear that the quadratic was always 3 points, I was setting it to OrderSize points instead.  Fixed that.


Feeding solution back into formulas as an accuracy and final sanity check. :D
Modified the program so you can set how many iterations of steepest descent you want, with none as an option.  Ran into a homework problem where steepest descent just ran off into the wild blue yonder.


This is one of my homework problems that is due on Tuesday.  It is a 2nd order non linear system of equations.  As you can see in main() the system_new function defines the 2 order and the title.  Then the Jacobian functions are defined based on the derivatives of those functions for either x1 or x2.  When you are creating a derivative of a function on a variable, every other variable is treated like it was a constant.