What does Brexit mean?

The first thing that Teresa May wanted to make clear on becoming the Prime Minister of the UK, was that “Brexit means Brexit”. (e.g. Link to video). She has repeated this whenever asked about Brexit. During the G20 summit in Hangzhou China, she further explained in a press conference, “The reason I’ve been saying Brexit means Brexit is precisely because it means it does”.

To help anyone who still isn’t sure about what Brexit means I have written a computer program to illuminate you.

The output of the program is as follows:

Want to know what Brexit means?
y/n:y
‘Brexit’ means Brexit

Want to know what ‘Brexit’ means Brexit means?
y/n:y
”Brexit’ means Brexit’ means ‘Brexit’ means Brexit

Want to know what ”Brexit’ means Brexit’ means ‘Brexit’ means Brexit means?
y/n:y
”’Brexit’ means Brexit’ means ‘Brexit’ means Brexit’ means ”Brexit’ means Brexit’ means ‘Brexit’ means Brexit

Want to know what ”’Brexit’ means Brexit’ means ‘Brexit’ means Brexit’ means ”Brexit’ means Brexit’ means ‘Brexit’ means Brexit means?
y/n:y
””Brexit’ means Brexit’ means ‘Brexit’ means Brexit’ means ”Brexit’ means Brexit’ means ‘Brexit’ means Brexit’ means ”’Brexit’ means Brexit’ means ‘Brexit’ means Brexit’ means ”Brexit’ means Brexit’ means ‘Brexit’ means Brexit

Want to know what ””Brexit’ means Brexit’ means ‘Brexit’ means Brexit’ means ”Brexit’ means Brexit’ means ‘Brexit’ means Brexit’ means ”’Brexit’ means Brexit’ means ‘Brexit’ means Brexit’ means ”Brexit’ means Brexit’ means ‘Brexit’ means Brexit means?
y/n:

The code in Python3 is as follows:

