Previous :
"Preamble"
Next
"Example :
Working with Matrices"
Tutorial
Working with Vectors
Download the source code and compile it - in the case of an installation in the own home directory - e.g. by :
gcc example1.c -O2 -march=athlon-xp -I $HOME/local/include -I $HOME/include/UMFPACK -L $HOME/local/lib $HOME/local/lib/libmeml.a -lm -llapack /usr/lib/libf2c.a -lumfpack -lamd -lcblas -lf77blas -latlas -o example1
/*
This is a small example how to do
vector manipulation and vector operations with meml
more functions are documented under
http://www.meml.smial.de/doc/group__meml__speichermanagent.html
http://www.meml.smial.de/doc/group__meml__vector__manipulation.html
and
http://www.meml.smial.de/doc/group__meml__vector__vector__operatoren.html
*/
# include "meml.h"
# define SIZE 10000
int main (void)
{
int i;
VECTOR *a, *b, *c, *d;
/* creating a vector of the dimension 10 filled with zeros */
a = meml_vector_new_zeros(10);
/* you can do the same by */
b = meml_vector_new(10);
/* and now create a vector filled with ones */
c = meml_vector_new_ones(10);
/* lets scale the last vector with 42 */
meml_vector_scaling_f(42,c);
/* now lets change a single element in a*/
/* most secure but quite slow via */
meml_vector_element_set (a, 5, -42);
/* a bit faster */
meml_vector_element_set_f (a, 6, -42);
/* or direct */
a->data[7] = -42;
/* this works well with vectors
do never try this with a matrix because you
can not be sure how the data is stored */
/* now add a to c and store the result in d */
d = meml_vector_add(a,c);
/* now add a to c and store the result in c */
meml_vector_add_f(a,c);
printf("now lets build the scalarproduct of a and c"
"which is %e \n",
meml_vector_scalarproduct(a,c));
printf("The norm of c is : %e \n",meml_vector_norm(c));
printf("The maximum norm of c is : %e \n",meml_vector_norm_max(c));
meml_vector_free(a);
meml_vector_free(b);
meml_vector_free(c);
meml_vector_free(d);
exit(EXIT_SUCCESS);
}
Previous :
"Preamble"
Next
"Example :
Working with Matrices"