## C language to calculate mean,variance

C language to calculate mean,variance
# 1
01-08-2008
C language to calculate mean,variance

Here I want to calculate mean,variance and sum from a file
1.1*2*4*22*211*22*12*22*22*11
2.2*2*22*12*22*11*11*122*33*22
3.9*7*22*88*87*98*67*66*56*66*11
As this is a large file and i am trying to write in c

where formulae of

MEAN = 1/N (X1...+..Xn)
Variance = square root of 1/N-1 (X1+.,,Xn - mean)2

So simply question say in this example we have one file where first part want to calculate mean and variance
again second part calculate mean and variance ..respectively and save the result

#include <math.h>
void moment(float data[], int n, float *ave, float *var)

{
void nrerror(char error_text[]);
int j;
float ep=0.0,s,p;
if (n <= 1) nrerror("n must be at least 2 in moment");

s=0.0;
for (j=1;j<=n;j++) s += data[j];
*ave=s/n;

what will be the code for variance?
Can rewrite the program with mentioning of open file and closing of file
Thanks
 cdfd123 View Public Profile for cdfd123 Find all posts by cdfd123
# 2
01-08-2008
 shamrock View Public Profile for shamrock Find all posts by shamrock
# 3
01-08-2008
Is this a homework assignment?? I keep reading posts with really "interesting" program requirements that seem to only have a theoretical benefit.
 frank_rizzo View Public Profile for frank_rizzo Find all posts by frank_rizzo
# 4
01-08-2008
Quote:
Originally Posted by frank_rizzo
Is this a homework assignment?? I keep reading posts with really "interesting" program requirements that seem to only have a theoretical benefit.
ask the source code for variance that i have got..
home work assignment only if u don't attempt on a problem and writing questions only....
sorry if bother
 cdfd123 View Public Profile for cdfd123 Find all posts by cdfd123
# 5
01-09-2008

Quote:
Here I want to calculate mean,variance and sum from a file
1.1*2*4*22*211*22*12*22*22*11
2.2*2*22*12*22*11*11*122*33*22
3.9*7*22*88*87*98*67*66*56*66*11
As this is a large file and i am trying to write in c
Are you trying to find the mean & variance of all the data points in the file or for every line of the file?

 shamrock View Public Profile for shamrock Find all posts by shamrock
# 6
01-09-2008
Quote:
Originally Posted by shamrock
Are you trying to find the mean & variance of all the data points in the file or for every line of the file?

Dear Shamrock,
Here trying to derive mean and variance for every line of the file Hereby each line is just say as separate entity.
That is In one file Input is
1.1*2*4*22*211*22*12*22*22*11 then derive its mean and variance
2.2*2*22*12*22*11*11*122*33*22 same derivations......
continue............etc.etc....
 cdfd123 View Public Profile for cdfd123 Find all posts by cdfd123
# 7
01-09-2008

Quote:
Originally Posted by cdfd123
Dear Shamrock,
Here trying to derive mean and variance for every line of the file Hereby each line is just say as separate entity.
That is In one file Input is
1.1*2*4*22*211*22*12*22*22*11 then derive its mean and variance
2.2*2*22*12*22*11*11*122*33*22 same derivations......
continue............etc.etc....
So let me see if I understand your post. You need the mean & variance for every line of input and every one of those input lines has ten data values separated by the asterisk character and the first data value is a floating point number like 1.1 2.2 yada yada...correct me if I am wrong.
The code you have posted does not seem to be able to compute the mean and variance of every line of input.
 shamrock View Public Profile for shamrock Find all posts by shamrock

Test Your Knowledge in Computers #317
Difficulty: Easy
Ada Lovejoy is often considered the first computer programmer.
True or False?

## Compare sum of two columns if variance is zero do nothing else send an email

11☺Hi, I have to data sets: One is in .txt format and other is in .csv format, please refer below two outputs from two files. File1.txt SOURCE PAYDATE TOTAL_DOLLARS RECORD_COUNT ASSET 05/25/2018 247643.94 ASSET 06/20/2018 ...

## Calculate

i have file input abcedef|wert|13|03|10|04|23|A1|13|05|01|09|31 fsdasdf|ferg|12|04|25|21|21|A1|13|02|26|20|31 dfsfsad|gerg|12|04|25|21|21|A1|13|02|25|25|31 i expect the output abcedef|wert|13|03|10|04|23|A1|13|05|01|09|31|9.516666667...

## AWK sample variance

I would like to calculate 1/n In awk, I wrote the following line for the sigma summation: { summ+=(\$1-average)^2 } Full code: BEGIN { Print "This script calculate error estimates"; sum=0 } { sum+=\$1; n++ } END { average = sum/n } BEGIN { summ=0 } { summ+=(\$1-average)^2 } END { print...

## Calculating Running Variance Using Awk

Hi all, I am attempting to calculate a running variance for a file containing a column of numbers. I am using the formula variance=sum((x-mean(x))^2)/(n-1), where x is the value on the current row, and mean(x) is the average of all of the values up until that row. n represents the total number...

## Awk total and variance

File1 0358 Not Visible ***:* NA:NA RDF1+TDEV Grp'd (M) RW 102413 0359 Not Visible ***:* NA:NA RDF1+TDEV N/Grp'd (m) RW - 035A Not Visible ***:* NA:NA RDF1+TDEV N/Grp'd (m) RW - 035B Not Visible ***:* NA:NA ...

## Calculate age of a file | calculate time difference

Hello, I'm trying to create a shell script (#!/bin/sh) which should tell me the age of a file in minutes... I have a process, which delivers me all 15 minutes a new file and I want to have a monitoring script, which sends me an email, if the present file is older than 20 minutes. To do...

## How To Calculate

I have 2 variables in my shell scripts in which i am using awk and calculating 2 files and getting 2 different variable called in_total and out_total. I want to subtract one variable from another so plz tell me how i can do that. Example is: cat in_file | awk -F: '{ in_total += \$1 * 86400...

## calculate time

Hi, How do I calculate time? I need to create an alert if a process is running more than 30 minutes. I need to get the first time and then get another, calculate it if more than 30 mins and then alert it to pager. Can't find it in internet. Thanks in advance, itik

## calculating variance in perl programming

#!/usr/bin/perl -w use strict; open(FH,"\$ARGV") or die; my @temp=<FH>; close FH; my \$mean = Mean(\@temp); my \$var = variance(\@temp); print "\$var\n"; sub estimate_variance { my (\$arrayref) = @_; my (\$mean,\$result) = (mean(\$arrayref),0); foreach (@\$arrayref) {...

## calculate output

I was wondering can anyone give me a clue how to start script which would do the following: I have 2 numbers as input for example: 100 and 1000 and I need to create file and in that file should be written 100 - 199 200 - 299 300 - 399 400 - 499 500 - 599 600 - 699 700 - 799...