# -*- coding: utf-8 -*-
"""
Created on Sun Sep 18 14:24:10 2016

Program to show what Brexit means.

@author: Mathew Peet
“””

str=”Brexit”
iWantToKnow = True

while iWantToKnow == True:
print(“Want to know what”,str,” means?”)
ans=input(“y/n:”)
ans = ans.lower()
if ans==’y’ or ans==’yes’:
str=”‘”+str+”‘”+’ means ‘+str
print(str,’\n\n’)
else:
iWantToKnow=False

 

screenshot-from-2016-09-18-154012

Advertisements

Octave/ Matlab is fun – Enter the Matrix

f = rot90((diag((ones(5,1)))) + hankel(zeros(5,1),2*(ones(5,1))),1)
warning: hankel: column wins anti-diagonal conflict
f =

0 2 2 2 3
0 0 2 3 2
0 0 1 2 2
0 1 0 0 2
1 0 0 0 0

hess(diag((ones(4,1))))
ans =

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

eig(diag((ones(4,1))))
ans =

1
1
1
1

diag([1,2,3],4)
ans =

0 0 0 0 1 0 0
0 0 0 0 0 2 0
0 0 0 0 0 0 3
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0

rot90(shift(rot90(rand(4),1),1),3)
ans =

0.141505 0.100645 0.200515 0.552900
0.163904 0.081520 0.505508 0.356016
0.458187 0.275491 0.472148 0.434868
0.988882 0.267269 0.680475 0.424024

My second g++/cpp program – Using a Makefile

I downloaded the example files from here:

http://www.cs.bu.edu/teaching/cpp/separate-compilation/

This demonstration explains how to compile using the make file. In this example you split up the program into separate modules, and use a make file to compile. This has the advantage that after making a change, only that part of the program needs to be recompiled.

Read the instructions on the web page, after downloading you need to edit Point.h to prevent it being included twice.

#ifndef POINT_H
#define POINT_H
/*
* File: Point.h
* Last Modified: January 31, 2000
* Topic: Modules, Separate Compilation, Using Make Files
* ----------------------------------------------------------------
*/

#include // one of two
using namespace std; // two of two, yay!

class Point
{
public:
Point();
Point(int xval, int yval);
void move(int dx, int dy);
int get_x() const;
int get_y() const;

private:
int x;
int y;
};

#endif

otherwise you will get the error:
g++ -c -o main.o main.cpp
In file included from Rectangle.h:13,
from main.cpp:9:
Point.h:13: error: redefinition of 'class Point'
Point.h:14: error: previous definition of 'class Point'

The files you download are: main.cpp, Makefile, Point.cpp, Point.h, Rectangle.cpp, Rectangle.h

and the Makefile looks like this:

# Makefile for Separate Compilation Example

# *****************************************************
# Parameters to control Makefile operation

CXX = g++
CXXFLAGS =

# ****************************************************
# Entries to bring the executable up to date

main: main.o Point.o Rectangle.o
$(CXX) $(CXXFLAGS) -o main main.o Point.o Rectangle.o

main.o: Point.h Rectangle.h

Point.o: Point.h

Rectangle.o: Rectangle.h Point.h

after running the make command you will have a bunch of object files (.o) and an executable. If you edit Rectangle.cpp and run make again then only Rectangle.o needs to be made again. The programs fragments of binary are linked by the .h header files.

if you run without preventing the multiple inclusion you get this error:

$ make
g++ -c -o main.o main.cpp
In file included from Rectangle.h:13,
from main.cpp:9:
Point.h:13: error: redefinition of ‘class Point’
Point.h:14: error: previous definition of ‘class Point’
make: *** [main.o] Error 1

After correction you get this:

$ make
g++ -c -o main.o main.cpp
g++ -c -o Point.o Point.cpp
g++ -c -o Rectangle.o Rectangle.cpp
g++ -o main main.o Point.o Rectangle.o

Edit Rectangle.cpp and run again; (e.g. open and save to update time, or just type “touch Rectangle.cpp“.


e$ make
g++ -c -o Rectangle.o Rectangle.cpp
g++ -o main main.o Point.o Rectangle.o

My first g++/cpp program

test.cpp is a text file containing:

#include

using namespace std;
int main()
{
cout<<"test test"<<endl;
return 0;
}

This is compiled using the command:
g++ -o test test.cpp

ftnchek

One tool I picked up from Clive Page’s Page on Fortran was ftnchek. This program is a static analyser. It enables checking or Fortran77 for semantic errors (rather than syntax errors), which usually aren’t reported by compilers. Once a Program compiles you can check for syntax errors by running ftnchek program.f

I found most of my errors are of this type.

    189             XTO400=XTO400+0.0001
                                 ^
Warning near line 189 col 26 file mucg83.f: promotion may not give desired
 precision: dble XTO400 + real const 0.0001

What I should have written is

            XTO400=XTO400+1D-04

Which means the fortran compiler knows the number involved is meant to be used in double precision. Since there is really no cost penalty to using ‘double’ precision rather than ‘single’ precision used with ‘Real’ numbers – and this might change depending on compiler.

I found the static analyser to be very useful for finding unused parts of a program, this might be useful to find errors, if you think those parts of the code are meant to do something! Or in cleaning up the code after making changes.

Installation
ftnchek can be downloaded from the ftnchek developers website, or installed in debian from the program repositories using apt-get, dselect or aptitude, etc.

ftnchek --version
FTNCHEK Version 3.3 November 2004 Patch Level 1

Magellan launch

The EPSRC National Service for Computational Chemistry Software (NSCCS) is pleased to announce the launch of its new machine, Magellan.

Magellan is a 224-core SGI Altix 4700, with 896GB of memory and 1TB of storage. You may not be aware that the service is also available for materials chemistry applications and supports the following codes;

CASTEP 4.0
CRYSTAL06
DL_POLY 2.17 and 3.07
SIESTA 2.0.1
GULP 3.1
CPMD 3.11.1
Quantum-ESPRESSO 3.1.1
NWChem 4.7

The NSCCS is particularly keen to attract experimental groups in the solid state area who might be interested in running simulations to help them analyse their results. These groups will be involved in a three-way collaboration with software support and hardware provided by the NSCCS, and additional scientific support provided by the Computational Materials Science group at the Daresbury and Rutherford Laboratories.

Any interested parties should contact the Service Manager, Dr Sarah Wilsey, for more information.

Further information about the NSCCS can be found on the Service website at http://www.nsccs.ac.uk.

Link to national computer centre: NSCCS.ac.uk
magellan computer

According to the statistics above the machine is having almost as much storage space in RAM as it is in the disk storage.

Using gnuplot for programming

Here’s an example script to calculate stuff in gnuplot. gnuplot is capable of many functions of the c programming language such as sin(x) erf(x). This is easy to extend since it is possible to define functions and perform logic.

Save this into a file calc.gnu and run with with command > gnuplot calc.gnu

# gnuplot script by Mathew Peet
# 18 February 2007
# Example script to calculate something
#
A = 1
B = 2
Answer = A + B
print "The answer: ", Answer

This could be used in conjunction with regression of data to do all sort of useful stuff.

List of supported functions

In general, any mathematical expression accepted by C, FORTRAN, Pascal, or BASIC may be plotted. The precedence of operators is determined by the specifications of the C programming language.

The supported functions include:
abs(x), acos(x), asin(x), atan(x), cos(x), cosh(x), erf(x), exp(x), inverf(x), invnorm(x), log(x), log10(x), norm(x), rand(x), sgn(x), sin(x), sinh(x), sqrt(x), tan(x), tanh(x).