Question
PLEASE HELP ME FIGURE OUT THIS CODE i really need help with this. I need help figuring out how to solve the errors. I dont
PLEASE HELP ME FIGURE OUT THIS CODE i really need help with this. I need help figuring out how to solve the errors.
I dont think i did the linear regression part right PLEASE HELP ME. I am very confused and dont know what to do.
This is my code and need help revising it. PLEASE just revise my code.
#include
#include
double sum(double x[], double y[], int n);
double r(double x[], double y[], int n, double a, double b);
float func(float x,float y);
float euler(float x0,float xn,float y0,int n);
int main(){
double x[]={2,3};
double y[]={3};
double one[]={1,1};
float x0,xn,y0,e;
int n=2;
double x0=2;
double sumx, sumy,sumxx,sumxy;
double a,b;
sumx=sum(x,one,n);
sumy=sum(y,one,n);
sumxx=sum(x,x,n);
sumxy=sum(x,y,n);
a=(n*sumxy-sumx*sumy)/(n*sumxx-sumx*sumx);
b=(sumy*sumxx-sumx*sumxy)/(n*sumxx-sumx*sumx);
printf(" By linear regression, the function is: y=%fx+%f ",a,b);
printf(" When x= %f, y= %f ",x0,a*x0+b);
printf(" r = %f ",r(x,y,n,a,b));
return 0;
}
double sum(double x[],double y[], int n){
double s=0.0;int i=0;
for (i=0;i s=s+x[i]*y[i]; return s; } double r(double x[],double y[], int n, double a, double b){ double s0=0,s=0,ybar=0,total=0; int i=0; for (i=0;i total+=y[i]; } ybar=total; for (i=0;i s0+=pow((y[i]-ybar),2); s+=pow((y[i]-b-a*x[i]),2); } return pow((s0-s)/s0,0.5); } printf(" inputn: "); scanf("%d",&n); printf("input x0: "); scanf("%f",&x0); printf("input xn: "); scanf("%f",&xn); printf("input y0: "); scanf("%f",&y0); e=euler(x0,xn,y0,n); } } float func(float x,float y){ return ((x*x)-(3*x)); } float euler(float x0,float xn,float y0,int n){ float x,y,h; int i; x=x0; y=y0; h=(xn-x0); printf("y(%f)=%6.4f ",x0,y0); for(i=1;i x=x0+i*h; printf("y(%f)=%6.4f ",x,y); } return y; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started