LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-25-2005, 09:44 PM   #1
mshinska
LQ Newbie
 
Registered: Oct 2005
Posts: 14

Rep: Reputation: 0
error when finding the standard deviation of a vector


I keep getting this error, which i have never seen before:

lab10.cpp: In function `int main()':
lab10.cpp:50: `sorry, not implemented: `float_expr' not supported by dump_expr
(<expression error> - average)' cannot be used as a function


my code that gets the error is:

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main(void)
{
vector<int> values;
int input;
cout << "Enter a number: ";
cin >> input;
while(!cin.fail())
{ values.push_back(input);
cout << "Enter a number: ";
cin >> input;
}
int f;
float stdDev;
float sum2= 0.0;
for (int f=0; f < values.size(); f = f+1)
{ sum2 = ((sum2) + (values[f]-average)(values[f]-average) );
}
sum2 = sum2/ values.size();
stdDev=sqrt((sum2));

cout << "The standard deviation is: " << stdDev << endl;

return 0;
}
 
Old 10-25-2005, 09:50 PM   #2
mshinska
LQ Newbie
 
Registered: Oct 2005
Posts: 14

Original Poster
Rep: Reputation: 0
i forgot to add this when i copy/pasted

float average;
float sum;
for (int i = 0; i<values.size(); i = i + 1)
{ sum = sum + values[i];
average = sum/ values.size();

}
 
Old 10-25-2005, 09:52 PM   #3
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
what does this line do?
Code:
sum2 = ((sum2) + (values[f]-average)(values[f]-average) )
whats "average" and what is "(values[f]-average)(values[f]-average)" do?

just seen you post, i still dont know what the second part does tho.

Code:
i forgot to add this when i copy/pasted

float average;
float sum;
for (int i = 0; i<values.size(); i = i + 1)
{ sum = sum + values[i];
average = sum/ values.size();

}
your calculating the average every loop here.

Last edited by dmail; 10-25-2005 at 09:55 PM.
 
Old 10-25-2005, 10:01 PM   #4
mshinska
LQ Newbie
 
Registered: Oct 2005
Posts: 14

Original Poster
Rep: Reputation: 0
standard deviation is the square root of (each element - mean)^2 added together divided by the number of elements

for example if you have a vector of [ 1 2 3] the standard deviation is
sqrt( ( (1-2)^2 + (2-2)^2 + (3-2)^2)/3)

i explained average in my first correction



Last edited by mshinska; 10-25-2005 at 10:03 PM.
 
Old 10-25-2005, 10:05 PM   #5
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
you seem to be missing the point, or i am.
is this some macro magic or something
Code:
(values[f]-average)(values[f]-average)
what does this evaluate to? is there susposed to be an operator in there?
 
Old 10-25-2005, 11:03 PM   #6
mshinska
LQ Newbie
 
Registered: Oct 2005
Posts: 14

Original Poster
Rep: Reputation: 0
oh i get what you are saying i forgot the multipication symbol (*), thank you for your help it works now!!!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
finding the mode(# which occurs most often) of a given vector mshinska Programming 3 11-21-2005 07:14 PM
error in gcc / g++ standard file maheshbmane Programming 6 09-02-2005 08:30 PM
can i modify int 80 vector to a user-defined vector qqrilxk Linux - Security 1 03-03-2005 08:46 PM
charting mean and standard deviation allelopath Linux - Software 2 02-04-2005 02:36 PM
Deviation v.1 Securing your Linux/BSD machine sil Linux - Security 0 05-18-2001 06:59 PM


All times are GMT -5. The time now is 08:12 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration