Tuesday, December 23, 2008

Trigonometry Identities

There a number of “identities” in trigonometry that can be found from the basic ideas of sin, cos and tan as explained in my earlier post. These identities can help in solving equations involving trig functions, especially when there are 2 or more different functions as the often allow you to write the equation in terms of one function, eg sin, that you can then solve.


One of the identities is:

sin2 + cos2 = 1.

To prove this consider a right angled triangle with side a,b and c as shown below



From this we can use Pythagoras theorem to say:

a2+b2=c2

now we know

sin t = b/c so b = csin t

cos t = a/c so a = ccos t


substituting these values in the above equation we get

(csint)2 +(ccost)2 = c2

canceling the c2 we get

sint2 + cost2 = 1




There are trig functions that are equal to 1 over sin, cos and tan called cosec = 1/sin, sec = 1/cos and cot = 1/tan. These can be remembered using the third letter rule as the third letter of each of these corresponds to the the function it is one over.




Using these a cos2 + sin2 = 1 we can calculate other identities

tan2t + 1 = sec2t

We can obtain this by dividing through by cos2 as we know sin/cos = tan, cos/cos = 1 and 1/cos = sec.

Other similar identities can be obtained for cosec and cot.

Wednesday, December 17, 2008

Economic Update 17th December

A lot has happened again in the economic world this week including :

· Today the administrators that have taken over Woolworths said that all stores will close by January 5th.

· Unemployment has risen to 1.86 million.

· The pound hit a low of 1.0796 euros.

· Opec is making an output cut of 2.2million barrels per day.

· Yesterday the US interest rates to between 0 and 0.25%.

· National express is to cut 750 jobs

But on the positive side inflation has fallen to 4.1% !!!

Thursday, December 11, 2008

Making Sense of the Economic Climate

Yesterday the Bank of England cut interest rates to 2% (lowest level since 1951) but is it actually going to help us.
It will help those who are struggling to pay our mortgages as repayments should become cheaper but not all banks are going to pass on the cut/ the cut in fall to customers. They are much quicker to pass on the cut to savers however.
Those without a mortgage and have savings are losing out, they did not borrow money they could not pay back yet they are the ones who are getting less income from their savings.
Earlier in the week VAT was cut by 2.5% was this the right decision? In my opinion no, this is not going to get people to start spending money again as people have no money. People are likely to buy the same and keep the savings to pay for other outgoings .
The retail sector is really starting to feel the pinch Woolworths, MFI and The Pier have all gone into administration and we could see many more go in the next few weeks/months.
I don’t think that the economic situation is going to get any better in the near future infact i think that it is going to get wose but hopefully we have all learnt a valuable lesson, do not borrow so much money! and let us not go back to our borrowing ways
Nicola crowston

Wednesday, December 10, 2008

Hyperbolic Functions

Hyperbolic functions are similar to sin,cos tan etc in trigonometry and share many similar rules. Usually hyperbolic functions are written like the trigonometric ones but with a h on the end, eg sinh and cosh.

The hyperbolic functions can be all written in terms of e, sinh and cosh are as follows

sinh(x) = (ex - e-x)/2
cosh(x) = (ex + e-x)/2

And tanh can be defined as sinh/cosh so

tanh = (ex - e-x) / (ex + e-x)

though this is often written as
tanh = (e2x - 1) / (e2x + 1)
by timesing the top and bottom by ex

the other other hyperbolic functions sinh as sech, coth etc can be found in the same way as they would be in trigonometry, by using 1 over the other functions, ie sech = 1/cosh

Most of the identities in trigonometry have a similar identity with hyperbolic functions, however in most of these whenever there is a sin2 it changes to a -sinh2
so
cosh2 - sinh2=1
which you can work out by placing the equations with e’s in the place of sinh and cosh

Friday, December 5, 2008

3D Graphics

