Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between a vector in maths and programming

Tags:

math

vector

Maybe this question is better suited in the math section of the site but I guess stackoverflow is suited too. In mathematics, a vector has a position and a direction, but in programming, a vector is usually defined as:

Vector v (3, 1, 5);

Where is the direction and magnitude? For me, this is a point, not a vector... So what gives? Probably I am not getting something so if anybody can explain this to me it would be very appreciated.

like image 793
mishmash Avatar asked May 29 '11 22:05

mishmash


People also ask

What is a vector in programming?

A vector, in programming, is a type of array that is one dimensional. Vectors are a logical element in programming languages that are used for storing a sequence of data elements of the same basic type. Members of a vector are called components.

What is the difference between math and programming?

One big reason that mathematics is much more like language than programming, is that doing mathematics involves resolving ambiguities. In programming you have a compiler/interpreter that just dictates how an ambiguity resolves. But in mathematics, as in real language, you have to resolve them yourself based on context.

What is the difference between a vector in math and in physics?

One difference is that physics vectors can be moved, math vectors can't. In elementary physics we don't usually have language that distinguishes between a vector and a vector field.

What is a math vector?

vector, in mathematics, a quantity that has both magnitude and direction but not position. Examples of such quantities are velocity and acceleration.


2 Answers

If we are working in cartesian coordinates, and assume (0,0,0) to be the origin, then a point p=(3,1,5) can be written as

enter image description here

where i, j and k are the unit vectors in the x, y and z directions. For convenience sake, the unit vectors are dropped from programming constructs.

The magnitude of the vector is

enter image description here

and its direction cosines are

enter image description here

respectively, both of which can be done programmatically. You can also take dot products and cross-products, which I'm sure you know about. So the usage is consistent between programming and mathematics. The difference in notations is mostly because of convenience.

However as Tomas pointed out, in programming, it is also common to define a vector of strings or objects, which really have no mathematical meaning. You can consider such vectors to be a one dimensional array or a list of items that can be accessed or manipulated easily by indexing.

like image 88
abcd Avatar answered Oct 07 '22 23:10

abcd


In mathematics, it is easy to represent a vector by a point - just say that the "base" of the vector is implied to be the origin. Thus, a mathematical point for all practical purposes is also a representation of a mathematical vector, and the vector in your example has the magnitude sqrt(3^2 + 1^2 + 5^2) = 6 and the direction (1/2, 1/6, 5/6) (a normalized vector from the origin).

However, a vector in programming usually has no geometrical use, which means you really aren't interested in things like magnitude or direction. A vector in programming is rather just an ordered list of items. Important here is that the items need not be numbers - it can be anything handled by the language in question! Thus, ("Hello", "little", "world") is also a vector in programming, although it (obviously) has no vector interpretation in the mathematical sense.

like image 22
Tomas Aschan Avatar answered Oct 07 '22 23:10

Tomas Aschan