Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication3.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <math.h>
- using namespace std;
- double lagran(double *xa, double *ya, double poz);
- const double FIRST = 0.3;
- const double SECOND = 1.5;
- const double THIRD = 2.8;
- const int ARR_SIZE = 6;
- int main()
- {
- double y[] = { 0.100167, 0.636654, 1.50946, 2.94217, 6.69473, 10.0179 };
- double x[] = { 0.1, 0.6, 1.2, 1.8, 2.6, 3 };
- cout << "Wynik dla " << FIRST << " to: " << lagran(x, y, FIRST) << endl;
- cout << "Wynik dla " << SECOND << " to: " << lagran(x, y, SECOND) << endl;
- cout << "Wynik dla " << THIRD << " to: " << lagran(x, y, THIRD) << endl;
- cout << "Wynik dla sinh " << FIRST << " to: " << sinh(FIRST) << " roznica: " << abs(lagran(x, y, FIRST) - sinh(FIRST)) << endl;
- cout << "Wynik dla sinh " << SECOND << " to: " << sinh(SECOND) << " roznica: " << abs(lagran(x, y, SECOND) - sinh(SECOND)) << endl;
- cout << "Wynik dla sinh " << THIRD << " to: " << sinh(THIRD) << " roznica: " << abs(lagran(x, y, THIRD) - sinh(THIRD)) << endl;
- system("PAUSE");
- return 0;
- }
- double lagran(double *xa, double *ya, double poz) {
- double wynik = 0.0;
- double tmp;
- for (int i(0); i < ARR_SIZE; i++) {
- tmp = 1.0;
- for (int j(0); j < ARR_SIZE; j++) {
- if (j != i) {
- tmp = tmp*((poz - xa[j]) / (xa[i] - xa[j]));
- }
- }
- wynik += tmp*ya[i];
- }
- return wynik;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement