B
Bill Cunningham
I have some code here and a snippet of unfinished, untested code which
is an attempt at a function called stddev. This is of course meant to
calculate a standard deviation. I am trying to build small helper functions
that can be built into tech analysis tools. Something I've been attempting
and thinking about for a long time. stddev's first parameter is passed the
return value of the function mean(). It may not need a second parameter but
this is what I have so far. stddev needs to do the following things.
1) find the difference in prices from mean. Whether negative of positive
numbers.
2) square those numbers
3) sum those squares
4) calculate the square of the total from 3 above.
header called "tech.h"
#include <stdio.h>
#include <stdlib.h>
#ifdef M
#include <math.h>
#endif
double mean(double *, int);
double stddev(double, double *);
mean.c
#include "tech.h"
double mean(double *avg, int num)
{
double sum, average;
int i;
sum = average = 0;
for (i = 0; i < num; ++i) {
sum = sum + avg;
average = sum / num;
}
return average;
}
stddev.c /*the attempt*/
#include "tech.h"
double stddev(double mean, double *prices)
{
double price = 0.0;
int i = 0;
for (; i < prices; ++i) {
if (prices > mean) {
price = prices - mean;
return prices;
} else if (prices < mean) {
price = mean - prices;
return prices;
}
I really have no way to code this but I don't want anyone to do my
homework. Can someone offer tips or citations as to what I might need to do
here?
Bill
is an attempt at a function called stddev. This is of course meant to
calculate a standard deviation. I am trying to build small helper functions
that can be built into tech analysis tools. Something I've been attempting
and thinking about for a long time. stddev's first parameter is passed the
return value of the function mean(). It may not need a second parameter but
this is what I have so far. stddev needs to do the following things.
1) find the difference in prices from mean. Whether negative of positive
numbers.
2) square those numbers
3) sum those squares
4) calculate the square of the total from 3 above.
header called "tech.h"
#include <stdio.h>
#include <stdlib.h>
#ifdef M
#include <math.h>
#endif
double mean(double *, int);
double stddev(double, double *);
mean.c
#include "tech.h"
double mean(double *avg, int num)
{
double sum, average;
int i;
sum = average = 0;
for (i = 0; i < num; ++i) {
sum = sum + avg;
average = sum / num;
}
return average;
}
stddev.c /*the attempt*/
#include "tech.h"
double stddev(double mean, double *prices)
{
double price = 0.0;
int i = 0;
for (; i < prices; ++i) {
if (prices > mean) {
price = prices - mean;
return prices;
} else if (prices < mean) {
price = mean - prices;
return prices;
}
I really have no way to code this but I don't want anyone to do my
homework. Can someone offer tips or citations as to what I might need to do
here?
Bill