| 查看: 823 | 回复: 0 | ||
[求助]
大家帮忙看一下这个C#求解线性方程组的程序那里有问题?
|
|
程序编译没错误,可是算出来的结果不对。小弟才学习C#还请多多指教! namespace 解线性方程组 { class Program { static void Main(string[] args) { int amount;//存储方程组的方程个数 double[,] m;//二维数组用于表示存放方程系数的系数矩阵 double[] solution;//一维数组用于存放方程组的解 double t1, t2; Console.WriteLine("Input number of equation" ;//接收用户输入的方程个数amount = Convert.ToInt32(Console.ReadLine()); m = new double[amount, amount + 1]; solution = new double[amount]; Console.WriteLine("Input coefficient of equation" ;for (int i = 0; i < amount; i++) { for (int j = 0; j < amount + 1; j++) m[i, j] = Convert.ToDouble(Console.ReadLine()); } Console.WriteLine("The coefficient of equation is:" ;Console.WriteLine("-------------------------------" ;for (int i = 0; i < amount; i++) { for (int j = 0; j < amount + 1; j++) Console.Write("{0,8}", m[i, j]); Console.WriteLine(); } for (int i = 1; i < amount; i++) { for (int j = i; j < amount; j++) { double coef = -m[j, i - 1] / m[i - 1, i - 1]; for (int k = i - 1; k < amount + 1; k++) { m[j, k] += m[i - 1, k] * coef; } } } t1 = m[amount - 1, amount - 1]; solution[amount - 1] = m[amount - 1, amount] / t1; for (int i = amount - 1; i >= 0; i--) { t2 = 0d; for (int j = i + 1; j <= amount - 1; j++) { t2 += m[i, j] * solution[j]; } solution = (m[i, amount] - t2) / m[i, i]; } Console.WriteLine(); Console.WriteLine("\n The result is:" ;Console.WriteLine("-----------------------" ;for (int i = 0; i < amount; i++) { Console.WriteLine("x[{0}] = 1", i, solution); } Console.Read(); } } } |
» 猜你喜欢
对氯苯硼酸纯化
已经有3人回复
求助:我三月中下旬出站,青基依托单位怎么办?
已经有12人回复
不自信的我
已经有12人回复
假如你的研究生提出不合理要求
已经有5人回复
所感
已经有4人回复
论文终于录用啦!满足毕业条件了
已经有28人回复
要不要辞职读博?
已经有7人回复
北核录用
已经有3人回复
实验室接单子
已经有3人回复
磺酰氟产物,毕不了业了!
已经有8人回复

找到一些相关的精华帖子,希望有用哦~
请教一个matlab求解非线性方程组的问题
已经有9人回复
用matlab求解非线性方程组说无解,一定是方程组本身无解,还是有可能程序有问题呢?
已经有11人回复
matlab如何求解一个非线性微分方程组
已经有8人回复
用fortran程序遗传算法解非线性方程组
已经有7人回复
MATLAB求解非线性方程组
已经有5人回复
【求助】非线性方程组的求解问题
已经有6人回复
拟牛顿法求解复杂(带根号的)非线性方程组
已经有17人回复
求Matlab高手解决线性方程组的迭代求解问题
已经有17人回复
非线性方程组的解法
已经有5人回复
急切求助!一个mathematica求解一个简单一元非线性方程的问题
已经有4人回复
求助matlab---fsolve解非线性方程组
已经有6人回复
用不动点迭代求非线性方程组,求得的不是想要的解,怎么办
已经有12人回复
matlab求解非线性方程组
已经有16人回复
求matlab求解一个方程组的问题
已经有6人回复
求高人指点用matlab求解非线性方程组,解决了追加100金币;
已经有11人回复
matlab的fsove 命令求解非线性方程组
已经有6人回复
【求助】用mathematica 5.0求解一个非线性方程组失败,特发帖求助!
已经有5人回复
【求助】matlab求解非线性方程组,并画图处理。要求y,z是实数解!
已经有18人回复
【求助】求教matlab解非线性方程组
已经有9人回复
【求助】求解非线性方程
已经有8人回复
科研从小木虫开始,人人为我,我为人人












;//接收用户输入的方程个数
回复此楼
点击这里搜索更多相关资源