suppose the reaction temperature suppose the reaction temperature suppose the re
ID: 3737944 • Letter: S
Question
suppose the reaction temperature suppose the reaction temperature suppose the reaction temperature suppose the reaction temperature suppose the reaction temperature Develop a C-code to obtain linear regression relation yeax+b for both data shown below. Print a and b value on screen. Predict and print the y value when x- 27 on screen. Calculate and print the r value. Print "This is a good fit ifr is greater than 0.95 on screen. Otherwise, print This is a rough fir on screen. Run the code twice for the following data 67.4 62.3 24 30 35 42 51.2 2) 24 30 35 42 67.4 65.3 55.3 20.2 Show both codes and results of above two situations in your PDF file.Explanation / Answer
#include<stdio.h>
#include<math.h>
main()
{
int n,i;
float a,b,m,x[10],y[10],sum_of_x,sum_of_y,sum_of_xy,sum_of_x_square,sum_of_y_square,y_val,r;
printf("Enter the value of n ");
scanf("%d",&n);
printf("Enter the value of x : values ");
for (i=0;i<n;i++)
{
scanf("%f",&x[i]);
}
printf("Enter the value of y : values ");
for (i=0;i<n;i++)
{
scanf("%f",&y[i]);
}
sum_of_x=0.0;
sum_of_y=0.0;
sum_of_xy=0.0;
sum_of_x_square=0.0;
sum_of_y_square=0.0;
for (i=0;i<n;i++)
{
sum_of_x=sum_of_x+x[i];
sum_of_y=sum_of_y+y[i];
sum_of_xy=sum_of_xy+x[i]*y[i];
sum_of_x_square=sum_of_x_square+x[i]*x[i];
sum_of_y_square=sum_of_y_square+y[i]*y[i];
}
m=1.0*n;
a=(sum_of_x*sum_of_y - m*sum_of_xy)/(sum_of_x*sum_of_x - m*sum_of_x_square);
b=(sum_of_y-a*sum_of_x)/m;
r=(n*sum_of_xy- sum_of_x*sum_of_y)/sqrt((m*sum_of_x_square-sum_of_x*sum_of_x)*(m*sum_of_y_square-sum_of_y*sum_of_y));
printf("a = %f b = %f ",a,b);
printf("r = %f ",r);
y_val=a*27.0+b;
printf("Wnen x=27 , value of y is = %f ",y_val);
if(r>0.95)
{
printf("This is a good fit ");
}
else
{
printf("This is a rough fit ");
}
}
Result: 1
Enter the value of n
4
Enter the value of x : values
24 30 35 42
Enter the value of y : values
67.4 62.3 55.3 51.2
a = -0.933046 b = 89.607262
r = -0.987621
Wnen x=27 , value of y is = 64.415016
This is a rough fit
Result: 2
Enter the value of n
4
Enter the value of x : values
24 30 35 42
Enter the value of y : values
67.4 65.3 55.3 20.2
a = -2.621175 b = 137.893478
r = -0.914328
Wnen x=27 , value of y is = 67.121758
This is a rough fit
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.