This is a brief explanation of how to create basic 3D graphics. There are many different packages that will allow you to program using pre written 3D graphics library's, such as Java 3D but this is aimed at using and understanding the actual formula that can be used to draw the graphics yourself.

This assumes you are looking straight ahead from a single point and will map points in the 3D space in front of you onto a single plane at a fixed distance in front of you, probably 1 unit to keep it simple.

First of all consider the vertical direction, y axis. If we consider the right angled triangle formed by taking the line from you eye to the point, the line from your eye to beneath the point (ie the line where y =0) and the final verical equal to the y cordinate, we can use trigonometry to work out the height that need to be displayed.

From this we can work out the angle at your eye would be tan-1(y/(x2+z2))
This is because the length of the "opposite" is equal to the y co-ordinate and the adjacent can be found using pythagoras from the x and z co-ordinates.

We now can use the angle we have found to work out where the point needs to be displayed in our plane. Again we need to form a triangle similar to the first one but where the top corner is the final position of the point when it is projected. Ie the opposite is the y co-ordinate we need.
therefore,
y = tan(t)((x/z)2+1)
y=y((x/z)2+1)
(x2+z2)

Wednesday, December 3, 2008

Matrix Calculator, C++ Program

I recently went back to my c++ matrix calculator program and noticed it needed some improving so here are the improvements along with the source code.


Download the c++ matrix calculator here


Firstly I have added add/minus features to it. I accidentaly forgot to code these last time but have included them in the new program with the commands add and min. A note on the code, all the min function actually does is reverse all the signs on the second matrix and then call add.


I have also allowed you to determine both the number of rows and columns in the matrix to give it more flexibility. However this is not extended to the transformations (rotate and reflect) which still only work in 3 dimensions. Also in this process I have changed the lgth variable in the matrix to colls so that it now has rows and colls.


Finally to avoid some errors i have ensured all answer matrices are assigned colls and rows values.


Please feel free to use the program and don’t be put off by the fact it uses a command prompt, just type help to see the list of commands and when you type the command followed by enter it will give you step by step guidance on what to do.


David Woodford


// matrix.cpp : main project file.


#include “stdafx.h”

#include <iostream>

#include <cmath>

#include <string>

using namespace std;


class mat

{

public:

double mata[20][10];

int colls;

int rows;

void dimmat()

{

cout << “enter collums of matrix” << endl;

cin >> colls;

cout << “enter rows of matrix” << endl;

cin >> rows;

//    cout << “” << endl;


for(int n=0;n<rows;n++)

{

cout << “enter values for row” << n << ” , each followed by ‘enter’:” << endl;

for(int m=0;m<colls;m++)

{

cin >> mata[n][m];

}

}

}


void display()

{

int rcount = 0;

int ccount = 0;


while(rcount < rows)

{

while(ccount < colls)

{

//cout << “matrix:”<<endl;

cout << mata[rcount][ccount] << ” , “;


ccount++;

}

cout << ‘\n’;

ccount=0;

rcount++;

}

}


/*void rotate()

{

mat mat2;

mat2.dimmat();

mat mat3;

mat3 = mult(this, mat2);

}*/

};


mat mult(mat A, mat B)

{

cout << “multiply started” << endl;


//char pause;


mat ans;

ans.colls=B.colls;

ans.rows=A.rows;


int rcount = 0;

int ccount = 0;

int c2 = 0;


while(rcount < 3)

{

//cout << “row: ” << rcount << ” started” << endl;

while(ccount < A.colls)

{

//cout << “collum: ” << ccount << “started” << endl;


ans.mata[rcount][ccount] = 0;

while(c2 < A.rows)

{

ans.mata[rcount][ccount] = ans.mata[rcount][ccount] + (A.mata[rcount][c2] * B.mata[c2][ccount]);

c2++;

}

//cout << “value is: ” << ans.mata[rcount][ccount] << endl;

//cin >> pause;

c2=0;

ccount++;

}

ccount=0;

rcount++;

}


if(A.colls != B.rows)

{

cout <<”matrices are wrong sizes to be multiplied” << endl;

return A;

}

else

{


ans.display();

return ans;

}

}


