daily pastebin goal
4%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<cmath>
  3. #include<math.h>
  4. #include<conio.h>
  5. #include<iomanip>
  6.  
  7. #define PI 3.141592654
  8. using namespace std;
  9.  
  10. void gaussian_vals(double x[], double vals[], int length, double mean, double sig);
  11.  
  12. double gaussian(double x, double mean , double sig);
  13.  
  14. void main()
  15. {
  16.     double values,x[100],mean,sigma,vals[100]={0};
  17.    
  18.    
  19.    
  20.     cout<<"enter mean of gaussian"<<endl;
  21.     cin>>mean;
  22.  
  23.     cout<<"enter standard deviation of gaussian"<<endl;
  24.     cin>>sigma;
  25.    
  26.     cout<<"how many values to be entered? (max 100)"<<endl;
  27.     cin>>values;
  28.  
  29.     cout<<"enter values"<<endl;
  30.  
  31.         for(int i=0;i<values;i++)
  32.         {
  33.             cin>>x[i];
  34.         }
  35.  
  36.         gaussian_vals(x,vals,values,mean,sigma);
  37.  
  38.         for(int j=0;j<values;j++)
  39.             cout<<"gauss("<<x[j]<<")"<<setw(21)<<"="<<vals[j]<<endl;
  40.  
  41. }  
  42.  
  43. double gaussian(double x , double mean , double sig)
  44. {
  45.    
  46.    
  47.     double g=0;
  48.     double r =((x-mean)/sig)*((x-mean)/sig);
  49.     g = 1/(sig*sqrt(2*PI))*exp(-0.5*r);
  50.    
  51.     return g;
  52. }
  53.  
  54. void gaussian_vals(double x[], double vals[], int length, double mean, double sig)
  55. {
  56.  
  57.     for (int i=0;i<length;i++)
  58.    
  59.         vals[i]=gaussian(x[i],mean,sig);
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top