Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- double (*funkcja)(double);
- double fx(double x) // x + 2
- {
- return x + 2;
- }
- double gx(double x) // x - 5
- {
- return x - 5;
- }
- double hx(double x) // x^2
- {
- return x*x;
- }
- struct Punkt
- {
- double x;
- double y;
- };
- double(*tabfun[3])(double) = {fx, gx, hx};
- Punkt minimum(double(*f)(double), double a, double b)
- {
- double szukany_x = a;
- double wartosc = f(a);
- for(double x = a; x <= b; x += .000001)
- if(f(x) < wartosc)
- {
- szukany_x = x;
- wartosc = f(x);
- }
- Punkt wynik;
- wynik.x = szukany_x;
- wynik.y = wartosc;
- return wynik;
- }
- int main(int argc, char* argv[])
- {
- if(argc != 4)
- {
- cout << "Niepoprawna liczba argumentow. Program zakonczy prace.\n";
- _getch();
- return -1;
- }
- Punkt wynik = minimum(fx, -5, 5);
- cout << wynik.x << ',' << wynik.y << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment