Ryan Harrison My blog, portfolio and technology related ramblings

Free GitHub Micro Plan for Students

GitHub is a great service that I use often to host my personal projects. Their free accounts offer an unlimited number of public repositories where your code is visible to anyone visiting your profile. This is great for any open source work, but not so good for coursework projects where you really want to keep your source code private (at least until the deadline).

Handily though, if you are a student GitHub will give you a free Micro plan for a few years to help in your studies. This plan comes with 5 private repositories and of course you are still able to create an unlimited number of public ones.

All you need is a valid academic email address that has been added to your GitHub and you are good to go.

Sign yourself up here: https://github.com/edu

Read More

[Link] Everything About Java 8

As the release of Java 8 looms ever closer and closer, here is some good information about what new changes to expect. Unlike Java 7 this release does seem to actually include some useful features including lambda’s which can be neatly integrated with the new streams API and a much needed new date/time API.

Everything About Java 8

Read More

Chrome Resolving Host Fix

So recently I came up against the ‘Resolving Host’ problem in Chrome that temporarily grinds the browser to a complete halt. There seems to be a lot of people who are having the same problems, yet no real solution that works for any substantial amount of time.

The current fixes take the form of unchecking the ‘Predict network actions to improve page load performance’ checkbox under the advanced settings section of Chrome. On a completely updated system, for me however, this didn’t seem to work.

After a ton of searches and many trials I think I’ve found a solution that really works (well for me anyways):

Disable the ‘Built-in Asynchronous DNS’ functionality of Chrome by:

  1. Navigate to chrome://flags
  2. Find Built-in Asynchronous DNS (about halfway down the page)
  3. Disable it and then restart Chrome

I’ve been using this fix for over a month now and the problem seems to have disappeared completely.

Read More

Java - A better Hello World program?

For years now this has been the Java version of the famous ‘Hello World’ program that is often the very first program that new developers write:

  
public class HelloWorld {  
    public static void main(String[] args) {  
        System.out.println("Hello World!");  
    }  
}  

But is this a really the kind of code beginners should be seeing when they begin the Java adventures - putting all the logic in the main method and making no use of object oriented practices? Surely it would be better to drive in the fundamental OOP principles from the very start? You see all too much people using loads of static methods and calling them all in their main method which by now spans a good few hundred lines of code. Maybe they get this idea from this ‘Hello World’ program?

If we are really following object oriented programming practices (which Java tries so hard to enforce), the ‘Hello World’ program should really look more like this:

  
public class HelloWorld {  
    public static void main(String[] args) {  
        new HelloWorld().printHelloWorld();  
    }

    public void printHelloWorld() {  
        System.out.println("Hello World!");  
    }  
}  

Now we are suddenly using classes and methods! Ok it’s a little more complicated for complete beginners to learn, but at least it gives the teachers more to talk about rather than trying to avoid the inevitable questions about the static keyword and that String[].

Traditionally the ‘Hello World’ program is normally the shortest amount of code possible to generate the necessary output. That’s fair enough and the first example does this fine, but for teaching practices the second program is so much better. Classes/methods are amongst the hardest concepts to teach new programmers so why not begin that journey from the very beginning? A lot of new Java developers try to force procedural code into a purely object oriented language. Most of the time it doesn’t end well at all. Maybe this could be avoided by skipping the whole concept entirely (the static keyword is the main culprit). Everything should be inside methods of a class - of which objects should be created and those methods called with them. Hopefully the main method would then never grow into a hundred line mess of logic.

Just a suggestion to any Java teachers out there. Although a little harder to teach, in my experiences I reckon this could be a pretty helpful change in the long run.

Read More

Java - Math Engine

This project is something that I have been working on practically since I started programming in Java. It’s been through a load of changes through the years, and in some cases complete rewrites. It started out as a simple stack based expression parser and evolved to use regular expressions and again into its current state which uses expression trees and a recursive descent parser. The expression parser has also been joined with many other packages to create the full mathematical library as it is today.

The full source code for the library is available in the GitHub repository.

Guide

A mathematical library complete with an advanced expression parser with custom functions and support for Vectors and Matrices. Includes packages for symbolic differentiation, numeric integration, equation solving, unit conversions and much more.

Functions

The Function class provides a common interface into many packages of this library. A Function models an equation of one variable that maps to a resulting Y value. To create a basic Function object use the constructor that takes a single String argument representing the desired equation:

Function function = new Function("x^2 + 8*x + 12");

To create more customised Functions, use the overloaded constructors where you can define the variable and the angle units that will be used when calculating any trigonometric values in the function:

Function function = new Function("x^2 + 8*x + 12", "x", AngleUnit.Radians);

By default the Function will have a variable of x and will use Radians if they are not explicitly specified in the constructor.

Once and instance of the Function class is created, you also have the ability to evaluate the function at a specified point (any instances of the variable will become the specified value during evaluation). For example:

Function function = new Function("x^2 + 8*x + 12");
double result = function.evaluateAt(12.5);

OUTPUT -
268.25

You can also evaluate the equation at another expression. This is better explained in an example:

Function function = new Function("x^2 + 8*x + 12");
double result = function.evaluateAt("6 + 6.5");

OUTPUT -
268.25

Differential

The differential package includes classes to both symbolically and numerically differentiate Function instances. Numeric differentiation will only allow you to differentiate at a certain point (giving the value of the derivative at this point). Conversely symbolic differentiation will return a new Function object representing the exact derivative to the Function. This resulting Function can then be evaluated as above to get the a value at a certain point (as in numeric differentiation).

Numeric

Function function = new Function("x^2 + 8*x + 12");
DividedDifferenceMethod method = new DividedDifferenceMethod(function, DifferencesDirection.Central);

In this example a Function is first created by which the deriviatives values will be calculated. Then a new instance of a DividedDifferenceMethod differentiator is created that uses the the Finite Difference method with central equations. A result of the first derivative at the point 3.5 can be obtained by:

method.setTargetPoint(3.5);
double derivative = method.deriveFirst();

OUTPUT - 
15.000000000000213

Values can change depending on the supplied value of h (the difference). By default the value is 0.01. Other classes are available that can yield more accurate results in certain circumstances are also available which include the ExtendedCentralDifferenceMethod (more accurate than standard differences as above) and RichardsonExtrapolationMethod (which again can yield more accurate results).

The numerical methods only give estimates of the derivatives and in some cases may be wildly inaccurate. However for most well formed, continuous functions, and a sensible value of h, a reasonably accurate answer can be obtained. For exact results consider the symbolic package.

Symbolic

The symbolic differentiation package offers support to obtain exact derivatives of Function objects. Instead of returning a double value of the derivative at a certain point (as in the numeric package), the symbolic package returns a new Function object representing the exact derivative function. This can then be evaluated to get the derivative at a certain point:

Function function = new Function("x^2 + 8*x + 12");
Differentiator differentiator = new Differentiator();
Function derivative = differentiator.differentiate(function, true);
derivative.evaluateAt(3.5);

OUTPUT -
f(x) = 2*x+8
15.0

As you can see the symbolic differentiator returns a Function representing the equation of the derivative, which in this case is 2*x + 8. This function is then evaluated at the some point 3.5 to get an answer of 15. Note how this result is exact and without the small error retrieved from the numeric method of differentiation.

Read More