Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Circuit Theory/Convolution Integral/code

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

#include <iostream> #include <TF1.h> #include <TCanvas.h> #include <TAttLine.h> #include <TLegend.h> #include <TLegendEntry.h> #include <TLatex.h> #include <TGraph.h> //Instantiate the functions and graphs to be used //Their properties will be set later TF1 *func1; //The function to be translated TF1 *func2; //The Function to be reflected TF1 *func3; //The product of func1 and func2 TGraph *graph4; //The Resulting Convolution Graph //Set Precision of the Integrals (number of steps) Int_t precision = 100; //Create an animated gif? Bool_t createGIF = true; //Does the multiplication of the two functions Double_t multipliedFuncs(Double_t *x, Double_t *par){ Double_t xx = x[0]; Double_t f_x = func1->Eval(xx)*func2->Eval(xx); return f_x; }//End multipliedFuncs //Find the larger value between of the functions //This is used to shade the overlap region Double_t smallerValue(Double_t x){ //Evaluate the Functions Double_t val1 = func1->Eval(x); Double_t val2 = func2->Eval(x); if (val1 < val2) return val1; else return val2; }//End largerValue //Makes Graph 5 for each x position //Graph 5 is responsible for shading the overlap region TGraph *graph5 = new TGraph(); void makeGraph5(){ Double_t tempX =-10.0; Int_t point = 0; //Loop Over all values of x and find the overlap region to shade do { graph5->SetPoint(point, tempX, smallerValue(tempX)); tempX += 0.05; point++; } while(tempX < 10.0); }//End makeGraph5