Questions 10

  1. Where exactly are the files gsl_multimin.h and gsl_multiroots.h located in your box?

    Hint: gsl-config --cflags.

  2. Consider a Makefile,
    blahblah : data log ; for f in $^; do echo $$f:; cat $$f; done
    data log : Makefile ; echo $@ > $@
    clean    :          ; $(RM) data log
    
    What (and why) will it do and what (and why) will it build? Why double dollars in the first line?
  3. Suppose you run the command make main and it fails with diagnostics
    cc     main.c   -o main
    main.c:1:19: fatal error: gsl_sf.h: No such file or directory
    compilation terminated.
    
    Explain the error and how to correct it.

    Hint: clang returns the following diagnostics,

    clang     main.c   -o main
    main.c:1:9: fatal error: 'gsl_sf.h' file not found
    #include<gsl_sf.h>
            ^
    1 error generated.
    
  4. Suppose you run the command make main and it fails with diagnostics
    cc     main.c   -o main
    /tmp/cce2r3LL.o: In function `main':
    main.c:(.text+0x1e): undefined reference to `gsl_sf_gamma'
    collect2: error: ld returned 1 exit status
    
    Explain the error and how to correct it. Who is "ld" that returned exit status 1?
  5. Will this definition of f(t) work (and why)?
    #include"stdio.h"
    #include"math.h"
    int main(){
    	double A=3.5, T=3.2, B=1.2;
    	#define f(t) A*exp(-(t)/T)+B
    	for(double t=0;t<=5;t+=1) printf("%g %g\n",t,f(t));
    return 0;
    }
    
  6. Will this definition of f(t) work (and why)?
    #include"stdio.h"
    #include"math.h"
    int main(){
    	double A=3.5, T=3.2, B=1.2;
    	double f(double t){return  A*exp(-t/T)+B;}
    	for(double t=0;t<=5;t+=1) printf("%g %g\n",t,f(t));
    return 0;
    }
    
  7. Will this definition of f(t) work (and why)?
    #include"stdio.h"
    #include"math.h"
    #define f(t) A*exp(-(t)/T)+B
    int main(){
    	double A=3.5, T=3.2, B=1.2;
    	for(double t=0;t<=5;t+=0.1) printf("%g %g\n",t,f(t));
    return 0;
    }
    
  8. Will this definition of f(t) work (and why)?
    #include"stdio.h"
    #include"math.h"
    double f(double t){return  A*exp(-t/T)+B;}
    int main(){
    	double A=3.5, T=3.2, B=1.2;
    	for(double t=0;t<=5;t+=1) printf("%g %g\n",t,f(t));
    return 0;
    }
    
  9. Will this call to print_f_of_one work (and why)?
    #include"stdio.h"
    void print_f_of_one( double (*f)(double) ){printf("%g\n",f(1.0));}
    int main(){
    	double f(double x){return x+x;}
    	print_f_of_one(f);
    return 0;
    }
    
  10. Will this call to print_f_of_one work (and why)?
    #include"stdio.h"
    void print_f_of_one( double (*f)(double) ){printf("%g\n",f(1.0));}
    int main(){
    	#define f(x) (x)+(x)
    	print_f_of_one(f);
    return 0;
    }
    
  11. Explain the difference between
    echo 'gsl-config --libs'
    
    and
    echo `gsl-config --libs`
    
  12. Write a C-program that sends its command-line arguments to the standard output (that is, emulates the echo unix utility).