mat add(mat A, mat B)

{

mat ans;

if(A.colls == B.colls && A.rows == B.rows)

{

ans.colls = A.colls;

ans.rows=A.rows;

int i = 0;

int j = 0;

while(i < ans.colls)

{

j=0;

while(j<ans.rows)

{

ans.mata[i][j] = A.mata[i][j] + B.mata[i][j];

j++;

}

i++;

}

return ans;

}

else

{

cout << “matricies cannot be added : diffrent lengths” << endl;

return A;

}

}


mat minus(mat A, mat B)

{

int i =0;

int j =0;

while(i<B.colls)

{

while(j<B.rows)

{

B.mata[i][j] = 0 - B.mata[i][j];

j++;

}

j=0;

i++;

}

return add(A,B);

}

mat rotate(mat A, int angle)

{

mat T;

T.colls = 3;


mat matans;


//creat transformation matrix

double pi = 3.14159265;

double theta = (angle*pi)/180;

T.mata[0][0] = cos(theta);

T.mata[0][1] = 0 - sin(theta);

T.mata[0][2] = 0;


T.mata[1][0] = sin(theta);

T.mata[1][1] = cos(theta);

T.mata[1][2] = 0;


T.mata[2][0] = 0;

T.mata[2][1] = 0;

T.mata[2][2] = 1;


matans = mult(T, A);

return matans;

}


mat reflect(mat A, int angle)

{

mat matans;

mat T;

T.colls = 3;

//creat transformation matrix

double pi = 3.14159265;

double theta = (angle*pi)/180;

T.mata[0][0] = cos(2 * theta);

T.mata[0][1] = sin(2 * theta);

T.mata[0][2] = 0;


T.mata[1][0] = sin(2*theta);

T.mata[1][1] = 0 - cos(2*theta);

T.mata[1][2] = 0;


T.mata[2][0] = 0;

T.mata[2][1] = 0;

T.mata[2][2] = 1;


matans = mult(T, A);

return matans;

}


void input()

{

string dim = “dim”;


string com;

int end = 0;


mat matans;

int matcount = 0;

mat mats[11];

while(end == 0)

{

cout << “enter command>”;

getline(cin, com);


if(dim == com)

{

cout << “matrix” << matcount <<endl;

mats[matcount].dimmat();

matcount++;

}

if(com == “rot”)

{

cout << “which matirx?” <<endl;

int matnum;

cin >> matnum;

cout << “what angle (degrees)” << endl;

int rotang;

cin >> rotang;

matans = rotate(mats[matnum], rotang);

mats[10] = matans;

}

if(com == “rlt”)

{

cout << “which matirx?” <<endl;

int matnum;

cin >> matnum;

cout << “what angle (degrees)” << endl;

int rotang;

cin >> rotang;

matans = reflect(mats[matnum], rotang);

mats[10] = matans;

}

if(com == “ans”)

{

matans.display();

}

if(com == “mlt”)

{

cout << “first matrix” << endl;

int mat1;

cin >> mat1;

cout << “second matirx” << endl;

int mat2;

cin >> mat2;


matans = mult(mats[mat1], mats[mat2]);

mats[10] = matans;

}

if(com == “add”)

{

cout << “enter first matrix” << endl;

int A;

int B;

cin >> A;

cout << “enter second matrix” << endl;

cin >> B;


matans = add(mats[A],mats[B]);

mats[10] = matans;

matans.display();


}

if(com == “min”)

{

cout << “enter first matrix” << endl;

int mata, matb;

cin >> mata;

cout << “enter second matrix” << endl;

cin >> matb;


matans = minus(mats[mata], mats[matb]);

mats[10] = matans;

matans.display();

}

if(com == “dsp”)

{

cout << “which matirx?” << endl;

int matdsp;

cin >> matdsp;

mats[matdsp].display();

}

if(com == “let”)

{

cout << “which matirx?” << endl;

int mat1;

cin >> mat1;

int mat2;

cout <<”eaqual to (10 is answer matrix)” << endl;

cin >> mat2;

mats[mat1] = mats[mat2];


}

if(com == “help”)

{

cout <<”Davids Woodfords matrix calculator” << endl;

cout << “takes the following commands” << endl;

cout <<” ‘dim’    ::  allows you to dfine a matrix”<< endl;

cout <<” ‘rot’    :: roates a matrix through an agnle” << endl;

cout <<” ‘rlt’    :: reflects a matrix through the line y=tan(a) where a is given” << endl;

cout <<” ‘ans’    :: displays the answer to the last calculation” << endl;

cout <<” ‘mlt’    :: lets u multiply 2 matricies together” << endl;

cout <<” ‘dsp’    :: displays a matrix specified”<<endl;

cout <<” ‘let’    :: allows u to assign one matrix the value of another, eg answer”<<endl;

cout <<” ‘add’    :: lets u add 2 matricies together” << endl;

cout <<” ‘min’    :: lets u minus 2 matricies together” << endl;

cout<<”===================================================================”<<endl;

cout <<”matricies are sotred in an array of 10, with numerical values starting at 0″<<endl;

cout<<”matrix 10 is the answer matrix”<<endl;

cout<<”any parameters will be asked for wen needed”<<endl;


}

}


}


