Matlab中的高斯消除

Matlab中的高斯消除

本文介绍了Matlab中的高斯消除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用本书中的matlab代码: http://books.google.com/books/about/Probability_Markov_chains_queues_and_sim.html?id=HdAQdzAjl60C 这是代码:

I am using the matlab code from this book: http://books.google.com/books/about/Probability_Markov_chains_queues_and_sim.html?id=HdAQdzAjl60CHere is the Code:

    function [pi] = GE(Q)

    A = Q';
    n = size(A);
    for i=1:n-1
      for j=i+1:n
         A(j,i) = -A(j,i)/A(i,i);
      end
         for j =i+1:n
            for k=i+1:n
        A(j,k) = A(j,k)+ A(j,i) * A(i,k);
         end
      end
      end

     x(n) = 1;
      for i = n-1:-1:1
        for j= i+1:n
          x(i) = x(i) + A(i,j)*x(j);
        end
       x(i) = -x(i)/A(i,i);
      end

      pi = x/norm(x,1);

有我不知道的更快的代码吗?我要将此功能调用数百万次,并且需要太多时间.

Is there a faster code that I am not aware of? I am calling this functions millions of times, and it takes too much time.

推荐答案

MATLAB具有一整套内置的线性代数例程-输入help slashhelp luhelp chol即可开始学习其中的一些在MATLAB中有效求解线性方程组的常用方法.

MATLAB has a whole set of built-in linear algebra routines - type help slash, help lu or help chol to get started with a few of the common ways to efficiently solve linear equations in MATLAB.

在内部,这些函数通常调用优化的LAPACK/BLAS库例程,这些例程通常是在任何编程语言中进行线性代数运算的最快方法.与像MATLAB这样的慢速"语言相比,如果它们比m文件实现快几个数量级,那也就不足为奇了.

Under the hood these functions are generally calling optimised LAPACK/BLAS library routines, which are generally the fastest way to do linear algebra in any programming language. Compared with a "slow" language like MATLAB it would not be unexpected if they were orders of magnitude faster than an m-file implementation.

希望这会有所帮助.

这篇关于Matlab中的高斯消除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 04:26