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 ConsoleApplication24
- {
- class Program
- {
- static double Fi1 (double x, double y)
- {
- return 1 + 3 * Math.Sin(Math.PI * x / 2);
- }
- static double Fi2 (double x, double y)
- {
- return 1 + Math.Sin(Math.PI * y);
- }
- public static double roundValues (double x)
- {
- return (double)Math.Round(x * 1000) / (double)1000;
- }
- static void printM(double[,] m)
- {
- for (int i = 0; i < m.GetLength(0); i++)
- {
- for (int j = 0; j < m.GetLength(1); j++)
- {
- Console.Write(roundValues(m[j, j]) + " ");
- }
- Console.WriteLine("");
- }
- }
- static void Main(string[] args)
- {
- int nx, ny;
- nx = 10;
- ny = 10;
- double[] x = new double[nx];
- double[] y = new double[ny];
- double[,] u = new double[nx,ny];
- double Hx, Hy, alpha, d, du, Uold, Unew;
- Hx = 0.01;
- Hy = 0.01;
- alpha = Hx / Hy;
- for (int i = 0; i < nx; i++)
- {
- x[i] = i * Hx;
- u[i, 0] = Fi1(x[i], 0);
- u[1, ny - 1] = Fi1(x[i], 1);
- }
- for(int j = 1; j < nx; j++)
- {
- y[j] = j * Hy;
- u[0, j] = Fi2(0, y[j]);
- u[nx - 1, j] = Fi2(1, y[j]);
- }
- du = 0;
- d = 0;
- do
- {
- for (int i = 1; i < nx - 1; i++)
- {
- for (int j = 1; j < ny - 1; j++)
- {
- Uold = u[i, j];
- u[i, j] = 1 / (2 * (1 + alpha * alpha)) * ((u[i, j + 1]) + u[i, j - 1] * alpha * alpha + (u[i + 1, j] + u[i - 1, j]));
- Unew = u[i, j];
- if (Math.Abs(Unew) < 0.0001)
- {
- du = Math.Abs((Unew - Uold) / Unew);
- }
- if (du > d)
- {
- d = du;
- }
- u[i, j] = Unew;
- }
- }
- } while (d > 0.0001);
- printM(u);
- Console.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement