Matlab-2.doc



|MAT 274 |Elementary Differential Equations |Fall 1995 |

MATLAB 1.2: Creating matrices and first plots

| |

Objectives:

Getting started on learning alternatives how to efficiently create large matrices.

Rationale:

Three-by-three matrices are fine examples when studying most theoretical aspects in linear algebra.

In realistic applications thirty-by-thirty (or even 3000 by 3000) matrices are not at all uncommon.

Nobody would want to enter these by hand, component by component.

| |

1. The graph of a (scalar) function (of one variable):

Recall making a table of function values (by hand or EXCEL), plotting it point by point, connecting the dots.

In MATLAB it is done in a way very similar to EXCEL: First create a vector (a column) of x-values, then apply the function f to each x value and obtain a vector (another column) of y-values (ALERT: most mathe-maticians cringe at the application of the function f to a vector). Plot one vector (column) against the other.

Task (10 min):

Check the help for plot.

Create a plot for a function like sin or x->x^2 using 500 data points (pick your favorite function).

Expect trouble with the differences between .* and * or ./ and / or .^2 and ^2. This may take some time!

For fun try out various plot styles (like 'r-' , 'yo', or 'c*').

Prepare one presentation per team -- a team representative will be chosen at random to explain the steps.

| |

2. Creating matrices:

MATLAB essentially recognizes only one data structure: EVERYTHING is a matrix!

You know how to type in a matrix component-by-component.

For the graph using 500 points this was out of question -- you used ranges!

In the first class using MATLAB you learnt a few special commands like zeros, eye that make matrices.

But there are many more -- and we will need many of them! (check out hilbert, magic, meshgrid ......)

Task (10 min) (Team-to-team competition)

Find as many, essentially distinct, ways to create (usually large) matrices as possible. 12 is a good target!

Homework (due Friday, in teams):

Find even more ways -- try to get at least twenty. Bonus credit for the winning team, and for two volunteers who will summarize (for distribution to the whole class) all discoveries presented Friday.

Hints:

Except for asking MATLAB veterans (which should be properly acknowledged, and is not really fair),

your only choice is to browse the HELP INDEX. Pay attention to examples and referrals ``SEE ALSO''

| |

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download