creating arrays problem: give 3 different matlab commands to create the array shown below x = [ 2...

Post on 18-Jan-2016

214 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

1-d Arrays &

Plotting

Creating ArraysProblem: Give 3 different MATLAB commands to create the array shown below

x = [ 2 2.2 2.4 2.6 2.8 3.0 3.2]

Answers:>> x = [ 2 2.2 2.4 2.6 2.8 3.0 3.2]>> x = 2:0.2:3.2>> x = linspace(2, 3.2, 7)

Creating ArraysWhy can’t the array shown below be created using a single linspace or start:inc:max command?

x = [ 2 2.2 2.4 2.6 3.0 3.2]

Answer: Need equal spacing between the values.

However, you can concatenate vectors:

>> x = [ 2:0.2:2.6 3 3.2]>> x = [ linspace(2,2.6,4) 3 3.2]

PlottingPlot the following polynomial in MATLAB:

What are the steps?

1) Create a t-vector of values

2) Calculate the y-values (remember arithmetic operators and entry by entry operators)

3) Use >> plot(t,y)

Demo Plot Tools

All plots should be labeled and titled. This can be done at the MATLAB command line using xlabel, ylabel, and title. Plots can also be formatted using commands within the plot statement.

Plot tools provides an alternative option for labeling, formatting, adjusting range, adding text boxes, ....

Solving Equations GraphicallyConsider the same polynomial.

Use the data cursor to find the roots of the polynomial. How many roots should there be? Do we need to change our plot?

Graphs on Same PlotGraph both of these decaying exponentials on the same plot and add a legend.

This can be done in a single plot statement.What is a good range for t? (Hint: e-5 is very small)

Subplot CommandGraph these two functions in separate sub-windows using the subplot command.

top related