Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Launch MATLAB on your computer. Set the matlab101 folder as your Current Directoryby Directory by browsing to it using the browse button near the top of the MATLAB window (see image below). Confirm that the correct path appears in the Current Directory field.

Solve Matrix Equation in MATLAB

MATLAB comes with extensive on-line help. Let's see if this documentation can show us how to solve our simultaneous equations. Bring up the on-line help: Select Help > MATLAB Help. Click the Search tab, enter the search phrase solve simultaneous equations and hit Enter. Select the hit entitled mldivide \, mrdivide /. Scroll down to look at Example 1.

This example shows you how to use the {}(mldivide) operator to solve a matrix system. This help page has some juicy information; glance through it for future reference.

Wiki Markup
We'll work in the Command Window <span style="color: purple"><strong><em>Command Window</em></strong></span> and enter the MATLAB commands at the prompt >> <span style="color: purple"><strong><em>&gt;&gt;</em></strong></span>. Create matrixAmatrix <span style="color: blue"><em>A</em></span> by entering A = \[1 1; 0 12\] at the command prompt:

...

A semi-colon is used to start a new matrix row. Note that MATLAB shows you the resulting values for the elements of A. Similarly, create matrixBmatrix B:

Calculate the reaction matrix R using the \ {} operator by entering R = A\B.

...

The Workspace window shows all the currently defined variables. If you don't see this window, select Desktop > Workspace so that a tick mark appears next to the window name.

...

If you don't see this window, select Desktop > Command History .

We'll create a MATLAB program to calculate R using the above three statements. Nothing fancy here: the program will just be a text file with the above statements. Such a file is called an M-File. Let's take a peek at the documentation on M-Files. In the Help window, select

Contents (tab) > MATLAB > Programming > M-File Programming > Working with M-files

Glance through this section for future reference.

Bring up the Editor: Select the Command window by clicking in it. In the MATLAB GUI, select

File > New > M-File

In the Editor, enter the above three statements (you can be lazy like me and copy-and-paste from the Command History; hold down the Ctrl-key to select multiple statements simultaneously).

Save this file: File > Save

Enter beam.m for File name. M-Files need to have .m as the suffix. Make sure you are saving into your working directory. Click Save.

Run this program from the command line by typing in the filename without the .m suffix:

...