[Content_Types].xml
_rels/.rels
matlab/document.xml
matlab/output.xml
metadata/coreProperties.xml
metadata/mwcoreProperties.xml
metadata/mwcorePropertiesExtension.xml
metadata/mwcorePropertiesReleaseInfo.xml
MATLAB Systems of Linear Equations In this livescript, you will learn how MATLAB solves systems of linear equations Consider the system of equations 2x-3y+5z=10 4x+7y-2z=-5 2x-4y+25z=31 Equation 1. In order to solve such a system using numerical linear algebra, we have to place these equations into matrix form Part 1: (a) Write this system in the form [A]\{x\}=\{c\} If you are quite lazy, MATLAB can in fact do this for you using the function \texttt{equationsToMatrix} . (b) Run the following code and check your answer to (a). syms x y z
eq1 = 2*x – 3*y + 5*z == 10;
eq2 = 4*x + 7*y – 2*z == -5;
eq3 = 2*x – 4*y + 25*z == 31;
[A,c] = equationsToMatrix([eq1,eq2,eq3],[x,y,z]) The first line \texttt{syms} declares that the variables \texttt{x} , \texttt{y} , and \texttt{z} are symbolic. We then need to define our system of equations \texttt{eq1} , \texttt{eq2} , and \texttt{eq3} . Finally, we can feed these equations into \texttt{equationsToMatrix} by specifying the equations in a vector as well as the symbolic variables. Once we’ve done this, we can utilise the vast library of solvers available in MATLAB. The most versatile being the \texttt{\\} command, which can be used to solve [A]\{x\}=\{c\} by calling x = A\c The beauty of this function is that it is able to take advantage of the symmetries of the matrix [A] . We won’t cover most of the special cases here, but if you can find out more here . If you’re just interested in using LU decomposition, the functions \texttt{linsolve}
\texttt{lu} can do that. The only difference is between the two are that \texttt{linsolve} only returns the solution vector \texttt{x} , while \texttt{lu} returns the lower and upper matrices \texttt{L} and \texttt{U} . As for iterative methods, MATLAB does offer a number of solvers, which you may view here .
manual code ready 0.4 symbolic
A 6 symbolic
c 6 symbolic
x 7 true false syms x y z 0 18 18 false false eq1 = 2*x – 3*y + 5*z == 10; 1 19 19 false false eq2 = 4*x + 7*y – 2*z == -5; 2 20 20 false false eq3 = 2*x – 4*y + 25*z == 31; 3 21 21 false true [A,c] = equationsToMatrix([eq1,eq2,eq3],[x,y,z]) 4 23 23 0 1 true true x = A\c 5 28 28 2 true false A1 = rand([10000,10000]); 6 39 39 false false b = rand([10000,1]); 7 39 39 false false tic 8 39 39 false false x = A1\b; 9 39 39 false false toc 10 39 39 false false A2 = triu(A1); 11 39 39 false false tic 12 39 39 false false x = A1\b; 13 39 39 false true toc 14 39 39
2020-03-18T01:08:17Z 2020-03-18T02:03:30Z
application/vnd.mathworks.matlab.code MATLAB Code R2019b
9.7.0.1183724 e460efb1-79c0-4de2-8c99-df1acd58fb13
9.7.0.1296695
R2019b
Update 4
Jan 20 2020
3546228467