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;
- namespace mv_lab2
- {
- class Program
- {
- /*
- Y = SIN X
- A = 0
- B = PI / 4
- */
- static double A = 0;
- static double B = Math.PI * 0.25f;
- static double c1 = 1;
- static double c2 = 1;
- static double d1 = 1;
- static double d2 = 1;
- static double d = d1 * Math.Sin(B) + d2 * Math.Cos(B);
- static double c = c1 * Math.Sin(A) + c2 * Math.Cos(A);
- static int w = 35;
- static void Main(string[] args)
- {
- var res = Math.Sin(B);
- Console.WriteLine("|" + ResizeTo(w, "Нач") + "|" + ResizeTo(w, "Сер") + "|" + ResizeTo(w, "Кон") + "|");
- for (int n = 10; n < 65999; n *= 2)
- {
- solve(n);
- }
- Console.ReadKey();
- }
- static void solve(int n)
- {
- double[] xs = new double[n + 1];
- double[] ys = new double[n + 1];
- xs[0] = A;
- xs[n] = B;
- double h = (B - A) / n;
- for (int i = 1; i < n; ++i)
- {
- xs[i] = A + i * h;
- }
- double[] As = new double[n + 1];
- double[] Gs = new double[n + 1];
- double[] Bs = new double[n + 1];
- double[] MUs = new double[n + 1];
- double[] FIs = new double[n + 1];
- double[] Us = new double[n + 1];
- Bs[0] = c1 * h - c2;
- Gs[0] = c2;
- FIs[0] = h * c;
- for (int i = 1; i <= n; ++i)
- {
- As[i] = 1 - p(xs[i]) * h / 2;
- Bs[i] = -2 + q(xs[i]) * h * h;
- Gs[i] = 1 + p(xs[i]) * h / 2;
- FIs[i] = h * h * f(xs[i]);
- }
- As[n] = -d2;
- Bs[n] = h * d1 + d2;
- Gs[n] = 0 /*h * d*/;
- FIs[n] = h * d;
- // Прямая прогонка
- MUs[0] = -Gs[0] / Bs[0];
- Us[0] = FIs[0] / Bs[0];
- for (int i = 1; i <=n; i++)
- {
- MUs[i] = -Gs[i]
- / (Bs[i] + As[i] * MUs[i - 1]);
- Us[i] = (FIs[i] - As[i] * Us[i - 1])
- / (Bs[i] + As[i] * MUs[i - 1]);
- }
- // Y[n] ???
- ys[n] = Us[n];
- for (int i = n - 1; i >= 0; --i)
- {
- ys[i] = Us[i] + MUs[i] * ys[i + 1];
- }
- //for (int i = 0; i < ys.Length; ++i)
- // Console.WriteLine(i + " " + ys[i]);
- Console.WriteLine("|"
- + ResizeTo(w, ys[0] - Math.Sin(xs[0]) + "") + "|"
- + ResizeTo(w, ys[n / 2] - Math.Sin(xs[n / 2]) + "") + "|"
- + ResizeTo(w, ys[n] - Math.Sin(xs[n]) + "") + "|");
- }
- static string ResizeTo (int n, string s)
- {
- string res = s;
- while (res.Length < n)
- {
- if (res.Length % 2 == 0)
- res = res + " ";
- else
- res = " " + res;
- }
- return res;
- }
- static double f(double x)
- {
- return -Math.Sin(x) + p(x) * Math.Cos(x) + q(x) * Math.Sin(x);
- }
- static double p(double x)
- {
- return 1 / (x * x - 1);
- }
- static double q(double x)
- {
- return 1 / Math.Sqrt(1 - x * x);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement