Hi,
I need to understand the proper way to represent vector in C. Can any one give a hint for it.?
V = ui+vj+wk.
Thanks in advance
shiv
Hi,
I need to understand the proper way to represent vector in C. Can any one give a hint for it.?
V = ui+vj+wk.
Thanks in advance
shiv
The i, j, and k parts are unit vectors that depict the direction of each component of the vector.
Basically, represent a vector in C using a 1 dimensional array. In your case, an array of 3 elements. It's up to you to maintain how to index the components of the vector.
I don't understand the meaning of presenting and "my case is 3d" ?
And try to save i, j and k for your loops. Just a convention. Use x, y and z instead.
Thank you for the reply.
It means velocity is flowing in all three directions... Thank you
Is this simple code correct for representing a 3D vector?. If it is correct then I will develop the similar code to compute the velocity..Code:for(x=0;x<10;i++) { for(y=0;y<10;j++) { for(z=0;z<10;z++) { printf("%d", v[x][y][z]); } } }
shiv
You don't need a 3D array.
All vectors are 1 dimensional. Matrices are 2 dimensional.
a i + b j + c k is represented in vector form as (a, b, c) so all you need is :
All your doing in this case is using a 1D array to store your vector and we use an enumeration for intuitive indexing of the array.Code:#include <stdio.h> enum { x = 0, y = 1, z = 2 }; int main(void) { float v[3] = { 0 }; v[x] = 1.23; v[y] = 2.56; v[z] = 34.0; printf("v = { %f, %f, %f }\n", v[x], v[y], v[z]); return 0; }