Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mgoullie
sp4_exercises
Commits
f98a45ed
Commit
f98a45ed
authored
Oct 01, 2020
by
Guillaume Anciaux
Browse files
Merge branch 'master' of
ssh://c4science.ch/source/sp4e
into master
parents
ecbabdb3
05d4bdb3
Changes
15
Hide whitespace changes
Inline
Side-by-side
exercises/week2/float/sources-solution/CMakeLists.txt
0 → 100644
View file @
f98a45ed
cmake_minimum_required
(
VERSION 2.6
)
project
(
hello-exercise
)
add_executable
(
main main.cc
)
exercises/week2/float/sources-solution/main.cc
0 → 100644
View file @
f98a45ed
/* -------------------------------------------------------------------------- */
#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
;
}
exercises/week2/hello/sources-solution/CMakeLists.txt
0 → 100644
View file @
f98a45ed
cmake_minimum_required
(
VERSION 2.6
)
project
(
hello-exercise
)
add_executable
(
hello hello.cc series.cc
)
exercises/week2/hello/sources-solution/hello.cc
0 → 100644
View file @
f98a45ed
#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
;
}
exercises/week2/hello/sources-solution/series.cc
0 → 100644
View file @
f98a45ed
int
computeSeries
(
int
N
)
{
int
res
=
0
;
for
(
int
i
=
0
;
i
<=
N
;
++
i
)
{
res
+=
i
;
}
return
res
;
}
exercises/week2/hello/sources-solution/series.hh
0 → 100644
View file @
f98a45ed
#ifndef SERIES_HH
#define SERIES_HH
int
computeSeries
(
int
N
);
#endif
exercises/week2/pi/sources-solution/CMakeLists.txt
0 → 100644
View file @
f98a45ed
cmake_minimum_required
(
VERSION 2.6
)
project
(
hello-exercise
)
add_executable
(
main main.cc
)
exercises/week2/pi/sources-solution/launch.sh
0 → 100755
View file @
f98a45ed
#! /bin/bash
for
((
i
=
0
;
i < 7
;
++i
))
;
do
echo
-n
"10e
$i
"
./main 1e
$i
done
\ No newline at end of file
exercises/week2/pi/sources-solution/main.cc
0 → 100644
View file @
f98a45ed
/* -------------------------------------------------------------------------- */
#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
;
}
exercises/week3/stl/starting_point/CMakeLists.txt
0 → 100644
View file @
f98a45ed
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)
exercises/week3/stl/starting_point/main.cc
0 → 100644
View file @
f98a45ed
#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
;
}
exercises/week3/stl/starting_point/memory_first.cc
0 → 100644
View file @
f98a45ed
#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
;
}
exercises/week3/stl/starting_point/memory_second.cc
0 → 100644
View file @
f98a45ed
#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
;
}
exercises/week3/stl/starting_point/memory_third.cc
0 → 100644
View file @
f98a45ed
#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
;
}
exercises/week3/stl/sujet.pdf
0 → 100644
View file @
f98a45ed
File added
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment