I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » C/C++ »

I need help please

TheEnd\′s Photo
29 Oct 06, 10:13PM
(5 replies)
I need help please
I looked everywhere but didn't find clear help x.x

I need to make a program using gaussian function, which is also called bell curve. I need the program to receive the mean and standard deviaton and then request 4 points which are values for x and then display in a tabular format the x and the corresponding f(x) values. And all calculations must be done in a separate function and all results to be displayed in main.

Can anyone please help?
lucian\′s Photo
29 Oct 06, 11:17PM
Hi, have you seen this component?

http://www.codecogs.com/d-ox/stats/dists/continuous/normal/pdf.php

This is basically a component which returns the value of the gaussian function f(x) for given values of the mean and standard deviation. This module also contains some example code which may give you a hint on how to write your algorithm.

Please let me know if you have further questions.
TheEnd\′s Photo
30 Oct 06, 1:06AM
Yes, that does help. One problem I had was figuring out how to do the calculations, that does show it pretty well.

Now getting x and f(x) tabular format is another problem, I'll try to look for that.
TheEnd\′s Photo
30 Oct 06, 2:13AM
er wait, there is a library there from codecogs but this program has to be used with other people, then won't every person have to use that library but they won't have it...
lucian\′s Photo
30 Oct 06, 6:58PM
I see what you mean but since this component is licensed both under GPL and commercial terms, it will be no problem downloading a version for each person that will be using it. Just make sure the .h header file will be in the right folder so that the #include will work.

Have you managed to display the results in tabular format? I have come up with the following piece of code which I believe is an implementation of your algorithm.

#include <stdio.h>
#include <codecogs/stats/dists/continuous/normal/pdf.h>
 
// the number of points 
#define N 4
 
int main()
{
  double mean;
  printf("mean = "); scanf("%lf", &mean);
 
  double stdev;
  printf("standard deviation = "); scanf("%lf", &stdev);
 
  double x[N];
  printf("\nthe given points:\n\n");
  for (int i = 0; i < N; i++)
  {
    printf("x[%d] = ", i+1);
    scanf("%lf", &x[i]);
  }
 
  printf("\nfunction values:\n\n");
  for (int i = 0; i < N; i++)
    printf("x = %lf\tf(x)= %lf\n", 
    x[i], Stats::Dists::Continuous::Normal::PDF(x[i]));
  printf("\n");
 
  return 0;
}

Notice that you may change the number of points through the #define at the beginning of the code. Looking forward to your reply.

lucian\′s Photo
31 Oct 06, 3:33PM
Sorry, just forgot to include two essential parameters when making a call to the PDF function. This block of code, right after reading the user data

printf("\nfunction values:\n\n");
  for (int i = 0; i < N; i++)
    printf("x = %lf\tf(x)= %lf\n",
    x[i], Stats::Dists::Continuous::Normal::PDF(x[i]));
  printf("\n");

should obviously be changed into

printf("\nfunction values:\n\n");
  for (int i = 0; i < N; i++)
    printf("x = %lf\tf(x)= %lf\n",
    x[i], Stats::Dists::Continuous::Normal::PDF(x[i], mean, stdev));
  printf("\n");

You shouldn't have received any compiler errors since this function assigns mean = 0 and stdev = 1 implicitly, as for the standard normal PDF.

Currently you need to be logged in to leave a message.