简体   繁体   中英

solving linear equations using matrices in MATLAB

my script creates a matrix and 2 vectors using several 'for' loops and as an example they are returned as follows:

K =

  1.0e+006 *

    1.2409    0.6250    0.8153    0.1250
    0.6250    3.6591   -0.1250    3.5375
    0.8153   -0.1250    1.2409   -0.6250
    0.1250    3.5375   -0.6250    3.6591

F =

  1.0e+006 *

    0.1733
    1.3533
   -0.1066
    1.3371

U =

 u3
 v3
 u4
 v4

As can be seen, the 'U' vector is a set of variables and I need to solve 'K*U=F' for variables contained in 'U' .

When I try to do that using linsolve or solve I get unexpected results and a message that the inverse of my matrix is close to singular.

HOWEVER, when I make another script and put in the SAME matrix and vectors BY HANDS it all works fine and I can't figure out what's wrong.

Is that somehow related to the way MATLAB stores matrices created by loop functions and I need to change the state of the matrix to something after the loop?

Also, when I put the matrix by hands it displays it without the 1.0e+006 multiplier in front of it:

K11 =

     1240900      625000      815300      125000
      625000     3659100     -125000     3537500
      815300     -125000     1240900     -625000
      125000     3537500     -625000     3659100

can that be related??

Thanks in advance.

Try the backslash operator:

U = K\F

See this reference .

From the previous discussion it's clear that your matrix is singular. This means that your equations are not linearly independent. When this happens there are two possibilities. Your system may be inconsistent (over-constrained), in which case no solutions exist. Or alternatively, it can also mean that your equations are under-constrained, in which case there is an infinite set of solutions.

To determine which case it is you can use rref to get the "row reduce echelon form" of the matrix. Do this as follows:

 KF = [K,F]
 rref(KF)

If the last row goes entirely to zeros then you're under-constrained and can extract a solution set (but not a unique solution) from your reduced matrix.

In this case however I get a row of [0 0 0 0 1], which makes the system over-constrained and hence without any solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM