Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace LabWork
- {
- class Program
- {
- delegate double Func(double x);
- static void Main()
- {
- Calc(A);
- Calc(B);
- Console.ReadKey();
- }
- static double A(double x)
- {
- return 5 * x + 2 - 2 * Math.Exp(x);
- }
- static double B(double x)
- {
- return Math.Pow(0.5, x) - 1 - Math.Pow((x + 2), 2);
- }
- static void Calc(Func function)
- {
- double a = -10, b = 10, x = (a + b) / 2, eps = 0.0001F;
- while (Math.Abs(b - a) > eps)
- {
- if (Math.Sign(function(x)) != Math.Sign(function(a)))
- b = x;
- else
- a = x;
- x = (a + b) / 2;
- }
- string name = function.Method.Name;
- Console.WriteLine("Корень ф-ции {0}: X = {1}", function.Method.Name, x);
- Console.WriteLine("Значение фунции {0}({1}) = {2}", name, x, function(x));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement