线性方程求解导致程序退出(x64)

时间:2014-06-19 05:55:08

标签: ilnumerics

线性方程求解有一些问题。我有两个矩阵:A和B. 系统的维度是24(" A"是24x24矩阵)。 然后我调用" ILMath.linsolve(A,B)",程序意外关闭,没有任何异常或消息。 我发现这个问题出现在平台目标x64上,而x86则不存在。 有人会评论这个吗?对ILNumerics使用的错误或误解?

英特尔酷睿i7上的操作系统Windows 7(64位)。

以下是导致错误的矩阵(无法找到如何附加文件)。在x86平台上,结果是NaN,但这是可以接受的(与程序退出相反)。

P.S。可能与https://mediaautomat.de/mantis/view.php?id=178

有关

file:testMatrixSolver_ [24,24] .txt

A = 
<Double> [24,24]
(:,:) 1e+004 * 
0,00000    1,44682    0,88271    1,08754    2,84771    2,80983    3,64760    3,54584    4,21863    4,78911    4,19593    4,60941    5,16538    4,90552    4,87245    5,02034    5,42170    5,87407    5,85920    5,89104    6,08131    6,26784    6,56444    0,00010 
1,44682    0,00000    1,91625    1,33214    1,99742    2,83174    3,21557    4,10363    4,04118    3,84300    4,18627    3,99828    4,35512    4,61547    4,78964    5,29765    5,85039    5,70449    6,17333    6,30469    5,70157    6,30999    6,41938    0,00010 
0,88271    1,91625    0,00000    0,82227    2,68614    2,16273    3,20411    2,74905    3,65844    4,71273    3,56469    4,29182    5,02270    4,43590    4,30925    4,36273    4,80273    5,45878    5,30938    5,35701    5,80569    5,84445    6,29503    0,00010 
1,08754    1,33214    0,82227    0,00000    1,93358    1,83034    2,66562    2,95360    3,30749    4,07693    3,32752    3,73749    4,44312    4,05599    4,05870    4,39840    4,99967    5,20256    5,43769    5,58527    5,44640    5,76367    6,09578    0,00010 
2,84771    1,99742    2,68614    1,93358    0,00000    1,82125    1,46606    3,58486    2,52773    2,33607    2,87539    2,17512    2,76087    3,01279    3,40940    4,43698    5,33298    4,37984    5,60471    5,94724    4,26287    5,41505    5,35821    0,00010 
2,80983    2,83174    2,16273    1,83034    1,82125    0,00000    1,33559    1,89433    1,62275    3,64206    1,59220    2,62374    3,77787    2,53021    2,41331    2,99133    3,95767    3,80246    4,35438    4,74840    4,32867    4,50010    4,99090    0,00010 
3,64760    3,21557    3,20411    2,66562    1,46606    1,33559    0,00000    2,94252    1,12597    2,57844    1,59661    1,33467    2,61332    1,65705    2,05491    3,39554    4,54986    3,15292    4,77203    5,30888    3,31932    4,34527    4,34657    0,00010 
3,54584    4,10363    2,74905    2,95360    3,58486    1,89433    2,94252    0,00000    2,52378    5,09231    2,01864    4,00447    5,12100    3,36273    2,71871    1,93348    2,42875    4,11021    3,05014    3,25482    5,09454    4,05941    5,23146    0,00010 
4,21863    4,04118    3,65844    3,30749    2,52773    1,62275    1,12597    2,52378    0,00000    3,36997    0,62578    1,78442    3,21093    0,98858    0,96613    2,47528    3,80680    2,33181    3,96235    4,65882    3,04762    3,40287    3,69050    0,00010 
4,78911    3,84300    4,71273    4,07693    2,33607    3,64206    2,57844    5,09231    3,36997    0,00000    3,89486    1,79566    0,78164    3,19042    3,98246    5,35377    6,19888    4,27500    6,28968    6,62640    3,32117    5,67391    4,94431    0,00010 
4,19593    4,18627    3,56469    3,32752    2,87539    1,59220    1,59661    2,01864    0,62578    3,89486    0,00000    2,38476    3,76017    1,44043    0,89166    1,91209    3,26664    2,46461    3,46354    4,16939    3,46091    3,16292    3,83318    0,00010 
4,60941    3,99828    4,29182    3,73749    2,17512    2,62374    1,33467    4,00447    1,78442    1,79566    2,38476    0,00000    1,51218    1,47929    2,36528    4,04614    5,19817    2,79991    5,28332    5,86071    2,30655    4,41114    3,79334    0,00010 
5,16538    4,35512    5,02270    4,44312    2,76087    3,77787    2,61332    5,12100    3,21093    0,78164    3,76017    1,51218    0,00000    2,83580    3,70818    5,20484    6,11432    3,80128    6,16799    6,56776    2,64560    5,36160    4,41525    0,00010 
4,90552    4,61547    4,43590    4,05599    3,01279    2,53021    1,65705    3,36273    0,98858    3,19042    1,44043    1,47929    2,83580    0,00000    1,00339    2,91194    4,25484    1,58188    4,26136    5,04277    2,13430    3,15454    2,91422    0,00010 
4,87245    4,78964    4,30925    4,05870    3,40940    2,41331    2,05491    2,71871    0,96613    3,98246    0,89166    2,36528    3,70818    1,00339    0,00000    1,96941    3,40757    1,61655    3,41133    4,27827    2,87243    2,52115    3,05316    0,00010 
5,02034    5,29765    4,36273    4,39840    4,43698    2,99133    3,39554    1,93348    2,47528    5,35377    1,91209    4,04614    5,20484    2,91194    1,96941    0,00000    1,53942    3,01426    1,66056    2,52905    4,48908    2,36774    4,13186    0,00010 
5,42170    5,85039    4,80273    4,99967    5,33298    3,95767    4,54986    2,42875    3,80680    6,19888    3,26664    5,19817    6,11432    4,25484    3,40757    1,53942    0,00000    4,25928    0,86437    1,04855    5,56686    3,18305    5,11819    0,00010 
5,87407    5,70449    5,45878    5,20256    4,37984    3,80246    3,15292    4,11021    2,33181    4,27500    2,46461    2,79991    3,80128    1,58188    1,61655    3,01426    4,25928    0,00000    4,01693    4,96341    1,91873    2,09750    1,51094    0,00010 
5,85920    6,17333    5,30938    5,43769    5,60471    4,35438    4,77203    3,05014    3,96235    6,28968    3,46354    5,28332    6,16799    4,26136    3,41133    1,66056    0,86437    4,01693    0,00000    1,26782    5,43508    2,61931    4,77691    0,00010 
5,89104    6,30469    5,35701    5,58527    5,94724    4,74840    5,30888    3,25482    4,65882    6,62640    4,16939    5,86071    6,56776    5,04277    4,27827    2,52905    1,04855    4,96341    1,26782    0,00000    6,11622    3,76101    5,64400    0,00010 
6,08131    5,70157    5,80569    5,44640    4,26287    4,32867    3,31932    5,09454    3,04762    3,32117    3,46091    2,30655    2,64560    2,13430    2,87243    4,48908    5,56686    1,91873    5,43508    6,11622    0,00000    3,82539    2,06788    0,00010 
6,26784    6,30999    5,84445    5,76367    5,41505    4,50010    4,34527    4,05941    3,40287    5,67391    3,16292    4,41114    5,36160    3,15454    2,52115    2,36774    3,18305    2,09750    2,61931    3,76101    3,82539    0,00000    2,56155    0,00010 
6,56444    6,41938    6,29503    6,09578    5,35821    4,99090    4,34657    5,23146    3,69050    4,94431    3,83318    3,79334    4,41525    2,91422    3,05316    4,13186    5,11819    1,51094    4,77691    5,64400    2,06788    2,56155    0,00000    0,00010 
0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00010    0,00000 
B = 
<Double> [24,1]
(:,:) 1e+004 * 
1,43198 
1,76503 
2,28512 
2,32261 
3,60803 
3,98305 
4,57855 
4,72375 
5,18107 
5,20678 
5,21228 
5,31666 
5,62346 
5,71215 
5,75390 
5,93499 
6,23050 
6,47977 
6,53616 
6,54298 
6,54379 
6,76731 
6,87920 
0,00010 

