#include #include #include #include #include #include std::function)> integrate(const std::function)>& input,double left, double right, double step = 0.001){ auto output = [=](std::vector v) -> double{ //wrapper function: integrates our function for given vector double result = 0; double left_l = left, right_l = left; while(right_l < right){ result += input(right_l, v); right_l += step; } result *= step; return result; //integration result for given vector }; return output; //now we may find integral for any vector given } int main(){ /*std::function)> func = [](double x, std::vector v) -> double{ return x*v.size(); }; std::cout << integrate(func,0,1,0.0001)(std::vector({2,4,6}));*/ //results are satisfactory, function works TCanvas* c = new TCanvas("canvas", "canvas"); c->Divide(2,2); c->cd(1); std::function)> func_exact_cos = [](double x, std::vector v) -> double{return x*TMath::Sqrt(x*x-1)*TMath::Cos(x*v[0]);};//1 std::function)> func_exact_sin = [](double x, std::vector v) -> double{return x*TMath::Sqrt(x*x-1)*TMath::Sin(x*v[0]);};//2 std::function)> func_urel_cos = [](double x, std::vector v) -> double{return x*x*TMath::Cos(x*v[0]);};//3 std::function)> func_urel_sin = [](double x, std::vector v) -> double{return x*x*TMath::Sin(x*v[0]);};//4 const int numpoints = 1000; // num of points in order to build graph double x[numpoints], y[numpoints]; // points in order to build graph double lim = 2; // defines graph area as [-lim, lim] //double rel_coeff[4]{5,10,20,40}; // relativistic coefficient == (U-M)/m_i - upper integration limit for(int index = 0; index < numpoints; ++index){ x[index] = -lim + lim*index*2.0/numpoints; y[index] = integrate(func_exact_cos, 1, 1+5)(std::vector({x[index]}))/integrate(func_urel_sin,1,1+5)(std::vector({x[index]})); } TGraph* gr1 = new TGraph(numpoints, x, y); gr1->SetMarkerStyle(21); gr1->SetMarkerSize(0.2); gr1->SetMarkerColor(kRed); gr1->Draw("APL"); /*for(int index = 0; index < numpoints; ++index) y[index] = integrate(func_exact_cos, 1, 1+5)(std::vector({x[index]}))/integrate(func_urel_cos,1,1+5)(std::vector({x[index]})); TGraph* gr2 = new TGraph(numpoints, x, y); gr2->SetMarkerStyle(22); gr2->SetMarkerColor(kGreen); gr2->SetMarkerSize(0.2); //gr2->Draw("PL");*/ //c->SaveAs("temp.pdf"); /*double a[4]{5,10,20,40}; for(int index = 0; index < 4; ++index){ c->cd(index+1); }*/ }