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

8
1-d Arrays & Plotting

Upload: beatrix-fitzgerald

Post on 18-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Creating Arrays Problem: 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

1-d Arrays &

Plotting

Page 2: Creating Arrays Problem: 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

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)

Page 3: Creating Arrays Problem: 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

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]

Page 4: Creating Arrays Problem: 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

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)

Page 5: Creating Arrays Problem: 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

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, ....

Page 6: Creating Arrays Problem: 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

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?

Page 7: Creating Arrays Problem: 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

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)

Page 8: Creating Arrays Problem: 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

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