What Is Vector Trap?

Vector Algebra in C programming?

  • Ok so im writing A vector algebra package in C in order to solve some problems, but im having trouble with the vector algebra package. I need to write code for scalar product, dot product, and magnitude. Heres me source code just in case for reference. PLease help, i would really appreciate it, i cant go on and finish my assignment until get this part of it going. #include <stdio.h> #include <stdlib.h> #include "vector.h" vector vector_create_empty (int n) { vector* new_vector; new_vector = malloc(sizeof(vector)); new_vector->size = n; new_vector->element = malloc(n * sizeof(double)); return *new_vector; } vector vector_create(int n, double* values) { int i; vector* new_vector; new_vector = malloc(sizeof(double)); new_vector->size = n; new_vector->element = malloc(n * sizeof(double)); for(i=0; i<n; i++) new_vector->element[i] = values[i]; return *new_vector; } void print_vector (vector a) { int i; printf("["); for(i = 0; i<a.size-1; i++) printf("%lf ," , a.element[a.size-1]); printf("%lf]", a.element[a.size-1]); } vector vector_add (vector a, vector b) { if (a.size != b.size) { printf("\n Error in vector addition: the two vectors must have the same dimension\n"); exit(0); } int i; vector result; result = vector_create_empty(a.size); for(i=0; i<a.size; i++) result.element[i] = a.element[i] + b.element[i]; return result; } vector vector_subtract(vector a, vector b) { if (a.size != b.size) { printf("\n Error in vector addition: the two vectors must have the same dimension\n"); exit(0); } int i; vector result; result = vector_create_empty(a.size); for(i=0; i<a.size; i++) result.element[i] = a.element[i] - b.element[i]; return result; }

  • Answer:

    This is a very good question. I want to the answer too. buy darkfall gold www.selldarkfallgold.net

NHL FAN at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.