其他分享
首页 > 其他分享> > 使用matlab求解线性方程

使用matlab求解线性方程

作者:互联网

使用matlab求解线性方程

   

Ax = B 形式

 A ,B为矩阵

共有三种方法求解:

example
clear all
A = [3 -9; 2 4];
b = [-42; 2];
% three methods
x = inv(A)*b       % good
x = A\b            % better
x = linsolve(A,b)  % best

 https://www.mathworks.com/help/matlab/ref/linsolve.html 

syms a b c d e f 
 M = [a b;c d];
 rhs = [e;f];
 z = inv(M)*rhs

>> z = inv(M)*rhs
 
z =
 
 (d*e)/(a*d - b*c) - (b*f)/(a*d - b*c)
 (a*f)/(a*d - b*c) - (c*e)/(a*d - b*c)
 
>> z = M^-1*rhs
 
z =
 
 (d*e)/(a*d - b*c) - (b*f)/(a*d - b*c)
 (a*f)/(a*d - b*c) - (c*e)/(a*d - b*c)
 
>> z = linsolve(M,rhs)
 
z =
 
 -(b*f - d*e)/(a*d - b*c)
  (a*f - c*e)/(a*d - b*c)


>> M = [3 -9;2 4]
>> rhs = [-42;2];

>> z = inv(M)*rhs

z =

   -5.0000
    3.0000

>> z = M^-1*rhs

z =

   -5.0000
    3.0000

>> z = linsolve(M,rhs)

z =

    -5
     3

  

标签:求解,rhs,inv,linsolve,matlab,线性方程
来源: https://www.cnblogs.com/csymemory/p/14225661.html