Let me state my problem.
This is my main.c
and I have declared the structure vector as follows:
and the definition for the initialize_vect or() function is as follows:
and finally this is the code for the first_order_loc al_matrix() function:
The problem is that the first 3 calls for the initialize_vect or() from main() goes well. But when the initalize_vecto r() is called from first_order_loc al_matrix() I get a segmentation fault.
Any clues on what I am doing wrong here?
Thanks in advance.
This is my main.c
Code:
#include <stdio.h>
#include "includes/first_order_local_matrix.h"
int main()
{
float eps = 1;
struct vector *x, *y, *rho, *q;
struct matrix *P;
initialize_vector(x,3);
initialize_vector(y,3);
initialize_vector(rho,3);
x->values[0] = 0;
x->values[1] = 2;
x->values[2] = 0;
y->values[0] = 0;
y->values[1] = 0;
y->values[2] = 1;
rho->values[0] = 3;
rho->values[1] = 3;
rho->values[2] = 3;
first_order_local_matrix(x,y,rho,eps,P,q);
}
Code:
struct vector
{
float *values;
int length;
};
Code:
void initialize_vector(struct vector *vector_to_be_initialized, int length)
{
printf("Initializing Vector\n");
vector_to_be_initialized -> length= length;
vector_to_be_initialized -> values = malloc(length * sizeof(float));
printf("Initialized Vector\n");
}
Code:
void first_order_local_matrix(struct vector *x, struct vector *y, struct vector *rho, float epsilon, struct matrix *P, struct vector *q)
{
struct vector *b, *c;
float area;
int ii,jj,dim;
dim = x->length;
initialize_vector(b, dim);
initialize_vector(c, dim);
initialize_vector(q, dim);
initialize_matrix(P, dim,dim);
area = triangle(x,y,b,c);
for(ii=0; ii<dim; ii++)
{
for(jj=0; jj<dim; jj++)
P->values[ii][jj] = epsilon*area*(b->values[ii]*b->values[jj] + c->values[ii]*c->values[jj]);
q->values[ii] = area*(2*rho->values[ii] + rho->values[mod(ii,3)+1] + rho->values[mod(mod(ii,3)+1,3)+1])/12;
}
}
Any clues on what I am doing wrong here?
Thanks in advance.
Comment