To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 694b3e5c authored by Ignacio Labarca Figueroa's avatar Ignacio Labarca Figueroa
Browse files

Feedback Ex.2

parent 73642cc8
#include <iostream>
#include <vector>
/* Ignacio:
Looks good! Well done :)
Please register or sign in to reply
For the static approach:
Consider the case n > n_max
  • You mean only to print out something like "Insert a number n <= n_max". I just committed a change with this line.

Please register or sign in to reply
*/
int main() {
int n_max = 10;
......@@ -36,14 +43,14 @@ int main() {
std::cout << "Dynamic approach\n";
std::vector<double> vect;
double result = 0;
for(unsigned int i = 0; i < n; i++) {
double value;
std::cin >> value;
vect.push_back(value);
result += value;
}
// normalization
for (unsigned int i = 0; i < n; i++) {
vect[i] /= result;
......@@ -56,4 +63,4 @@ int main() {
std::cout << "\n";
return 0;
}
\ No newline at end of file
}
......@@ -3,6 +3,12 @@
#include <cassert>
#define _USE_MATH_DEFINES
/* Ignacio:
Did you test your Simpson rule?
  • I added a test_function that checks the integral from 0 to 1 of x*(1-x) and it seems good to me. Am I missing something?

Please register or sign in to reply
It seems that something is wrong when N is odd.
*/
double integration(double a, double b, int N, double (*my_func)(double x)) {
assert(N>0);
assert(b > a);
......@@ -20,4 +26,3 @@ double integration(double a, double b, int N, double (*my_func)(double x)) {
result += my_func(b);
return result*delta/3.0;
}
/* Ignacio:
Use const when it is possible!
Please register or sign in to reply
All of the arguments should be of this type
*/
double integration(double a, double b, int N, double (*my_func)(double x));
......@@ -10,4 +14,4 @@ double integration(double a, double b, int N, double (*my_func)(double x));
Post-conditions
- The result is the integral of the specified function in the interval [a,b]
*/
\ No newline at end of file
*/
Markdown is supported
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