Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,697 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,501 people online right now. Registration is fast and FREE... Join Now!




Vectors and Sequences

 
Reply to this topicStart new topic

Vectors and Sequences, Thermocouple Equation

LaviniaT
post 14 Dec, 2005 - 10:24 AM
Post #1


New D.I.C Head

*
Joined: 13 Dec, 2005
Posts: 5


My Contributions


Hello, I'm at the end of my first programming course and I have to say I'm stumped in the final problem assigned.

The problem is to solve the equation of a thermocouple device using various voltages and temperatures inputted by the user.

The linear equation for solving T is a*V +b were we solve for coefficients a and b.

T is temperature, V is voltage and a and b are computed using the following formulas.

a = (n*(E(Vi*Ti)) - (EVi) * (ETi) /(n*(EVi*Vi)) - (EVi)^2)
b = (ETi-(a*EVi))/n

n is the number of measurements which is MAX in the code.
Vi and Ti are measured values of voltages and temperatures
E stands for sigma or sum of operator.(I'm not sure if there is a character symbol for it).


CODE

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

int main()
{
   
   int MAX;
   cout << "How many data points will be placed? ";
   cin >> MAX;
   vector<double> volt (MAX);
   vector<double> temp (MAX);
   
   for(int i = 0; i < MAX; i++)
   {
             cout << "Enter the volts\n";
             cin >> volt[i];
             cout << "Enter the temp\n";
             cin >> temp[i];
     
   }
   
    //loop for voltage
   double addvolts = 0;
   for(i = 0; i < MAX; i++)
   {
           addvolts+= volt[i];
   }
   
   cout << "Total volts " << addvolts << endl;
   
   //loop for temperature
   double addtemp = 0;
   for(i = 0; i < MAX; i++)
   {
           addtemp+= temp[i];
   }
   
   cout << "Total temperature " << addtemp << endl;
   


    double x;
    /*
    Sequence of EVi*Vi were E is sigma
    
   //loop for Vi*Vi
   for(i = 0; i< MAX; i++)
   {
           x += volt[i];
   }
   
   cout << "X is equal to " << x << endl;
    */


   //space here for final loop


   double v;
   v = addvolts;
   double t;
   t = addtemp;

   
   double n = MAX * 2;
   double a;
   
   a = ((n * (v * t)) - (((v) * (t))) / ((n*x))-(pow(v, 2)));
   
   double b;
   
   b = (t - (a * (v))) / n;
   
   cout << "T = " << a << "*V + " << b << endl;
   
   /*
    Used later to test equation
   
 
    double V;
   double T;
   cout << "**TEST**\n";
   cout << "Enter the volts\n";
   cin >> V;
   T = (a*V) + b;
   cout << "The temperature is " << T << endl;
    */

   
   system ("pause");
   
   return 0;
   
}


This is what I have so far. It might be because I haven't taken a math course in a while but I'm getting stumped making a loop for the sequence of EVi*Vi and EVi*Ti.


From the code I made that section in comment which is this one
CODE
    double x;
    /*
    Sequence of EVi*Vi where E is sigma
    
   //loop for Vi*Vi
   for(i = 0; i< MAX; i++)
   {
           x += volt[i];
   }
   
   cout << "X is equal to " << x << endl;
    */


Which I then added to the initial loop x = volt[i] *volt[i] since from my understanding EVi*Vi would be the first voltage inputted multiplied by itself and then added to the next voltage inputted that was multiplied by itself. Which would be Voltage1*Voltage1 + Voltage2*Voltage2 from my understanding of it.

Unfortunatly adding x= volt[i]*volt[i] to initial loop didn;t work.
CODE
for(int i = 0; i < MAX; i++)
   {
             cout << "Enter the volts\n";
             cin >> volt[i];
            // x=volt[i]*volt[i]
             cout << "Enter the temp\n";
             cin >> temp[i];
     
   }


I was thinking that maybe I would have to make two seperate loops one to multiply them and another one to add that result?Something likeVi * Vi could be x*x. Thats why I'm using the x variable.

And for the final loop which is E(Vi*Ti) from my understanding it is Voltage1*Temperature1 + Voltage2*Temperature2 etc.. Which would make sense but a classmate informed me it was V1+T1*V2+T2? I'm not totally to sure on this one due to my lack of understanding of sequences.

I apologize for making this too long and rather confusing. If need be I will clarify any point or if I can find a scanner somewhere around I could try scanning the actual problem if my poor description isn't clear enough.

Any guidance as to what I could do next would be appreciated.

Thank you.
User is offlineProfile CardPM

Go to the top of the page

Nova Dragoon
post 14 Dec, 2005 - 10:51 AM
Post #2


The Innocent Shall Suffer, Big Time

Group Icon
Joined: 16 Aug, 2001
Posts: 6,125



Thanked 4 times

Dream Kudos: 515

Expert In: Python, Linux

My Contributions


E(Vi*Ti) should be as you described it.
The way your classmate described it would be the Product (pi function? i think)
User is online!Profile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/20/08 08:53AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month