Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*вариант 1
- Вычислить и вывести на экран в виде таблицы значения функции, заданнй с помощью ряда Тейлора, на интервале от xn до xk с шагом dx с точностью е
- ln((x+1)/(x-1))=2*(1/x+1/3*x^3+1/5x^5+...) abs(x)>1*/
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- #include <conio.h>
- using namespace std;
- float TaylorExpansion(float x, int &n, int &flag){
- float e = 0.00001;
- float sum = 0;
- float sl = 1 / x;
- while (fabs(sl) >= e)
- {
- sum += sl;
- sl *= (2 * n - 1) / (x*x*(2 * n + 1));
- n++;
- if (n == 1000) {
- flag = 1;
- break;
- }
- }
- return sum * 2;
- }
- void Table(float xn, float xk, float dx){
- float x,f;
- cout << "-----------------------------------------------\n";
- cout << "| x | f |ln((x+1)/(x-1))| n |\n";
- cout << "-----------------------------------------------" << endl;
- int n,flag;
- for (x = xn; x <= xk; x += dx)
- {
- n = 1;
- flag = 0;
- f = TaylorExpansion(x, n, flag);
- if (flag == 0)
- printf("|%6.2f | %8.5f | %8.5f |%6d |\n", x, f, log((x + 1) / (x - 1)), n);
- else
- printf("|%6.2f | - | - |%6d |\n", x, n);
- }
- cout << "-----------------------------------------------\n";
- }
- int main()
- {
- float xn, xk, dx;
- cout << "Enter xn, xk, dx: \n";
- cin >> xn >> xk >> dx;
- Table(xn, xk, dx);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement