Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <math.h>
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- int wybor;
- cout<<"Podaj metode: "<<endl;
- cout<<"1) Metoda Lagrange'a "<<endl;
- cout<<"2) Metoda Hermite'a "<<endl;
- cout<<"0) Zamknij program" <<endl;
- cin>>wybor;
- switch (wybor)
- {
- case 0:
- { system("pause");
- return 0;
- }
- case 1:
- {
- int n;
- double *A;
- double *w;
- double x;
- cout<<"Metoda Lagrange'a"<<endl;
- cout<<"podaj rozmiar tablicy wezlow : ";
- cin>>n;
- A=new double[n];
- w=new double[n];
- for(int i=0;i<n;i++)
- {
- cout<<"podaj wartosc tablicy wezlow ["<<i<<"] = ";
- cin>>A[i];
- }
- for(int i=0;i<n;i++)
- {
- cout<<"podaj wartosci w wezlach ["<<i<<"] = ";
- cin>>w[i];
- }
- cout<<"Podaj x: ";
- cin>>x;
- double s=0;
- double w1=1;
- double w2=1;
- for (int j=0; j<n-1; j++) {
- for ( int i = 0; i<n-1; i++)
- {
- if (i!=j){
- w1=w1*(x-A[i]);
- w2=w2*(A[j]-A[i]);}
- }
- s=s+((w[j]*w1)/w2);
- }
- cout<<"wynik: "<<s;
- break;
- }
- case 2:
- {
- cout<<"Hr";
- break;
- }
- default:
- cout<<"Nie znany znak";
- break;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment