Commit f98a45ed authored by Guillaume Anciaux's avatar Guillaume Anciaux
Browse files

Merge branch 'master' of ssh://c4science.ch/source/sp4e into master

parents ecbabdb3 05d4bdb3
cmake_minimum_required(VERSION 2.6)
project(hello-exercise)
add_executable(main main.cc)
/* -------------------------------------------------------------------------- */
#include <cstdlib>
#include <cmath>
#include <iostream>
/* -------------------------------------------------------------------------- */
void exo1(){
std::cout << "Exo1" << std::endl;
int a = 0.5;
std::cout << a << std::endl;
double b = 1/2;
std::cout << b << std::endl;
}
/* -------------------------------------------------------------------------- */
float tanh1(double x){
double res = (exp(x) - exp(-x))/(exp(x) + exp(-x));
return res;
}
float tanh2(double x){
double res = (1 - exp(-2.*x))/(1 + exp(-2.*x));
return res;
}
void exo2(){
std::cout << "Exo2" << std::endl;
int nstep = 10;
double dx = 1000./nstep;
for (int i = 0; i < nstep; ++i) {
double a = tanh1(dx*i);
double b = tanh2(dx*i);
std::cout << dx*i << " " << tanh(dx*i) << " "
<< a << " " << b << std::endl;
}
}
/* -------------------------------------------------------------------------- */
double tanh3(double x){
double res = ( -2.*exp(-2.*x))/(1 + exp(-2.*x));
return res;
}
double evolution(double pn, double v, double dt){
return pn + dt*v;
}
void exo3(){
std::cout << "Exo3.a" << std::endl;
int nstep = 10;
double dx = 1000./nstep;
for (int i = 0; i < nstep; ++i) {
double a = tanh3(dx*i);
std::cout << dx*i << " " << tanh(dx*i) -1 << " "
<< a << std::endl;
}
std::cout << "Exo3.b" << std::endl;
double a = 0;
double b = a + 1e-3;
double dt = 1e3;
double v = 3e8;
for (int i = 0; i < 40; ++i) {
double res = b - a;
std::cout << i << " " << res << " " << a << " " << b << std::endl;
a = evolution(a,v,dt);
b = evolution(b,v,dt);
}
}
/* -------------------------------------------------------------------------- */
int main(int argc, char ** argv){
exo1();
exo2();
exo3();
return EXIT_SUCCESS;
}
cmake_minimum_required(VERSION 2.6)
project(hello-exercise)
add_executable(hello hello.cc series.cc)
#include "series.hh"
#include <cstdlib>
#include <iostream>
/* -------------------------------------------------------------------------- */
int main(int argc, char **charv) {
int N = atoi(charv[1]);
int res = computeSeries(N);
std::cout << "Hello " << N << " res " << res << std::endl;
return EXIT_SUCCESS;
}
int computeSeries(int N) {
int res = 0;
for (int i = 0; i <= N; ++i) {
res += i;
}
return res;
}
#ifndef SERIES_HH
#define SERIES_HH
int computeSeries(int N);
#endif
cmake_minimum_required(VERSION 2.6)
project(hello-exercise)
add_executable(main main.cc)
#! /bin/bash
for ((i = 0 ; i < 7 ; ++i)); do
echo -n "10e$i "
./main 1e$i
done
\ No newline at end of file
/* -------------------------------------------------------------------------- */
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
/* -------------------------------------------------------------------------- */
int main(int argc, char ** argv){
unsigned long maxiter = atof(argv[1]);
float pi = 0.;
float pi2 = 0.;
for (unsigned long k = 1 ; k < maxiter ; ++k){
pi += 1./(1.*k*k);
unsigned long k2 = maxiter-k;
pi2 += 1./(1.*k2*k2);
}
pi *= 6.;
pi2 *= 6.;
std::cout << std::scientific << std::setprecision(15)
<< pi << " " << pi2 << " " << M_PI*M_PI
<< " " << pi - M_PI*M_PI << " " << pi2 - M_PI*M_PI << std::endl;
return EXIT_SUCCESS;
}
cmake_minimum_required(VERSION 2.6)
add_executable(main main.cc)
# add_executable(memory_first memory_first.cc)
# add_executable(memory_second memory_second.cc)
# add_executable(memory_third memory_third.cc)
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
/* -------------------------------------------------------------------------- */
int main(int argc, char ** argv){
return EXIT_SUCCESS;
}
#include <vector>
#include <array>
#include <memory>
#include <iostream>
int main() {
int values;
for (int& v : values)
v = 0;
for (int i = 0; i < 10; ++i)
std::cout << values[i] << " ";
std::cout << std::endl;
return 0;
}
#include <vector>
#include <array>
#include <memory>
#include <iostream>
std::vector<int>* stack_allocation(int n) {
return nullptr;
}
std::vector<int>* heap_allocation(int n) {
return nullptr;
}
int main() {
std::vector<int> * stack_values = stack_allocation(10);
std::vector<int> * heap_values = heap_allocation(10);
std::cout << stack_values->size() << ", " << heap_values->size() << std::endl;
return 0;
}
#include <vector>
#include <array>
#include <memory>
#include <iostream>
int main() {
auto unique = std::make_unique<std::vector<int>>(10);
std::unique_ptr<std::vector<int>> other = nullptr;
other = unique;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment