inserting values into arrays from equation

Nov 18, 2015 at 1:29pm
Hi there

Im looking for some help with my problem. Is it possible to put values for y from my equation into a new array, so I can then use this and an original array to work out a sum of squared difference?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  using namespace std;	
int main()
{
	double t[] = { 700,730,760,790,810,840,910,1000 };
	double k[]= { 0.011,0.035,0.105,0.343,0.789,2.17,20,145 } ;
	double yhat[7] = {};


	double yhatvalue = 0.0;
	double R = 0.083144598; //in kJ K−1 mol−1
 	double A = 1.1E12;

	for (int i = 0; i < 8; i = i + 1)
	{
		 yhatvalue = A*(exp(-150/( R*t[i])));
	}
	cout << yhat << endl;

	system("Pause");
}


essentially I want to put 8 values of yhat into a new array, and then subtract yhat from each corresponding k value

Thanks
Nov 18, 2015 at 1:39pm
1) yhat must be defined to have 8 elements instead of 7
2)
1
2
3
4
5
	for (int i = 0; i < 8; i = i + 1)
	{
		 yhatvalue = A*(exp(-150/( R*t[i])));
		 yhat[i] = yhatvalue;
	}

3) Use std::vector instead of c-style arrays

http://www.programming4beginners.com/tutorial/chapter10/printing-out-arrays
Nov 18, 2015 at 2:14pm
My yhat array is displaying all values of zero though, why wont it insert the value using the equation for yhatvalue?
Nov 18, 2015 at 3:35pm
Because you have to instruct the computer to insert the value into yhat array.
Nov 18, 2015 at 5:06pm
ok, thanks, so how do i do that step?
Nov 18, 2015 at 5:19pm
Look at line 4 of the code in part 2 of my first answer.

Also, line 17 of your code will not print out the yhat array.
Last edited on Nov 18, 2015 at 5:23pm
Topic archived. No new replies allowed.