calling 2 arrays into function and returning multiple values back to main

The raw data consists of a set of points, each with two measured coordinate values. For example, one could measure the temperature and humidity at intervals throughout the day, and then plot them on a graph. Often, a clear relationship will be evident just by looking at the data. If the relationship appears to be linear, then linear regression analysis is appropriate. To determine the equation of the straight line model, we find both the slope and the intercept:


x[] and y[] are arrayes

m=f(x,y)=(example m=sum of x[i]+sum ofy[i] and so on)
n=g(x,y)
R=h(x,y)



and the correlation coefficient squared (or R-squared value) is a measure of how good the fit is:



In these equations, n is the number of data points and
(xi,yi) are the coordinate values of each data point.


Write a program that uses linear regression to determine the equation of the straight line that best fits the data shown on the back of this page. Begin by downloading the input file named resist.txt containing the values shown there. Your program will read this file and store the values in two parallel arrays. It will then analyze the data and output to the console (neatly formatted) the number of data points, the mean value of both variables, the equation of the best-fit line, and its R-squared value. Don't forget to check your work—at least make sure your answers are reasonable. The following are required:



1)Write a function to load the arrays. Do not hardcode the number of data points (n) —count them as you load the arrays.
2)Pass the arrays to a second function that will calculate the slope, y-intercept and R-squared value of the best-fit straight line. (This will involve the summations.)
3)Write a third function that will return the average value of any array passed to it. (Call it twice to obtain Tavg, and Ravg.)
4)Write a fourth function to output the results to the console.


Number of data points: a
Mean value of Temperature (deg. F): a.aa
Mean value of Resistance (Ohms): a.aa
The equation of the best fit line is: y = (a.aa)x + a.aa
The R-squared value is: a.aaaa


The resistance characteristics of a thermistor can be found by placing it in an oven where its temperature can be varied while its resistance to electrical current is measured. One such exercise resulted in the following data:

Temperature(F) Resistance(Ohms)
100 13580
121 10430
139 7576
160 5328
182 3446
201 2308
220 1578
240 932
258 726
284 416
299 169


I did 1) 3) for 2) i did it however I am stuck on how to return 3 values from a function back to main (). knowiny that in #2 I called the 2 arrays because i used the data in both arrays to make calculation of 3 coefficents that I need to get back to main ()


-------------------------------


main ()
{
// my main program
//



slopfct(temp, res, numValues);

//
//
return 0;
}

double slopfct(double values1[], double values2[],int numValues){

// mycalculation

//now i have 3 values m, n and R that I need to send back to main


any guidance is appreciated.


You can pass values from a function back up to the calling code as function parameters. You will need to pass by reference, which means your parameters will need to be either pointers or references to the values.
Topic archived. No new replies allowed.