Skip to content

About Scalar and Vector

December 5, 2009

Few Words

In my design of this calculator (although I am afraid it is evolving into language)

I made a decesion about making its types like the mathmatical numbering types

1- Scalar

2- Vector

3- Matrix

4- Tensor   (LATER LATER I HOPE)

The Scalar in Qs is  a normal  number with a unit.

(remember the idea of this calculator is that all numbers are quantities)

so Scalar in my programming model for now is  holding a quantity   which is number+unit

and ofcourse Vector is an array of Scalars

😀 the great thing I’ve discovered is that there are two Vector types

Vector Types

a) Euclidean Vector : This is only a three component vector

This Vector is always expressing the point in the space

It has the famous Cross Product Multiplication   (implemented in Qs as ‘x’ letter)

b) Normal Vector : This is an array holding a lot

This Vector is any number of components and can have Dot Product and

I am dealing with this types as a whole entity, I am not taking the approach of element by element calculation

because I am not convinced again about this approach :S

Multiplication Operators

So after great thinking and a lot of fancy shadows in my tiny room I made a three multiplication operators

1- Ordinary multiplication  ‘*’

2- Dot Product                          ‘.’

3- Cross Product                      ‘x’    <== YES it is the X letter 😀  [Who cares??!] my language after all 😀

Power Operators

and to make it worse I made a distinction between the three Power operators which are attached by meaning by their associated Multiplication operators

1- Ordinary Power              ‘^’

2- Dot Power                        ‘^.’               Which is different completely from the matlab ‘.^’ element power operator

3- Cross Power                   ‘^x’

Matrix Exponential

So you Remember about the sequence implementation

with sequence implementation I can make functions like sin, cos, and my famous Exponential sequence

Qs> e[n](x) ..> x^n/n!

then wrapping the sequence into a function call

Qs> e(x) = e[0++50](x)

This functions is working great in scalars

have you tried it with matrix ??

I tried it and succeed 🙂 look into this wikipedia page Matrix Exponential (by the way you should donate to wikipedia)

e^X = \sum_{k=0}^\infty{1 \over k!}X^k.

so if you passed a matrix to the function it will be treated as a whole matrix not element by element like matlab for example.

and this was an advantage from my model.

Power Dot

another funny thing is the ‘^.’ Power Dot when applying it to the vector.

by the way in any Power operation in Qs I get internally the first term to be Identity

for example in scalar it is 1<1>

Vector: {1<1> 1<1> … }   with the number of the components

Matrix Identity : Which is  diagonal ones  in a matrix with the same dimensions

\begin{array}{ccc}3 & 4 & 2\\7 & 4 & 3\\5 & 3 & 4\end{array}=\begin{array}{ccc}1\\& 1\\& & 1\end{array}

so when applying the Power dot to vector

first item  or zero repetion is the identity term, then by the power number I multiply the vector in the identity for repeat one and etc.

the funny thing is that dot product in vector gives a scalar value then scalar is multiplied by vector again to give a vector value then a scalar

so when you make a power dot to  an even exponent the result is vector, and when you make an odd exponent it will be scalar.

pretty strange 🙂

Relation Operators

Relation operators are <, >, <=, >=, ==, !=

ofcourse it is well known for scalars

but what about Vector and Scalar

I solved this issue by comparing the norm of the vector with the norm of the scalar

review Vector Norm so The comparison is based on Norm which is Absolute in Scalar and Magnitude in Vector.


As you can see implementing the Scalar, Vector , and Matrix as a first citizen entities in Qs is overwhelming

and a lot of challenges appeared.

however I hope that next post to be about my new innovative idea of the Comparison statement itself

see you 🙂


From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: