Cpsc 440 Problem Set 1 Question 2

Cpsc 440 Problem Set 1 Question 2 - hw1p2.h #ifndef HW1P2_H...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
hw1p2.h 2/13/2008 # ifndef HW1P2_H # define HW1P2_H typedef struct test_vector * test_vector ; test_vector newTestVector ( void ) ; void freeTestVector ( test_vector test_vec ) ; int read_data ( FILE * in , test_vector test_vec ) ; void process_data ( test_vector test_vec ) ; float library_calculator ( float x ) ; float taylors_calculator ( float x ) ; # endif 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
hw1p2.c 2/13/2008 # include < math . h > # include < stdio . h > # include < stdlib . h > # include "hw1p2.h" # define MIN_VECTOR_SIZE 10 # define ERROR_MARGIN 1e-18 struct test_vector { int num_data ; int capacity ; // x_values = values at which to evaluate F(X) // l_values = library values for F(X) // t_values = Taylor-series values for F(X) float * x_values ; float * l_values ; float * t_values ; } ; test_vector newTestVector ( void ) { test_vector test_vec = malloc ( sizeof ( struct test_vector ) ) ; test_vec - > num_data = 0 ; test_vec - > capacity = MIN_VECTOR_SIZE ; test_vec - > x_values = malloc ( test_vec - > capacity * sizeof ( float ) ) ; test_vec - > l_values = malloc ( test_vec - > capacity * sizeof ( float ) ) ; test_vec - > t_values = malloc ( test_vec - > capacity * sizeof ( float ) ) ; return ( test_vec ) ; } void freeTestVector ( test_vector test_vec ) { free ( test_vec - > x_values ) ; free ( test_vec - > l_values ) ; free ( test_vec - > t_values ) ; free ( test_vec ) ; } int main ( int argc , char * argv [] ) 1
Background image of page 2
hw1p2.c 2/13/2008 { // Extract the command-line arguments if ( argc ! = 3 ) { printf ( "\nERROR: %s expects 3 arguments, given %i\n" , argv [ 0 ] , argc ) ; return ( 1 ) ; } char
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/19/2008 for the course CPSC 440 taught by Professor Vladimirrokhlin during the Spring '08 term at Yale.

Page1 / 8

Cpsc 440 Problem Set 1 Question 2 - hw1p2.h #ifndef HW1P2_H...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online