C program to calculate polynomial regression algorithm
Regression is a predictive modeling technique that studies the relationship between a dependent variable and a non-dependent variable.
Polynomial regression
It is a form of regression analysis that shows the relationship between the independent variable x and the dependent variable y, which is an n-degree polynomial model of x.
Example
The following is a C program to compute the polynomial regression algorithm −
#include<math.h> #include<stdio.h> #include<conio.h> main(){ int i,j,k,m,n; float x[20],y[20],u,a[10],c[20][20],power,r; printf("enter m,n:"); scanf("%d%d",&m,&n); for(i=1;i<=n;i++){ printf("enter values of x and y"); scanf("%f%f",&x[i],&y[i]); } for(j=1;j<=m+1;j++) for(k=1;k<=m+1;k++){ c[j][k]=0; for(i=1;i<=n;i++){ power=pow(x[i],j+k-2); c[j][k]=c[j][k]+power; } } for(j=1;j<=m+1;j++){ c[j][m+2]=0; for(i=1;i<=n;i++){ r=pow(x[i],j-1); c[j][m+2]=c[j][m+2]+y[i]*r; } } for(i=1;i<=m+1;i++){ for(j=1;j<=m+2;j++){ printf("%.2f\t",c[i][j]); } printf("</p><p>"); } for(k=1;k<=m+1;k++) for(i=1;i<=m+1;i++){ if(i!=k){ u=c[i][k]/c[k][k]; for(j=k;j<=m+2;j++){ c[i][j]=c[i][j]-u*c[k][j]; } } } for(i=1;i<=m+1;i++){ a[i]=c[i][m+2]/c[i][i]; printf("a[%d]=%f</p><p>",i,a[i]); } getch(); }
Output
When the above program is executed, It produces the following result −
enter m,n:4 5 enter values of x and y1 1 enter values of x and y2 3 enter values of x and y1 2 enter values of x and y1 2 enter values of x and y1 1 5.00 6.00 8.00 12.00 20.00 9.00 6.00 8.00 12.00 20.00 36.00 12.00 8.00 12.00 20.00 36.00 68.00 18.00 12.00 20.00 36.00 68.00 132.00 30.00 20.00 36.00 68.00 132.00 260.00 54.00 a[1]=1.750000 a[2]=-2.375000 a[3]=2.000000 a[4]=0.500000 a[5]=-0.375000
The above is the detailed content of C program to calculate polynomial regression algorithm. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

General Matrix Multiplication (GEMM) is a vital part of many applications and algorithms, and is also one of the important indicators for evaluating computer hardware performance. In-depth research and optimization of the implementation of GEMM can help us better understand high-performance computing and the relationship between software and hardware systems. In computer science, effective optimization of GEMM can increase computing speed and save resources, which is crucial to improving the overall performance of a computer system. An in-depth understanding of the working principle and optimization method of GEMM will help us better utilize the potential of modern computing hardware and provide more efficient solutions for various complex computing tasks. By optimizing the performance of GEMM

WORD is a powerful word processor. We can use word to edit various texts. In Excel tables, we have mastered the calculation methods of addition, subtraction and multipliers. So if we need to calculate the addition of numerical values in Word tables, How to subtract the multiplier? Can I only use a calculator to calculate it? The answer is of course no, WORD can also do it. Today I will teach you how to use formulas to calculate basic operations such as addition, subtraction, multiplication and division in tables in Word documents. Let's learn together. So, today let me demonstrate in detail how to calculate addition, subtraction, multiplication and division in a WORD document? Step 1: Open a WORD, click [Table] under [Insert] on the toolbar, and insert a table in the drop-down menu.

How to use Python's count() function to calculate the number of an element in a list requires specific code examples. As a powerful and easy-to-learn programming language, Python provides many built-in functions to handle different data structures. One of them is the count() function, which can be used to count the number of elements in a list. In this article, we will explain how to use the count() function in detail and provide specific code examples. The count() function is a built-in function of Python, used to calculate a certain

Given two strings str_1 and str_2. The goal is to count the number of occurrences of substring str2 in string str1 using a recursive procedure. A recursive function is a function that calls itself within its definition. If str1 is "Iknowthatyouknowthatiknow" and str2 is "know" the number of occurrences is -3. Let us understand through examples. For example, input str1="TPisTPareTPamTP", str2="TP"; output Countofoccurrencesofasubstringrecursi

In C#, there is a Math class library, which contains many mathematical functions. These include the function Math.Pow, which calculates powers, which can help us calculate the power of a specified number. The usage of the Math.Pow function is very simple, you only need to specify the base and exponent. The syntax is as follows: Math.Pow(base,exponent); where base represents the base and exponent represents the exponent. This function returns a double type result, that is, the power calculation result. Let's

A map is a special type of container in C++ in which each element is a pair of two values, namely a key value and a map value. The key value is used to index each item, and the mapped value is the value associated with the key. Regardless of whether the mapped value is unique, the key is always unique. To print map elements in C++ we have to use iterator. An element in a set of items is indicated by an iterator object. Iterators are primarily used with arrays and other types of containers (such as vectors), and they have a specific set of operations that can be used to identify specific elements within a specific range. Iterators can be incremented or decremented to reference different elements present in a range or container. The iterator points to the memory location of a specific element in the range. Printing a map in C++ using iterators First, let's look at how to define

Hyperbolic functions are defined using hyperbolas instead of circles and are equivalent to ordinary trigonometric functions. It returns the ratio parameter in the hyperbolic sine function from the supplied angle in radians. But do the opposite, or in other words. If we want to calculate an angle from a hyperbolic sine, we need an inverse hyperbolic trigonometric operation like the hyperbolic inverse sine operation. This course will demonstrate how to use the hyperbolic inverse sine (asinh) function in C++ to calculate angles using the hyperbolic sine value in radians. The hyperbolic arcsine operation follows the following formula -$$\mathrm{sinh^{-1}x\:=\:In(x\:+\:\sqrt{x^2\:+\:1})}, Where\:In\:is\:natural logarithm\:(log_e\:k)

The rename function changes a file or directory from its old name to its new name. This operation is similar to the move operation. So we can also use this rename function to move files. This function exists in the stdio.h library header file. The syntax of the rename function is as follows: intrename(constchar*oldname,constchar*newname); The function of the rename() function accepts two parameters. One is oldname and the other is newname. Both parameters are pointers to constant characters that define the old and new names of the file. Returns zero if the file was renamed successfully; otherwise, returns a nonzero integer. During a rename operation
