Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication2
- {
- class Program
- {
- static double MyFunc(double x)
- {
- return x * Math.Cos(x);
- }
- //x*Math.Cos(x)
- static double FuncPlus(double next, double current, double h)
- {
- return next - current / h;
- }
- static double FuncMinus(double previous, double current, double h)
- {
- return current - previous / h;
- }
- static double FuncMiddle(double next, double previous, double h)
- {
- return next - previous / 2 * h;
- }
- static void Main(string[] args)
- {
- double e = 0.0001, a = 0.0, b = 1.7, x = 0, h = 0.1, sum = 0;
- for (x = a; x <= b; x += h)
- {
- double current = x;
- double next = 1;
- double previous = 1;
- double Plus = 0, Minus = 0, Middle = 0, Func = 0;
- int k = 0;
- while (Math.Abs(current) >= e)
- {
- sum += current;
- previous = current;
- Minus = FuncMinus(previous, current, h);
- next = current * (-((x * x) / (2 * (k + 1) * (2 * k + 1))));
- Plus = FuncPlus(next, current, h);
- current = next;
- Middle = FuncMiddle(next, previous, h);
- Func = MyFunc(x);
- k++;
- }
- Console.WriteLine("x: {0} \t sum: {1} \t f(x): {2} \t f_+(x): {3} \t f_-(x): {4} \t f_0(x): {5}", x, sum, Func, Plus, Minus, Middle);
- sum = 0;
- }
- Console.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement