Solving Linear Equations
Learn how to solve a system of linear equation in MATLAB.
Published: 3 Nov 2020
In today's MATLAB Basics, I want to show how to solve a simple set of linear equations. The equations we'll be solving today are shown here-- 2x equals 3y plus 1 and x plus y equals 4. Since this is MATLAB, or Matrix Laboratory, we're going to want to get this into a matrix format.
We can do this by rearranging the top equation to gather all the x's and y's on one side. Once we do that, we get it into the matrix form. To enter this into MATLAB, we'll use the following notation, where we're going to call the left-hand matrix, A, a two-by-two. We'll call our x and y variables matrix B. And then we will call the right-hand side, matrix C.
To enter this into MATLAB, we will use two lines of code. Let's actually type those in. We type these in as a is equal to, and then square brackets for a matrix. We're going to go across the columns-- 2 minus 3. A semicolon to drop down to the next row-- 1 and 1. And then we're going to enter the C matrix by saying, c is equal to 1 and 4.
When we do that, we see that we got a row vector instead of a column vector. We can hit up arrow, and then put an apostrophe. And that's going to transpose our matrix.
Finally, if we want to solve this, we can simply say that b is equal to a back-divide by c. And we'll get our result. If we want to look at this result as a fraction, we could change our format-- format rational. And now we see it as a fraction.
I'm going to go back to my normal format. And we can finally test this. We can say, a times b. And we'll see that that is the right-hand side. Thank you.
Featured Product
MATLAB
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)