package com.smartmap.algorithm.equation.differential.partial.ellipsoidal;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringWriter; public class PoissonIteration {
public static void main(String[] args) {
int m = 64; int n = 32;
double minX = 0;
double maxX = 2;
double dx = (maxX - minX) / m;
double minY = 0;
double maxY = 1;
double dy = (maxY - minY) / n;
//
double xx[][] = new double[m+1][n+1];
//
System.out.println("----------------------------------------");
for(int j=0; j<m+1; j++)
{
double value = dx * j;
System.out.print(value + " ");
}
System.out.println("");
System.out.println("----------------------------------------");
for(int j=0; j<n+1; j++)
{
double value = dy * j;
System.out.print(value + " ");
}
System.out.println("");
//
for(int j=0; j<n+1; j++)
{
double value = dy * j;
xx[0][j] = getZeroXU(value);
xx[m][j] = getTwoXU(value);
}
for(int k=0; k<m+1; k++)
{
double value = dx * k;
xx[k][0] = getZeroYU(value);
xx[k][n] = getOneYU(value);
}
double error;
while(true)
{
error = gaussSeidelCompute(xx, m, n, dx, dy);
System.out.println("error: "+error);
if(error < 0.00000000001)
{
break;
}
}
System.out.println("--------------------------------");
for(int k=0; k<n+1; k++)
{
for(int j=0; j<m+1; j++)
{
System.out.printf(" %8.6f", xx[j][k]);
}
System.out.println(";");
}
} public static double gaussSeidelCompute(double[][] xx, int m, int n, double dx, double dy)
{
double dxdy = (1.0/Math.pow(dy, 2) + 1.0/Math.pow(dx, 2)) * 2;
double error = 0;
for(int i=1; i<m; i++)
{
for(int j=1; j<n; j++)
{
double oldValue = xx[i][j];
double x = 0 + dx * i;
double y = 0 + dy * j;
double f = getF(x, y);
xx[i][j] = (f + xx[i][j-1]*(1.0/Math.pow(dy, 2)) + xx[i-1][j]*(1.0/Math.pow(dx, 2)) + xx[i+1][j]*(1.0/Math.pow(dx, 2)) + xx[i][j+1]*(1.0/Math.pow(dy, 2)));
xx[i][j] = xx[i][j] / dxdy;
oldValue = Math.abs(xx[i][j] - oldValue);
if(oldValue > error)
error = oldValue;
}
}
return error;
}
public static void outputAA(double[][] aa, int elementCount, String filePath, String fileName)
{
try
{
FileOutputStream fileStream = new FileOutputStream(filePath + "\\"+fileName+".txt", false);
OutputStream outputStream = fileStream;
StringWriter streamWriter=new StringWriter();
for(int j=0; j<elementCount; j++)
{
for(int k=0; k<elementCount; k++)
{
streamWriter.write(String.format(" %8.6f", aa[j][k]));
}
streamWriter.write("\n");
}
char[] linearRingStringCharArray = streamWriter.toString().toCharArray();
for(int i=0; i<linearRingStringCharArray.length; i++)
{
outputStream.write(linearRingStringCharArray[i]);
}
fileStream.close();
streamWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static double getF(double x, double y)
{
double returnValue = 0;
returnValue = (Math.pow(Math.PI, 2) - 1) * Math.exp(x) * Math.sin(Math.PI * y);
return returnValue;
}
public static double getZeroXU(double y)
{
double returnValue = 0;
returnValue = Math.sin(Math.PI * y);
return returnValue;
}
public static double getTwoXU(double y)
{
double returnValue = 0;
returnValue = Math.exp(2) * Math.sin(Math.PI * y);
return returnValue;
}
public static double getZeroYU(double y)
{
double returnValue = 0;
return returnValue;
}
public static double getOneYU(double y)
{
double returnValue = 0;
return returnValue;
}
}

最新文章

  1. 逗号分隔的字符串转换为行数据(collection)
  2. api接口签名验证(MD5)
  3. SharePoint 2013 排错之&quot;Code blocks are not allowed in this file&quot;
  4. bigtint;int;smallint;tinyint
  5. Android ToggleButton使用介绍
  6. Dynamic Programming - leetcode [动态规划]
  7. MyBatis:学习笔记(1)——基础知识
  8. Ubuntu 16.04 安装Mysql 5.7 踩坑小记
  9. FeatureTools
  10. 纯原生JS大图轮播
  11. linux软件管理之rpm管理rpm包
  12. PowerShell 使用.NetFramework
  13. 卡尔曼滤波+单目标追踪+python-opencv
  14. [转]idea导入eclipse的web项目
  15. MySQL设置全局sql日志
  16. modelform的简介
  17. CVE-2017-12615漏洞利用
  18. linux通过speedtest-cli测试服务器网速
  19. LeetCode 题解之Plus One
  20. spring 发布 Jax-Ws Service (二)

热门文章

  1. Spark入门实战系列--3.Spark编程模型(上)--编程模型及SparkShell实战
  2. SQL一次查出多个字段的COUNT值
  3. 使用Microsoft Fakes进行单元测试(1)
  4. angularjs input上传图片前获取图片的Size
  5. 局部页面传值Model
  6. 开源的即时通讯框架 (endv.cn) (一)
  7. winform水平滚动条联动panel
  8. 不可或缺 Windows Native (12) - C++: 引用类型
  9. C语言文件方式输入与输出(最简洁方便实用的一种方式)
  10. How do I set the default schema for a user in MySQL