Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal class Program
- {
- public delegate double Function(double x);
- public delegate double Method(Function d, double eps);
- static public double func1(double x)
- {
- return Math.Exp(x) - 4 * (1 - Math.Pow(x, 2));
- }
- static public double func2(double x)
- {
- return 1 - (1 / Math.Log(x));
- }
- static public double dihotomy(Function f, double eps)
- {
- double left = 100;
- double right = -100;
- double c = left;
- int iteration = 0;
- while (right - left > eps)
- {
- ++iteration;
- c = (left + right) / 2;
- if (f(left) * f(c) < 0)
- {
- right = c;
- }
- else
- {
- if (f(left) * f(c) > 0)
- left = c;
- else
- return c;
- }
- }
- return c;
- }
- static public double chords(Function f, double eps)
- {
- {
- int iteration = 0;
- double x_next = 0;
- double tmp;
- double x_prev = -100;
- double x_curr = 100;
- do
- {
- ++iteration;
- tmp = x_next;
- x_next = x_curr - f(x_curr) * (x_prev - x_curr) / (f(x_prev) - f(x_curr));
- x_prev = x_curr;
- x_curr = tmp;
- } while (Math.Abs(x_next - x_curr) > eps);
- return x_next;
- }
- }
- static public double newton(Function f, double eps)
- {
- int iteration = 1;
- double x1 = 0;
- double delta = 1e-9;
- double der = (f(x1 + delta) - f(x1)) / delta;
- double x2 = x1 - (f(x1) / der);
- while (Math.Abs(x2-x1) > eps)
- {
- iteration += 1;
- x1 = x2;
- der = (f(x1 + delta) - f(x1)) / delta;
- x2 = x1 - (f(x1) / der);
- }
- return x2;
- }
- public static void Main(string[] args)
- {
- Function f = func1;
- Method m = newton;
- double k = m(f, 1e-10);
- Console.WriteLine(k);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement