ANTICHAT.XYZ    VIDEO.ANTICHAT.XYZ    НОВЫЕ СООБЩЕНИЯ    ФОРУМ  
Баннер 1   Баннер 2
Antichat снова доступен.
Форум Antichat (Античат) возвращается и снова открыт для пользователей. Здесь обсуждаются безопасность, программирование, технологии и многое другое. Сообщество снова собирается вместе.
Новый адрес: forum.antichat.xyz
Вернуться   Форум АНТИЧАТ > SЕО/Финансовые задачи/Социальные сети > Покупка, Продажа, Обмен > О Работе
   
Закрытая тема
 
Опции темы Поиск в этой теме Опции просмотра

Решение линейных уровнений медотом гаусса и крамера
  #1  
Старый 01.05.2009, 19:00
oleandr
Флудер
Регистрация: 27.04.2009
Сообщений: 4,294,967,295
Провел на форуме:
32025

Репутация: 2


По умолчанию Решение линейных уровнений медотом гаусса и крамера

Здравствуйте,я почитал ваш форум и понял что тут сидят норм прогеры мб у кого то будет несколько лишних минут, и напишит данную прогу на C#

Заранее благодарю !
 

  #2  
Старый 01.05.2009, 19:53
Flame of Soul
Участник форума
Регистрация: 25.05.2007
Сообщений: 290
Провел на форуме:
1740746

Репутация: 435
Отправить сообщение для Flame of Soul с помощью MSN
По умолчанию

Решение СЛАУ методом Гаусса
(написано на С, в С# переведете сами, я простыла и с температурой как то лень)

PHP код:
#include "stdio.h"
#include "iostream.h"

// возвращает true если LU-разложение для матрицы,
// состоящей из строк и столбцов с currRowAndColumn п numberOfEquation, было найдено
bool getLUDecompositiondouble **matrixUdouble **matrixLint currRowAndColumnint numberOfEquation ) {
    
bool result;
    
int ik;            // переменные циклов 
    
double tempItem;    // Вспомогательная переменная
    // если текущий элемент на диагонали равен 0 - LU-разложение не найдено
    
result = ( matrixU[currRowAndColumn][currRowAndColumn] != );        
    if ( 
result && currRowAndColumn numberOfEquation ) {
        
// определение новых значений элементов матрицы U
        // и получение нового столбца в матрице L
        
for ( currRowAndColumn 1numberOfEquationi++ ) {
            
matrixL[i][currRowAndColumn] = matrixU[i][currRowAndColumn] / matrixU[currRowAndColumn][currRowAndColumn];
            
tempItem = - matrixL[i][currRowAndColumn];
            for ( 
currRowAndColumnnumberOfEquationk++ ) {
                
matrixU[i][k] = matrixU[i][k] + matrixU[currRowAndColumn][k]*tempItem;
            }
        }
        
// рекурсивный вызов
        
result getLUDecompositionmatrixUmatrixLcurrRowAndColumn 1numberOfEquation );
    }

    return 
result;
}

void main() {
    
int ij;
    
int size;
    
double **matrixU, **matrixL;

    
cout << "Gauss'es method of LU.\nEnter system dimension: ";
    
cin >> size;

    
matrixU = new double*[size];
    
matrixL = new double*[size];
    for ( 
0sizei++ ) {
        
matrixU[i] = new double[size];
        
matrixL[i] = new double[size];
        for ( 
0size++ ){
            
matrixL[i][j] = ( == );
        }
    }

    for ( 
0size++ ){
        
cout << "Enter " << << " row: ";
        for ( 
0size++ ){
            
cin >> matrixU[i][j];
        }
    }

    if ( !
getLUDecompositionmatrixUmatrixL0size ) ) {
        
cout << "LU-decomposition for this matrix not found";
    }
    else {
        
cout << "L-matrix is:\n";
        for ( 
0size++ ){
            for ( 
0size++ ){
                
cout << matrixL[i][j] << " ";
            }
            
cout << "\n";
        }
        
cout << "\nU-matrix is:\n";
        for ( 
0size++ ){
            for ( 
0size++ ){
                
cout << matrixU[i][j] << " ";
            }
            
cout << "\n";
        }
    }
    
cout << "\nPress \"Enter\" to continue..." << endl
    
getchar();    

Решение СЛАУ методом Краммера:
(вроде рабочее, проверяйте сами)

PHP код:
#include <iostream.h>  
#include <stdio.h> 
#include <math.h> 
double DET (unsigned int columns);
bool PROVCOL(unsigned int numchar colNum);
unsigned int Column1(unsigned int numchar colNum);
unsigned int Column0(unsigned int numchar colNum);
double **Matrix;
int n;
main()
{
     
int ij
     
double mainDET
     
cout<<"Vvedite kolichestvo uravneniy "<<endl;
     
cin>>n;
     while (
10 || 1)
     {
          
cout<<"Vu ne mogete vvesti bol'she 10 ili men'she 1 uravneniya, vvedite esche raz ";
          
cin>>n;
     }
     
     
Matrix = (double**) new double[n];
     for (
i=0i<= n-1i++)
     {
Matrix[i] = new double[n+1];}
     for (
0<= n-1i++)
               for (
0<= nj++)
               {
                    
cout<<"Vvedite element matricu s koordinatami ("<<i<<","<<j<<") ";
                    
cin>>Matrix[i][j];
               }
     
cout<<"Vasha matrica:\n";
     for (
0<= n-1i++)
     {for (
0<= nj++)
          
cout<<Matrix[i][j]<<"\t";
          
cout<<endl;
     }
     
mainDET DET(pow(2,n));
     if (
mainDET == 0)
     {
         
cout<<"Net resheniy!\n";
     }
     else
     {
      
printf ("Korni sistemu:\n");
               for (
i=0<= n-1i++)
               
printf ("%.3f ", -pow(-1,n+i)*DET(pow(2,i))/mainDET);
          
printf ("\n");
     }
     
cout<<"Detrmenant sistemu raven: "<<mainDET<<endl;
     for (
0<= (n-1); i++) 
     
delete Matrix[i];
     
delete Matrix;
     
cout<<"Vuchisleniya zakonchenu. Spasibo chto vubrali nas!\n";
     return 
0;
}


double DET (unsigned int columns)
{
double det 0;
    
int inumCols 0lastFalsecntr 0;
     for (
i=0i<=ni++) 
     {
      if (
PROVCOL(columnsi)) 
      
numCols++;
      else 
lastFalse i;
     }
    if ((
numCols) == 0det Matrix[n-1][lastFalse];
     else
         for (
0<= ni++)
               if (!
PROVCOL(columnsi))
               {
                    
columns Column1(columnsi);
                    
det += pow(-1,(cntr))*Matrix[numCols-1][i]*DET(columns);
                    
columns Column0(columnsi);
                    
cntr++;
               }
     return 
det;
}
bool PROVCOL(unsigned int numchar colNum)
{
     
_asm
     
{
          xor 
eaxeax//в данном случаи обнуляет eax
          
xor ebxebx//тоже самое но для ebx
          
mov blcolNum//bl=colNum
          
bt numebx//считываем ebx бит из num в регистр флагов
          
jnc none//был перенос(ответ в флаге переноса)? Нет (флаг переноса 0), тогда переход на метку none
          
inc eax//увеличить eax
          
none//просто метка
     
}
}
unsigned int Column1(unsigned int numchar colNum)
{
     
_asm
     
{
          xor 
eaxeax
          
mov alcolNum
          
bts numeax
     }
     return 
num
}
unsigned int Column0(unsigned int numchar colNum)
{
     
_asm
     
{
          xor 
eaxeax
          
mov alcolNum
          
btr numeax
     }
     return 
num

 

  #3  
Старый 01.05.2009, 20:03
oleandr
Флудер
Регистрация: 27.04.2009
Сообщений: 4,294,967,295
Провел на форуме:
32025

Репутация: 2


По умолчанию

спасибо большое за быстрый отзыв , но если все таки кто нибудь переведет на С# буду очень благодарен
 

  #4  
Старый 03.05.2009, 09:49
procedure
Banned
Регистрация: 22.12.2007
Сообщений: 660
Провел на форуме:
3885269

Репутация: 1158


По умолчанию

Код:
using System;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            int size;

            Console.WriteLine("Gauss'es method of LU.\nEnter system dimension: ");
            size = int.Parse(Console.ReadLine());

            double[,] matrixU = new double[size, size];
            double[,] matrixL = new double[size, size];

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    matrixL[i,j] = (i == j ? 1 : 0);
                }
            }
            for (int i = 0; i < size; i++)
            {
                Console.WriteLine("Enter " + (i + 1) + " row: ");

                for (int j = 0; j < size; j++)
                {
                    matrixU[i,j] = double.Parse(Console.ReadLine());
                }
            }
            if (!getLUDecomposition(ref matrixU, ref matrixL, 0, size))
                Console.WriteLine("LU-decomposition for this matrix not found");
            else
            {
                Console.WriteLine("L-matrix is:\n");
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        Console.WriteLine(matrixL[i, j] +  " ");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine("\nU-matrix is:\n");
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        Console.WriteLine(matrixU[i,j] + " ");
                    }
                    Console.WriteLine();
                } 
            }

        }

        static bool getLUDecomposition(ref double[,] matrixU, ref double[,] matrixL, int currRowAndColumn, int numberOfEquation)
        {
                if (matrixU[currRowAndColumn, currRowAndColumn] == 0
                    && currRowAndColumn < (numberOfEquation - 1))
                    return false;
            double temp;

            for (int i = currRowAndColumn + 1; i < numberOfEquation; i++)
            {
                matrixL[i, currRowAndColumn] = matrixU[i, currRowAndColumn] / matrixU[currRowAndColumn, currRowAndColumn];
                temp = -matrixL[i, currRowAndColumn];
                for (int k = currRowAndColumn; k < numberOfEquation; k++)
                {
                    matrixU[i, k] = matrixU[i, k] + matrixU[currRowAndColumn, k] * temp;
                }
            }
            return getLUDecomposition(ref matrixU, ref  matrixL, currRowAndColumn + 1, numberOfEquation);
        }
    }
}
я даж не запускал. Не знаю что за бурда вышла)
 

  #5  
Старый 04.05.2009, 07:18
oleandr
Флудер
Регистрация: 27.04.2009
Сообщений: 4,294,967,295
Провел на форуме:
32025

Репутация: 2


По умолчанию

спасибо
 

  #6  
Старый 18.05.2009, 17:29
oleandr
Флудер
Регистрация: 27.04.2009
Сообщений: 4,294,967,295
Провел на форуме:
32025

Репутация: 2


По умолчанию

как всегда дотянулся, сам занят курсовой по линейке, времени на эту нет.

Мб есть авантюристы которые перепишут код для C#

рублей за 300 мб кто сделает
 

  #7  
Старый 19.05.2009, 20:27
oleandr
Флудер
Регистрация: 27.04.2009
Сообщений: 4,294,967,295
Провел на форуме:
32025

Репутация: 2


По умолчанию

ап
 
Закрытая тема





Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
 


Быстрый переход




ANTICHAT.XYZ