4.8.1: Plotting Vectors Additional Material
- Page ID
- 87663
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\dsum}{\displaystyle\sum\limits} \)
\( \newcommand{\dint}{\displaystyle\int\limits} \)
\( \newcommand{\dlim}{\displaystyle\lim\limits} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\(\newcommand{\longvect}{\overrightarrow}\)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\ket}[1]{\left| #1 \right>}\)
\(\newcommand{\bra}[1]{\left< #1 \right|}\)
\(\newcommand{\braket}[2]{\left< #1 \vphantom{#2} \right| \left. #2 \vphantom{#1} \right>}\)
\(\newcommand{\braopket}[3]{\left< #1 \vphantom{#2}\vphantom{#3} \right| #2 \vphantom{#1}\vphantom{#3} \left| #3 \vphantom{#1}\vphantom{#2} \right>}\)
\(\newcommand{\qmvec}[1]{\mathbf{\vec{#1}}}\)
\(\newcommand{\op}[1]{\hat{\mathbf{#1}}}\)
\(\newcommand{\expect}[1]{\langle #1 \rangle}\)
\(\newcommand{\dfn}[1]{\emph{\textbf{#1}}}\)
Watch this video on making an x-y plot with vectors. It also shows how to plot 2 curves on 1 figure with "hold on".
MATLAB Function Plotting Basics, Robert Talbert
Important note:
When a function has more than 1 input, you must put commas between the inputs.
Even though you can leave-out commas when specifying a vector such as x = [1 2 5 8], this does not work for functions. The commas between the inputs are required.
Examples:
plot(x, y), not plot(x y)
plot(x, y, '*'), not plot(x y '*')
.
Additional MATLAB functions for labeling plots:
title() puts a title on a plot. The argument of title is a character string.
Examples:
title('sin(x) vs. t')
xlabel() and ylabel() put labels on the x and y axes of a plot.
Examples:
xlabel('Time (s)')
ylabel('Distance')
(1 pt) Create a Matlab script: voltage_vector_YourName.m
(1 pt) Clear any variables; close any figures; eliminate white space; clear the console
clear all; close all; format compact; clc;
%% V = IR
(2 pts) Create a vector I (current) from 0 to 15 amps in steps of 3 amps
(2 pts) Create a vector R (resistance) from 100 to 600 Ohms in steps of 100 Ohms
(2 pts) Compute the corresponding vector of voltages by multiplying I time R element-wise with this code
V = I.*R % (volts)
%% Plot
% (1 pt) Open a figure window
% (1 pt) Plot V (y-axis) vs. I (x-axis) with this code:
plot(I, V, '-o')
title('Voltage vs. Current')
% (1 pt) Label the x-axis with this code:
xlabel('I (amps)')
% (1 pt) Label the y-axis with this code:
ylabel('V (volts)')
- Answer
-
The solution is not given here.
.


