X 05 12 24 36 57 75 Yfx 96 74 4 6 97 9 Develop a Ccode to me

X 0.5 1.2 2.4 3.6 5.7 7.5 Y=f(x) 9.6 7.4 4 -6 -9.7 -9 Develop a C-code to meet the requirements below:- Plot f(x) versus x on a graph using any plot programs (Excel) 1- Fit polynomials to the data using second-order polynomial Regression y= (a0+a1x+a2x^2) 2- Use Simpson’s Rule to calculate f (x) dx, where a0, a1 and a2 Are determined in step 1). The integration is limited between x values (0.5 – 7.5) Requirements:- Use C-code must contain the following features:- (1) Use of arrays, (2) Use Of pointers (3) Use of structure, (4) Use of union, (5) Use of functions and Function calls, (6) Formatted output on screen and (7) Saving of the same Output on a file.

Solution

Solution:

#include<stdio.h>

void main()

{

int *x, *y, n, i, x1=0, x12=0, y1=0, x1y1=0, a1, a0, e;

printf(\"Enter how many values:\");

scanf(\"%d\", &n);

x=(float*)malloc(n*4);

y=(float*)malloc(n*4);

puts(\"Enter correspnding elements X and Y\");

for(i=0; i<n;i++)

{

scanf(\"%d %d\", &x[i], &y[i]);

x1+=x[i];

y1+=y[i];

x1y1+=(x[i]*y[i]);

x12+=(x[i]*x[i]);

}

a1 = (n*x1y1-x1*y1)/(n*x12-x1*x1);

a0=y1/n-a1*x1/n;

e=y[0]-a0-a1*x[0];

printf(\"a0= %d \ a1 = %d \ e= %d\", a0, a1, e);

}

X 0.5 1.2 2.4 3.6 5.7 7.5 Y=f(x) 9.6 7.4 4 -6 -9.7 -9 Develop a C-code to meet the requirements below:- Plot f(x) versus x on a graph using any plot programs (E

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site