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
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asie-Pacifique
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)