Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0
Include Page
SIMULATION: MATLAB Google AnalyticsSIMULATION:
MATLAB Google Analytics
Include Page
SIMULATION: Intro Learning Module - PanelSIMULATION:
Intro Learning Module - Panel

...

Launch MATLAB on your computer. Set the matlab101 folder as your Current 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. From the home tab select Help > Documentation or simply click the documentation icon shown by an interrogation point. Enter the search phrase solve simultaneous equations and hit Enter. Select the hit entitled Systems of Linear Equations. It's usually easiest to start by looking at the examples provided which tend to be towards the bottom of the help pages. Scroll down to look at the first example under Square Systems.

   

This example shows you how to use the \ (mldivide) operator to solve a matrix system.  This documentation page has some juicy information; glance through it for future reference.unmigrated-wiki-markup

We'll work in the <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 matrix <span style="color: blue"><em>A</em></span> by entering {{A = \[1 1; 0 12\]}} at the command the Command Window and enter the MATLAB commands at the prompt >>. Create matrix A 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 matrix B:

...

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

Are these the values you expect?

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

...

Save this file: Click on the Save icon
Enter beam for File name. This will create a .m (script) file. 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:

...


Save and run the program again, this time using the Run icon     from the Editor tab. Check the result in the Command window.
Add comments to your program to lay out, in a human language, what it does. Comments are prefixed with a %; See below.

Any line beginning with a % will be skipped over by MATLAB; these are for human eyes only. You should add comments to your program to remind yourself what it does. Otherwise, a few months (or days!) down the line, you'll look at it, wonder what all the fuss is about and curse the ^&^*%%&* author.

...