Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.) write a cyc- program that does first order linear regression analysis on the

ID: 3802436 • Letter: 1

Question

1.) write a cyc- program that does first order linear regression analysis on the three laboratory data sets listed below. Note your program should print out a separate table for calculated results for each original (x,Y) data set the new values of Y calculated 3 original values of x using the newly determined slope and Each of the printed out tables should list the original (x,Y) data and the new curve fitted data denoted by Y new Note the original x values do not change, only the Y values cap volts TEnergviul) 10.15 316 3255 447 34 ,9514 683 340 957 346 952 B556 385 R49 R12 60 636 20.2 398 65 624 4334 0.998 4756 175 603 592 540 120 Use the following formulas for sums S S3 and S4: The x,Y data set should be entered by typing in each xlil and Ylil value using a for loop With cin> xlij and cin> YIij. After data is entered, use formulas below inside a for loop For(int i 0; ik N-1; i++)

Explanation / Answer

1.

#include<iostream>
using namespace std;
int main(){
   int n;
   cout<<"Enter n : ";
   cin>>n;
   double *x=new double[n];
   double *y=new double[n];
   double s1=0.0,s2=0.0,s3=0.0,s4=0.0;
   for(int i=0;i<n;i++){
       cout<<"x["<<i<<"] : ";
       cin>>x[i];
       cout<<"y["<<i<<"] : ";
       cin>>y[i];
       s1+=x[i]*y[i];
       s2+=x[i];
       s3+=y[i];
       s4+=x[i]*x[i];
   }
   double X_mean = s2/n;
   double Y_mean = s3/n;
   double B =(s1-s2*s3/n)/(s4-s2*s2/n);
   double A = Y_mean-B*X_mean;
   double *Y_new = new double[n];
   for(int i=0;i<n;i++){
       Y_new[i]=B*x[i]+A;
   }
   cout<<"coff. A : "<<A;
   cout<<endl<<"coff. B : "<<B<<endl<<endl;
   cout<<"-------------------------------------";
   cout<<endl<<" Y_new "<<" X "<<endl;
   for(int i=0;i<n;i++)
       cout<<Y_new[i]<<" "<<x[i]<<endl;
}

2.

#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
int main(){
   cout<<"Enter N and M : ";
   int M,N;
   cin>>N>>M;
   int min,max;
   cout<<"Enter Min : ";
   cin>>min;
   cout<<"Enter Max : ";
   cin>>max;
   int *binA=new int[M*N];
   int *binB=new int[M*N];
   int *binC=new int[M*N];
   int *binD=new int[M*N];
   int *binE=new int[M*N];
   int *binF=new int[M*N];
   int *Tri1=new int[M*N];
   int *Tri2=new int[M*N];
   int *Tri3=new int[M*N];
   int *Tri4=new int[M*N];
   int **RN=new int*[M];
   int a,b,c,d,e,f,g,h,k,l;
   a=b=c=d=e=f=g=h=k=l=0;
   for(int i=0;i<M;i++)
       RN[i]=new int[N];
   //memset(RN,'0',M*N*sizeof(int));
   for(int i=0;i<M;i++){
       for(int j=0;j<N;j++){
           RN[i][j]=min+(rand()%(max-min+1));
           if(RN[i][j]%64==0)
               binF[f++]=RN[i][j];
           else if(RN[i][j]%32==0)
               binE[e++]=RN[i][j];
           else if(RN[i][j]%16==0)
               binD[d++]=RN[i][j];
           else if(RN[i][j]%8==0)
               binC[c++]=RN[i][j];
           else if(RN[i][j]%4==0)
               binB[b++]=RN[i][j];
           else if(RN[i][j]%2==0)
               binA[a++]=RN[i][j];
           else if(RN[i][j]%81==0)
               Tri4[l++]=RN[i][j];
           else if(RN[i][j]%27==0)
               Tri3[k++]=RN[i][j];
           else if(RN[i][j]%9==0)
               Tri2[h++]=RN[i][j];  
           else if(RN[i][j]%9==0)
               Tri1[g++]=RN[i][j];  
       }
   }
   cout<<"binA : ";
   for(int i=0;i<a;i++)
       cout<<binA[i]<<" ";
   cout<<endl;
   cout<<"binB : ";
   for(int i=0;i<b;i++)
       cout<<binB[i]<<" ";
   cout<<endl;
   cout<<"binC : ";
   for(int i=0;i<c;i++)
       cout<<binC[i]<<" ";
   cout<<endl;
   cout<<"binD : ";
   for(int i=0;i<d;i++)
       cout<<binD[i]<<" ";
   cout<<endl;
   cout<<"binE : ";
   for(int i=0;i<e;i++)
       cout<<binE[i]<<" ";
   cout<<endl;
   cout<<"binF : ";
   for(int i=0;i<f;i++)
       cout<<binF[i]<<" ";
   cout<<endl;
   cout<<"Tri1 : ";
   for(int i=0;i<g;i++)
       cout<<Tri1[i]<<" ";
   cout<<endl;
   cout<<"Tri2 : ";
   for(int i=0;i<g;i++)
       cout<<Tri2[i]<<" ";
   cout<<endl;
   cout<<"Tri3 : ";
   for(int i=0;i<k;i++)
       cout<<Tri3[i]<<" ";
   cout<<endl;
   cout<<"Tri4 : ";
   for(int i=0;i<l;i++)
       cout<<Tri4[i]<<" ";
   cout<<endl;
   return 0;
}