Lagrange Polynomials
I have worked i开发者_高级运维n C language, but now i have been given this work where i will have to use C++. I have to generate lagrange polynomials. Now, i wont ask for the code or anything but i want to know a few of things:
- How do i go about this code: I ask the user to enter the data (i.e. the x and y coordinates) around which the polynomial is to be developed and give back a polynomial?
- Will the same concepts of C let me develop this code in C++ environment, i know there would be a few syntax differences, but would i need to know the classes and objects information for this code or will i be good without them too?
- If anything else i need to know?
Kindly help!
you can pretty much write C and compile it as C++. There might be some exceptions, but hopefully the compiler or a bit or Internet poking should help you there. C++ is a non-strict superset of C.
That said, if you are willing to invest some time in learning the particular facilities of C++, you'll probably find it rewarding. Whether this is worth the time for your particular assignment is a matter of the details of your assignment.
this is source code :
#include<iostream>
using namespace std;
int main()
{
double arrx[2];
double arrf[2];
double x, lx;
int h;
system("color C");
//----------------------------------------------
cout << "________________LAGRANGE POLYNOMIAL________________" << endl;
cout << " " << endl;
cout << "Enter 3 values For X :" << endl;
for (int i = 0; i < 3; i++)
{
cout << " " << endl;
cout << "X" << i << endl;
cin >> arrx[i];
}
cout << "Enter 3 values For F :" << endl;
for (int j = 0; j < 3; j++)
{
cout << "F" << j << endl;
cin >> arrf[j];
}
cout << "How Meany Value ?" << endl;
cin >> h;
for (int c = 1; c <= h; c++)
{
cout << "______________________________________________________" << endl;
cout << "Enter f(Value) : " << endl;
cin >> x;
cout << " " << endl; //*****Start //****StartTwo
lx = ((((x - arrx[1])*(x - arrx[2])) / ((arrx[0] - arrx[1])* (arrx[0] - arrx[2]))) * (arrf[0])) + ((((x - arrx[0])*(x - arrx[2])) / ((arrx[1] - arrx[0])* (arrx[1] - arrx[2]))) * (arrf[1])) + ((((x - arrx[0])*(x - arrx[1])) / ((arrx[2] - arrx[0])* (arrx[2] - arrx[1]))) * (arrf[2]));
cout << "f(" << x << ")" << "~=" << "L(" << x << ")" << " = " << lx << endl;
}
system("pause");
}
精彩评论