int main()

{

cout << “Welcome to David Woodfords Matrix calculator” << endl << endl;

cout<<”type ‘help’ for a list of commands” <<endl;

//    mat mata;

//    mata.dimmat();


/*    mat matb;

matb.dimmat();


mat matans;

matans = mult(mata, matb);

//    mata.display();

*/

//rotate(mata, 30);

input();

return 0;


}

Tan=Sin/Cos

this site is now at www.breakingwave.co.nr


This is often useful when solving trig equations so i thought i’d include it


basically:


sin = opp/hyp

and

cos=adj/hyp


so


sin/cos = (opp/hyp)/(adj/hyp)


so if we cancel the hyp’s we get


sin/cos = opp/adj


and since tan = opp/adj


tan = sin/cos

Sine and Cosine Rules

This is the basics of the sine cos and tan graphs and how sine and cos relate to give you tan. It also shows how to differentiate sin and cos.


The output or range of both sine and cos is from -1 to 1 when given any angle. They can be shown on a graph where y = sin(x) and y = cos(x). In these graphs all the angles go along the x axis and you can see a wave type shape is formed


Sine Graph

graph of y=sin(x)


Cosine Graph

cosine graph


As you can see both the sin and cos graphs move periodically between -1 and 1 as the angles change, this pattern continues indefinitely because once you pass 360 degrees or 2 pi radians you will return back to the beginning. If you try to perform sin-1 of a value out side the range -1 to 1 you will get an error.


Differentiate Sin and Cos

also notice that the gradient of the sin graph is the value of the cos graph for the same angle and that the gradient of the cos graph is the -value of the sin graph for that angle. This means that we can differentiate the sin and cos graphs:

if f(x) = sin(x) then f ‘ (x)=cos(x)

and

if f(x) = cos(x) then f ‘ (x) = -sin(x)


however if we use ax instead of x we must differentiate it by bringing the a out, when its just x this doesn’t matter as the differential of x is 1.

ie)

let y = sin(f(x))

now let u = f(x)

du/dx = f ‘ (x)

also

y=sin(u) as u = f(x)

dy/du = cos(u)


from the chain rule


dy/dx = du/dx * dy/du

therefore

if y = sin(f(x))

dy/dx = f ‘ (x)cos(f(x))


and similarly for cos

if y = cos(f(x))

