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?  http://www.cbsnews.com/news/who-were-the-4-us-citizens-killed-in-drone-strikes/  

How about the right of liberty? http://www.theguardian.com/world/2011/dec/15/americans-face-guantanamo-detention-obama   

How about the right to travel?  https://www.aclu.org/national-security/federal-court-sides-aclu-no-fly-list-lawsuit  

How about the right to own things? http://www.cato.org/events/policing-profit-abuse-civil-asset-forfeiture

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. (http://www.forbes.com/sites/adamhartung/2014/02/18/microsoft-should-give-xbox-one-to-nintendo/)

MS clusters on have 2 out of the top 500 super computers (http://en.wikipedia.org/wiki/TOP500). 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 (http://www.zdnet.com/the-biggest-cloud-app-of-all-netflix-7000014298/).  Every time you use Google, you are using one of the largest Linux clusters in the world with 25% of daily traffic (http://www.cnet.com/news/google-sets-internet-record-with-25-percent-of-u-s-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 (http://content.time.com/time/specials/packages/article/0,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 (http://linuxgizmos.com/embedded-developers-prefer-linux-love-android/).

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 (http://www.techrepublic.com/blog/linux-and-open-source/steam-box-will-bring-linux-to-the-masses/). 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.  (http://www.businessinsider.com/microsoft-to-cut-windows-xp-2013-4)

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 (http://thestute.com/2014/04/04/windows-8-still-massively-unpopular-nobody-is-surprised/comment-page-1/).  

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. 

Monday, March 24, 2014

N order systems of equations.

I updated my previous 2 order problem solver and 1 order problem solver to work with N order systems of equations, where N > 0 and < 100.  At N = 1 you are doing Runge-Kutta order 4 estimation.

You just have to set up all the equations and then pass them in along with an initial value for each one.  Your functions will be passed an array of long doubles in u[] from 0 to n-1.

Source code is here:
https://github.com/BuckRogers1965/Examples/blob/master/Math/NumericAnalysis/SysEqNOrderTest.c
https://github.com/BuckRogers1965/Examples/blob/master/Math/NumericAnalysis/SysEqNOrder.h
https://github.com/BuckRogers1965/Examples/blob/master/Math/NumericAnalysis/SysEqNOrder.c

First you create an object, setting it's start, end, steps per unit, and title.
Next you add Orders one at a time, with the initial value and function to use at that order.
One all the orders are entered, call the  calculate function to generate the results.
Then call the print function to output the results.
There are also methods to get the results programatically.
Finally dispose of the object and you are done.

Thinking about adding an actual result function that, if present, will print out with the results as the first column.

Friday, March 21, 2014

Estimating Systems of Higher-Order Equations

Evolving the Runge-Kutta method to solve higher-order equations is an interesting challenge. To get the first program working I did it in stages.  First the entire problem was in main, and I was happy to just get u1 and u2 sorted out.  After that I just got one iteration of the K1_1 - K4_2 sorted out, all eight values.  I found a couple of problems with my formulas and fixed them so that I got the same values as the example from the book.

The main loop was next.  I was able to loop through all 10 iterations without any problems because I took my time on that first iteration.  I printed out the results and it matched the output from the example in the book.  All that took about 4 hours.  It is tough to translate from a math book to a computer program, but I guess with practice one probably gets faster at it.

After that I wrapped the code in a C object and created an interface to the function.  I followed the same interface as the Runge-Kutta module I previously did.

I solved a homework problem as well, and print out the results from the actual function. 

The source code:

As I find problems in the code I will update the git repository.

Left to do:

This solves a specific order (order 2) of higher order problems.  To be truly general this should be made into a general function where you can add a function and matching initial values one at a time, then tell it solve all the levels, no matter how wide.

In that case this should solve when you tell it to print or try to pull out a value from the solved array.  It should not allocate the arrays for the work or the temp k values until you know how level of order you need.