cdfd123 has asked for the wisdom of the Perl Monks concerning the following question:
any suggestionsA)1.8 2.5 3.8 1.9 -3.5 -3.5 3.2 -3.9 4.2 4.5 2.8 B)-1.3 -0.9 -0.7 -0.4 -0.8 -3.5 -3.5 -1.6 -4.5 <c> continue.... That is in a file where in each line have to calculate mean and varia +nce where A, B can ignored as just saying that u have separate line +where each line have input data points in one file program is <code> #!/usr/bin/perl -w open( FILE, "< file_1" ) or die "Can't open file_1 : $!"; while( <FILE> ){ @fields = split / /; for($i=0;$i < scalar(@fields); $i++ ){ $sum[$i]+=$fields[$i]; $sumsq[$i]+=$fields[$i]*$fields[$i]; } $n++; } for($i=0;$i < scalar(@sum); $i++ ){ $sum[$i] /= $n; $sumsq[$i] /= $n; $stddev = sqrt( $sumsq[$i] - $sum[$i]*$sum[$i] ); print( $sum[$i]." ".$stddev." " ); } close FILE </code> But while running the program error occured <c> rgument "" isn't numeric in addition (+) at meanStddev.pl line 6, <FIL +E> line 1. Argument "" isn't numeric in addition (+) at meanStddev.pl line 6, <FI +LE> line 1. Argument "" isn't numeric in addition (+) at meanStddev.pl Argument "\n" isn't numeric in addition (+) at meanStddev.pl line 6, < +FILE> line 3. 0.573333333333333 0.867998975933856 0 0 0.833333333333333 1.1785113019 +7758 0 0 1.26666666666667 1.79133717900592 0 0 0.633333333333333 0.89 +566858950296 0 0 -1.16666666666667 1.64991582276861 0 0 -1.1666666666 +6667 1.64991582276861 0 0 1.06666666666667 1.5084944665313 0 0 -1.3 1 +.83847763108502 0 0 1.4 1.97989898732233 0 0 1.5 2.12132034355964 0 0 + 0.933333333333333 1.31993265821489 0 0 -0.433333333333333 0.61282587 +7028341 0 0 -0.3 0.424264068711929 0 0 -0.233333333333333 0.329983164 +553722 0 0 -0.133333333333333 0.188561808316413 0 0 -0.26666666666666 +7 0.377123616632825 0 0 -1.16666666666667 1.64991582276861 0 0 -1.166 +66666666667 1.64991582276861 0 0 -0.533333333333333 0.754247233265651 + 0 0 -1.5 2.12132034355964
20080114 Janitored by Corion: Changed bold tags to code tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: to calculate mean and variance
by davidrw (Prior) on Jan 11, 2008 at 03:01 UTC | |
by cdfd123 (Initiate) on Jan 11, 2008 at 07:35 UTC | |
by davidrw (Prior) on Jan 11, 2008 at 14:27 UTC | |
|
Re: to calculate mean and variance
by graff (Chancellor) on Jan 11, 2008 at 03:20 UTC | |
|
Re: to calculate mean and variance
by CountZero (Bishop) on Jan 11, 2008 at 06:26 UTC |