测试和解析代码

// ReSharper disable InconsistentNaming
class Program
{
    static void Main()
    {

        try
        {
            TEST();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            Console.WriteLine(e.StackTrace);
        }
    }

    private static void TEST()
    {
        var curDir = Directory.GetCurrentDirectory() + "\\";

        Console.WriteLine("\r\nSolving equation (Dimension 24)\r\n");

        a = readMatrixA("matrixSample_[24,24].txt", 10000);
        b = readMatrixB("matrixSample_[24,24].txt", 10000);

        ILMath.linsolve(a, b);

        Console.WriteLine("\r\nPress any key to exit...");
        Console.ReadKey();
    }

    private static ILArray<double> readMatrixA(string filePath, double m)
    {
        if (!File.Exists(filePath))
            throw new Exception("File not found: " + filePath);

        var reader = new StreamReader(filePath);

        ILArray<double> result = new double[0,0];

        string line;

        var row=0;
        var col=0;
        while ((line = reader.ReadLine()) != null)
        {
            if (line.Contains("A = "))
            {
                reader.ReadLine();
                reader.ReadLine();
                line = reader.ReadLine();
            }

            if (line == null || line.Contains("B ="))
                break;

            var parts = line.Split(' ');
            foreach (var part in parts.Where(part => !String.IsNullOrEmpty(part.Trim())))
                result[row, col++] = Double.Parse(part.Trim(), CultureInfo.InvariantCulture) * m;

            row++;
            col = 0;
        }

        reader.Close();
        return result;
    }

    private static ILArray<double> readMatrixB(string filePath, double m)
    {
        if (!File.Exists(filePath))
            throw new Exception("File not found: " + filePath);


        var reader = new StreamReader(filePath);

        ILArray<double> result = new double[0,0];

        string line;

        var dataStart = false;
        var row=0;
        var col=0;
        while ((line = reader.ReadLine()) != null)
        {
            if (line.Contains("B = ") && !dataStart)
            {
                reader.ReadLine();
                reader.ReadLine();
                line = reader.ReadLine();
                dataStart = true;
            }

            if (!dataStart || line == null)
                continue;

            if (String.IsNullOrEmpty(line.Trim()) || line.Contains("C = "))
                break;

            var parts = line.Split(' ');
            foreach (var part in parts.Where(part => !String.IsNullOrEmpty(part.Trim())))
                result[row, col++] = Double.Parse(part.Trim(), CultureInfo.InvariantCulture) * m;

            row++;
            col = 0;
        }

        reader.Close();
        return result;
    }

}
// ReSharper restore InconsistentNaming

0 个答案:

没有答案