dy/dx = -f ‘ (x)sin(f(x))

Area and Circumference of a Circle: pi

This is a basic guide to using pi to find the area and circumference of a circle using pi. And also explores why pi makes our formulea work.


Circle radius and circumference


area =πr2


circumference = 2πr or πd


where r = radius and d=diameter


Area


First lets look at the area of a circle, given by area =πr2. This is simple enough to use, we multiply the radius by itself and then by pi.

Does this make sense?

Well r squared is at least going to be an area but it might be a bit small so we multipy by pi. However this doesnt explain much untill we consider what pi is, the easiest way i find to do this is as follows




If we imagine a square that the circle fits inside perfectly(so it touches all four sides like the one above) r squared would give us one quadrant, so the area of that square is 4 x r2 . Of course the circle’s area is a bit smaller so we need to find the ratio between the areas of the square and circle. If we then times this value by four we have a magic constant to multiply r squared by to find the area of a circle (we times by four because we need the area of 4 quadrants and r squared gives us one).

Now this magic constant is pi (which makes sense being just over 3, meaning the area of the circle is just over 3/4 of the area of the square).

Circumference

The circumference of a circle is given by 2πr or πd. This seems simple, we just multiply the diameter (2r) by our magic constant pi.


Does this also make sense?

seeing as we only have one r this time so only one length it seems we are just finding a factor to increase the length by to make a different length(the circumference) which makes sense.

Again lets consider the square into which our circle fits perfectly, the perimeter of this square would be 4 time the length of one of the sides.

Now the length of the sides = the diameter so the perimeter is 4d.

Notice again that the value we are trying to find for the square is multiplied by 4, but for a circle were gonna need a ratio thats a bit smaller.

So we need to replace the 4, for a square, with another, smaller, number — it seems pi will do the job.

Conclusion

To me when i consider pi i don’t look at it as a magical fundamental constant, but more a magical fundamental constant multiplied by four, because when I consider how these formula work using pi this is how they seem to work.

So this new constant is really the ratio of

area of square to area of circle

perimeter of square to circumference of circle.

and it = pi/4 = 0.785398….

so if you have a value for a square and you want a similar value for the circle you just need to multiply it by this number and you’ll have your answer :)



I welcome comments, improvements or errors in this post. Please leave your comments below or email me at woodford_4@hotmail.co.uk

thanks

Ellipse’s: equation, foci, eccentricity

The equation of ellipse is usually written in one of 2 ways, as a parametric equation or as a Cartesian equation are as follows


P(h +a cos t ,k+ b sint), Where P is a point of the ellipse


or



where h and k are the amount the center of the ellipse is offset from the origin in the x and y directions and a and b the points on the x and y axis where the ellipse cuts.


An ellipse has to focal points (+/- ae) and can be defined as the loci of all the points P such that the sum of the distances from P to each focal point is constant.


The eccentricity of an ellipse e defines how sharp the ends of it are. e is always < 1 and can be calculated from the equation b2 = a2(1-e2).


The directrices of an ellipse are x = ±a/e. These are lines such that the ratio of the distance from every point P on the ellipse from the directic and foci is the constant e, the eccentricity of the ellipse.


For example at the point (a,0) on the ellipse the distance to the directirc is

a/e - a = a(1/e - 1) = a(1-e)/e

and the distance from the ellipse to the foci is

a - ae= a(1-e)

the ration of these is

a(1-e)

a(1-e)/e

which equals e


and for any point p,

the distance to the directric is

a/e - acost = a(1/e - cost) = a(1-ecost)/e

when squared becomes

a2cost(e2cost-2e)+a2

e2


the distance to the foci is


√{(acost-ae)2 + b2sin2t}

which with substitution for b given above becomes

a2cost(e2cost-2e)+a2


hence the ratio of the square of these 2 distances e2 so the ratio of the distances themselves is e


Post by David Woodford, also avalible at www.breakingwave.co.nr