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

Feedback Ex.2

parent 73642cc8
#include <iostream> #include <iostream>
#include <vector> #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 main() {
int n_max = 10; int n_max = 10;
...@@ -36,14 +43,14 @@ int main() { ...@@ -36,14 +43,14 @@ int main() {
std::cout << "Dynamic approach\n"; std::cout << "Dynamic approach\n";
std::vector<double> vect; std::vector<double> vect;
double result = 0; double result = 0;
for(unsigned int i = 0; i < n; i++) { for(unsigned int i = 0; i < n; i++) {
double value; double value;
std::cin >> value; std::cin >> value;
vect.push_back(value); vect.push_back(value);
result += value; result += value;
} }
// normalization // normalization
for (unsigned int i = 0; i < n; i++) { for (unsigned int i = 0; i < n; i++) {
vect[i] /= result; vect[i] /= result;
...@@ -56,4 +63,4 @@ int main() { ...@@ -56,4 +63,4 @@ int main() {
std::cout << "\n"; std::cout << "\n";
return 0; return 0;
} }
\ No newline at end of file
...@@ -3,6 +3,12 @@ ...@@ -3,6 +3,12 @@
#include <cassert> #include <cassert>
#define _USE_MATH_DEFINES #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)) { double integration(double a, double b, int N, double (*my_func)(double x)) {
assert(N>0); assert(N>0);
assert(b > a); assert(b > a);
...@@ -20,4 +26,3 @@ double integration(double a, double b, int N, double (*my_func)(double x)) { ...@@ -20,4 +26,3 @@ double integration(double a, double b, int N, double (*my_func)(double x)) {
result += my_func(b); result += my_func(b);
return result*delta/3.0; 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)); 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)); ...@@ -10,4 +14,4 @@ double integration(double a, double b, int N, double (*my_func)(double x));
Post-conditions Post-conditions
- The result is the integral of the specified function in the interval [a,b] - 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