-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tex
More file actions
1062 lines (943 loc) · 32.3 KB
/
main.tex
File metadata and controls
1062 lines (943 loc) · 32.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass{beamer} % Use [compress] for presentation. [handout]
%=========================================================================================
% Beamer settings
%=========================================================================================
\input{macro/beamerthemeAmsterdam.sty}
\beamertemplatenavigationsymbolsempty % No navigation bar.
\setbeamertemplate{footline}[frame number]{}
%=========================================================================================
% Math Packages
%=========================================================================================
\usepackage{lmodern}
\usepackage{textcomp}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{dsfont}
\usepackage{bbm}
\usepackage{enumerate}
\usepackage{hyperref}
\usepackage{url,tabularx,array}
\usepackage{pdfsync}
%=========================================================================================
% Figure and Graphics
%=========================================================================================
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\graphicspath{{fig/}}
%\usepackage{tikz,pgfplots}
%\usetikzlibrary{arrows}
%\pgfplotsset{compat=newest}
%\pgfplotsset{plot coordinates/math parser=false}
%=========================================================================================
% Syntax Coloring for Matlab code
%=========================================================================================
\usepackage{courier}
\usepackage{color}
\usepackage{listings}
\input{macro/lstMatlab.tex} % Defines the Matlab code listing style and commands.
\newcommand{\tttbf}[1]{\texttt{\textbf{#1}}} % Matlab keywords: typewriter+bf.
\definecolor{blockbody}{rgb}{0.914,0.914,0.953}
\setbeamercolor{block body}{bg = blockbody}
\lstnewenvironment{matlabcodebeamer}[1][]{\lstset{style=Matlab,backgroundcolor=\color{blockbody},#1}}{}
%=========================================================================================
% User Defined Macro
%=========================================================================================
\input{macro/mathMacro.tex}
\input{macro/vectorMacro.tex}
\input{macro/matrixMacro.tex}
%=========================================================================================
% Information
%=========================================================================================
\title{Matlab Graphics}
\author{Cheng-An Yang}
\institute{UCLA HSSEAS Workshop}
\date{December 17, 2012} % Insert customized date.
%=========================================================================================
% Slides Begin Here.
%=========================================================================================
\begin{document}
\frame{\titlepage}
%=========================================================================================
\begin{frame}
\frametitle{Outline}
\tableofcontents[pausesections]
\end{frame}
%=========================================================================================
\section{2D Plots}
\begin{frame}
\frametitle{2D Line Plot}
\begin{figure}
\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{Line_Plot_2D_2_01.png}
\caption{Stock Indices\cite{matlab_gallery} }
\end{subfigure}%
~
\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{Add_Lines_to_Plot_1_01.png}
\caption{Step Response\cite{matlab_gallery}}
\end{subfigure}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Basic Line Plot}
\begin{block}{Syntax}
\begin{itemize}[<+->]
\item To create an empty figure, call
\begin{matlabcodebeamer}[frame=none]
figure;
\end{matlabcodebeamer}
\item To create a line plot of vector \texttt{x} versus vector \texttt{t}, use
\begin{matlabcodebeamer}[frame=none]
plot(t,x);
\end{matlabcodebeamer}
\item You can input more vector pairs like
\begin{matlabcodebeamer}[frame=none]
plot(t1,x1,t2,x2);
\end{matlabcodebeamer}
\end{itemize}
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Basic Line Plot}
\begin{block}{Syntax}
\begin{itemize}[<+->]
\item Adding labels on axis
\begin{matlabcodebeamer}[frame=none]
xlabel('x label');
ylabel('y label');
\end{matlabcodebeamer}
\item Add title
\begin{matlabcodebeamer}[frame=none]
title('title for the figure');
\end{matlabcodebeamer}
\item Turn on/off the grid lines
\begin{matlabcodebeamer}[frame=none]
grid on;
grid off;
\end{matlabcodebeamer}
\item Adding legends
\begin{matlabcodebeamer}[frame=none]
legend('first','second',...);
\end{matlabcodebeamer}
\end{itemize}
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Basic Line Plot}
\textbf{Exercise}
Visualizing $\sin(t)$ and $\cos(t)$ on $0 \leq t \leq 2\pi$. \pause
\begin{figure}[htb]
\centering
\includegraphics[width=6cm]{basic_plot_sine}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Line Style}
\begin{itemize}[<+->]
\item Using the \textit{string specifier} to change the line style.
\item The \textit{string specifiers} contains
\begin{itemize}
\item Line style: \texttt{\{'-','--',':','-.','none'\}}
\item Marker symbol: \texttt{\{'+','o','*','.','x'\}} and more.
\item Color: \texttt{\{'r','g','b','w','k'\}}.
\end{itemize}
\item For example,
\begin{matlabcode}[numbers=none,frame=none]
plot(t,x,'--or');
plot(t,x,'r',t,y,'-.xk');
\end{matlabcode}
% \item RGB triple is a 3-vector
% \begin{matlabcode}[numbers=none,frame=none]
% c = [r b g];
% \end{matlabcode}
% where \texttt{r,g,b} are real numbers between 0 and 1.
% \item Color picker: returns a RGB triple
% \begin{matlabcode}[numbers=none,frame=none]
% c = uisetcolor;
% \end{matlabcode}
\end{itemize}
\end{frame}
%=========================================================================================
\begin{frame}{Line Style}
\textbf{Exercise}
Let
\begin{equation}
x(t) = t^2 \cos(5t) \e^{-t}.
\end{equation}\pause
The envelope of $x(t)$ is
\begin{equation}
y(t) = \pm t^2 \e^{-t}.
\end{equation}\pause
Please duplicate the figure shown below:
\begin{figure}[htb]
\centering
\includegraphics[width=5cm]{ex_line_style}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Plotting Complex Data}
\begin{block}{Syntax}
\begin{itemize}[<+->]
\item To plot complex array \texttt{x}, use
\begin{matlabcodebeamer}[frame=none]
plot(x);
\end{matlabcodebeamer}
\item It is equivalent to
\begin{matlabcodebeamer}[frame=none]
plot(real(x),imag(x));
\end{matlabcodebeamer}
\end{itemize}
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Plotting Complex Data}
\textbf{Example}
Visualizing the distribution of the eigenvalues of the random matrix. \pause
\begin{itemize}
\item Let \texttt{H} be an $n$-by-$n$ random matrix.
\item Let \texttt{x} be its eigenvalues.
\end{itemize}
\pause
\begin{figure}[htb]
\centering
\includegraphics[width=5cm]{random_matrix_eigenvalue}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Plotting Matrix Data}
\begin{block}{Syntax}
\begin{itemize}[<+->]
\item By default \tttbf{plot}\texttt{(Y)} will plot each column of \texttt{Y}.
\item When specifying the \texttt{x} vector,
\begin{matlabcodebeamer}[frame=none]
plot(x,Y);
\end{matlabcodebeamer}
will try to match the dimension of \texttt{x} and \texttt{Y}.
\end{itemize}
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Plotting Matrix Data}
\textbf{Example}
Plot \texttt{y = randn(5,3)} with and without \texttt{x = 1:3}.\pause
\setcounter{subfigure}{0}
\begin{figure}
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{plot_matrix_data1}
\caption{Without \texttt{x}.}
\end{subfigure}%
~\pause
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{plot_matrix_data2}
\caption{With \texttt{x}.}
\end{subfigure}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Plotting Multiple Lines On the Same Axes}
\begin{itemize}[<+->]
\item If you call \tttbf{plot} twice, the first plot will be erased.
\item To retain current graph when adding new graph, tell Matlab to
\begin{matlabcode}[frame=none]
hold on;
\end{matlabcode}
\item If you want different lines to have different color, use
\begin{matlabcode}[frame=none]
hold all;
\end{matlabcode}
\item The default is
\begin{matlabcode}[frame=none]
hold off;
\end{matlabcode}
\end{itemize}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Plotting Multiple Lines On the Same Axes}
\textbf{Exercise}
In our first sine wave example, we use
\begin{matlabcode}[frame=none]
plot(t,x,t,y)
\end{matlabcode}\pause
Now try
\begin{matlabcode}[frame=none]
plot(t,x);
hold all;
plot(t,y);
\end{matlabcode}
Change \texttt{'all'} to \texttt{'on'} and \texttt{'off'}.
\end{frame}
%=========================================================================================
\begin{frame}{Hierarchy of The Graphic Objects}
A Matlab plot is composed of (at least) three objects:
\setcounter{subfigure}{0}
\begin{figure}
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{figure_window.png}
\caption{Figure window.}
\end{subfigure}%
~\pause
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{empty_axis.png}
\caption{Axis object.}
\end{subfigure}
~\pause
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{lineseries_object.png}
\caption{Line series object.}
\end{subfigure}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Hierarchy of The Graphic Objects}
\begin{itemize}[<+->]
\item Each object has a unique identifier, called the \textbf{handle}.
\item You can ask Matlab to get and set the properties of the object with its handle.
\item To get the handle of the current figure, type
\begin{matlabcode}[frame=none]
h_fig = gcf;
\end{matlabcode}
\item To get the handle of the current axis, type
\begin{matlabcode}[frame=none]
h_ax = gca;
\end{matlabcode}
\item To get the handle of the line series, use
\begin{matlabcode}[frame=none]
h = plot(t,x);
\end{matlabcode}
\end{itemize}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Set and Get}
\begin{itemize}
\item Get the value of the property:
\begin{matlabcode}[frame=none]
value = get(h,'PropertyName');
\end{matlabcode}
\item Set using property-value pair:
\begin{matlabcode}[frame=none]
set(h,'PropertyName',value);
\end{matlabcode}
\end{itemize}
Complicated? Let's try an example.
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Set and Get}
\textbf{Example}
Plot $\sin(t)$ and $\cos(t)$. Change the line width and fine-tune the axis.
\setcounter{subfigure}{0}
\begin{figure}
\centering
\includegraphics[width=6cm]{set_axis_lineseries}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Linear and Log Scale}
\begin{itemize}[<+->]
\item By default \tttbf{plot} use linear scale on both axis.
\item Replace \tttbf{plot} by
\begin{itemize}
\item \tttbf{semilogx}
\item \tttbf{semilogy}
\item \tttbf{loglog}
\end{itemize}
\item Equivalently, use
\begin{matlabcode}[numbers=none,frame=none]
set(gca, 'XScale', 'log');
\end{matlabcode}
and/or
\begin{matlabcode}[numbers=none,frame=none]
set(gca, 'YScale', 'log');
\end{matlabcode}
\end{itemize}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Linear and Log Scale}
\textbf{Example}
The transfer function of a second order system has the form
$$H(s) = \frac{\omega_n^2}{s^2 + 2 \zeta \omega_n s + \omega_n^2},$$
where $\zeta$ is the damping ratio and $\omega_n$ is the natural frequency.
\pause
The frequecny response of a system is characterized by
\begin{itemize}
\item The magnitude $|H(\jmath \omega)|$
\item The phase $\angle H(\jmath \omega)$
\end{itemize}
In this example, we will plot the frequency response of $H(s)$.
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Linear and Log Scale}
\setcounter{subfigure}{0}
\begin{figure}
\centering
\includegraphics[width=6cm]{log_scale}
\caption{Frequency response of $H(s)$.}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Subplot}
\begin{block}{Syntax}
\begin{matlabcodebeamer}[frame=none]
subplot(m,n,1);
plot(t,x);
\end{matlabcodebeamer}
Will create a $m$-by-$n$ subplot and place the plot of \texttt{x} versus \texttt{t} at location 1.
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Subplot}
\textbf{Example}
Create 25 subplots of sine wave with increasing frequency.
\setcounter{subfigure}{0}
\begin{figure}
\centering
\includegraphics[width=6cm]{subplot_sine}
\end{figure}
\end{frame}
%=========================================================================================
\section{GUI and More 2D Plots}
\begin{frame}[fragile]
\frametitle{Adding Annotations}
\begin{block}{Syntax}
If you want to put \texttt{'some text'} at location \texttt{(x,y)}, type
\begin{matlabcodebeamer}[numbers=none,frame=none]
text(x,y,'some text');
\end{matlabcodebeamer}
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Adding Annotations}
\textbf{Example}
\setcounter{subfigure}{0}
\begin{figure}
\centering
\includegraphics[width=6cm]{set_axis_lineseries_text}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Adding Annotations}
\begin{itemize}[<+->]
\item It's a pain to calculate the coordinates, is there any easier way?
\item Luckily, Matlab provides a useful function
\begin{matlabcode}[numbers=none,frame=none]
gtext('some text');
\end{matlabcode}
\item Click on the figure to place the text.
\end{itemize}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{GUI}
It's about time to talk about the Graphical User Interface (GUI).
Pros:
\begin{itemize}
\item Easy to use.
\item No need to remember many commands.
\end{itemize}
\pause
Cons:
\begin{itemize}
\item Less flexible.
\item Can not batch process.
\end{itemize}
\pause
\begin{block}{Go with GUI if}
\begin{itemize}
\item There are only a few figures to edit.
\item No need to edit them in the future.
\end{itemize}
Otherwise using commands will be more efficient.
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Saving and Exporting}
Some tips about exporting figures:
\begin{itemize}[<+->]
\item Try to save to vector format.
\item Use `copy figure' on Windows.
\item Keep a \texttt{.fig} copy so you can edit it later.
\end{itemize}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Histogram}
\begin{block}{Syntax}
\begin{itemize}[<+->]
\item Create a histogram of data vector \texttt{x}
\begin{matlabcodebeamer}[numbers=none,frame=none]
hist(x);
\end{matlabcodebeamer}
% \item To specify number of bins, use
% \begin{matlabcodebeamer}[numbers=none,frame=none]
% hist(x,m);
% \end{matlabcodebeamer}
\end{itemize}
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Histogram}
\textbf{Example}
Linear Congruential Generator (LCG)
\begin{itemize}[<+->]
\item LCG is a popular (and old) Pseudo-Random Numbers Generator.
\item Simple and efficient to compute.
\item Well understood.
\item Poor choice of parameters lead to bad performance.
\end{itemize}
\pause
\begin{block}{LCG}
\begin{equation}
x_{n+1} \equiv \left( a x_n + b \right)~~\pmod{m},
\end{equation}
\begin{itemize}
\item $m > 0$: the modulus
\item $a > 0$: the multiplier
\item $b \geq 0$: the increment
\item $x_0$: the seed
\end{itemize}
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Histogram}
\textbf{Exercise}
Use
\begin{itemize}
\item $a = 3$
\item $b = 0$
\item $m = 31$
\item $x_0 = 1$
\end{itemize}
Generate $100$ samples to find its distribution.
\setcounter{subfigure}{0}
\begin{figure}
\centering
\includegraphics[width=5cm]{lcg_histogram}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Bar Chart}
\begin{block}{Syntax}
\begin{itemize}[<+->]
\item Create a bar chart
\begin{matlabcodebeamer}[numbers=none,frame=none]
bar(Y);
\end{matlabcodebeamer}
Each column of \texttt{Y} will have the same color and rows are grouped together.
\item It is equivalent to
\begin{matlabcodebeamer}[numbers=none,frame=none]
bar(Y,'grouped');
\end{matlabcodebeamer}
Try \texttt{'stacked'} instead of \texttt{'grouped'}.
\end{itemize}
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Bar Chart}
\textbf{Example}
\setcounter{subfigure}{0}
\begin{figure}
\centering
\includegraphics[width=6cm]{bar_chart}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Area Plot}
\begin{block}{Syntax}
\begin{itemize}
\item Stacks each data series and fill the underlying area with different colors
\begin{matlabcodebeamer}[numbers=none,frame=none]
area(X,Y);
\end{matlabcodebeamer}
\end{itemize}
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Area Plot}
\textbf{Example}
\setcounter{subfigure}{0}
\begin{figure}
\centering
\includegraphics[width=6cm]{area_plot}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Stem Plot}
Stem plot is useful for visualizing discrete time data.
\begin{block}{Syntax}
\begin{itemize}
\item Use exactly like the \tttbf{plot} function
\begin{matlabcodebeamer}[numbers=none,frame=none]
stem(t,x);
\end{matlabcodebeamer}
\end{itemize}
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Stem Plot}
\textbf{Example}
\setcounter{subfigure}{0}
\begin{figure}
\centering
\includegraphics[width=6cm]{stem_sine}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Polar Plot}
\begin{itemize}[<+->]
\item Sometimes it is easier to express coordinate in the polar form.
\item Let $(x,y)$ be the coordinates in the Cartesian coordinate system, its corresponding polar coordinates is given by
\begin{align}
r &= \sqrt{x^2 + y^2} \\
\theta &= \tan^{-1}(y/x).
\end{align}
\end{itemize}
\pause
\begin{block}{Syntax}
\begin{itemize}
\item Plot \texttt{r} versus \texttt{theta} in the polar coordinate
\begin{matlabcodebeamer}[numbers=none,frame=none]
polar(theta,r);
\end{matlabcodebeamer}
\end{itemize}
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Polar Plot}
\textbf{Example}
The butterfly fly curve, discovered by Temple H. Fay, is generated by the equations
\begin{equation}
r=e^{\sin \theta} - 2 \cos (4 \theta ) + \sin^5\left(\frac{2 \theta - \pi}{24}\right).
\end{equation}\pause
\setcounter{subfigure}{0}
\begin{figure}
\centering
\includegraphics[width=5cm]{polar_butterfly_curve}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Scatter Plot}
Scatter plot is used to visualize the distribution of two dimensional data.
\begin{block}{Syntax}
\begin{itemize}
\item to generate the scatter plot for the data vector \texttt{X} and \texttt{Y}
\begin{matlabcodebeamer}[numbers=none,frame=none,backgroundcolor=\color{blockbody}]
scatter(X,Y)
\end{matlabcodebeamer}
\end{itemize}
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Scatter Plot}
\textbf{Example} Linear Fitting
\begin{itemize}[<+->]
\item Suppose we are given a data set \texttt{x} and \texttt{y}.
\item It is assumed that $y = ax + b + \mbox{noise}$.
\item Find the best linear fit $\hat{y} = \hat{a} x + \hat{b}$.
\end{itemize}
\pause
\setcounter{subfigure}{0}
\begin{figure}
\centering
\includegraphics[width=6cm]{scatter_linear_fitting}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Contour Plot}
\begin{block}{Syntax}
\begin{itemize}[<+->]
\item The basic syntax is
\begin{matlabcodebeamer}[numbers=none,frame=none]
contour(Z);
\end{matlabcodebeamer}
\item You can specify the number of contour level
\begin{matlabcodebeamer}[numbers=none,frame=none]
contour(Z, n_level);
\end{matlabcodebeamer}
\end{itemize}
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Contour Plot}
\textbf{Example} Visualizing \texttt{peaks}
The Matlab function \texttt{peaks} is defined as
\begin{equation}
z = 3(1-x)^2 \e^{-x^2 - (y+1)^2} - 10(\frac{x}{5}-x^3-y^5)\e^{-x^2-y^2}-
\frac{1}{3}\e^{-(x+1)^2-y^2}.
\end{equation}\pause
\setcounter{subfigure}{0}
\begin{figure}
\centering
\includegraphics[width=6cm]{contour_peaks}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Animation}
The simplest way to generate animation in Matlab is use the template
\begin{matlabcode}[numbers=none,frame=none]
figure;
% Prevent Matlab reseting your view angle.
hold on;
for I=1:N
% Update your data here.
plot(t,x); % Draw new frame.
pause(0.1); % Pause for 0.1 seconds.
end
\end{matlabcode}
\end{frame}
%=========================================================================================
\section{3D Plots}
\begin{frame}[fragile]
\frametitle{3D Plot}
\begin{figure}
\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{Streamline_01.png}
\caption{Stream lines\cite{matlab_gallery} }
\end{subfigure}%
~
\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{Wind_01.png}
\caption{Wind Field\cite{matlab_gallery}}
\end{subfigure}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{3D Line Plot}
\begin{block}{Syntax}
\begin{itemize}
\item Plot lines in 3D
\begin{matlabcodebeamer}[numbers=none,frame=none]
plot3(x,y,z);
\end{matlabcodebeamer}
\end{itemize}
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{3D Line Plot}
\textbf{Example} 3D Brownian Motion:
the position $\vx_n$ of a Brownian particle at time $n$ is given by
\begin{equation}
\vx_n = \vx_{n-1} + \vv,
\end{equation}
where $\vv$ is a standard normal random vector.
\setcounter{subfigure}{0}
\begin{figure}
\centering
\includegraphics[width=6cm]{plot3D_brownian_motion}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{3D Line Plot}
\textbf{Example} Lorenz Attractor
Lorenz system is a simplified model for atmospheric convection, it is modeled by the ordinary differential equations
\begin{align}
\frac{dx}{dt} &= \sigma (y - x), \\
\frac{dy}{dt} &= x (\rho - z) - y, \\
\frac{dz}{dt} &= x y - \beta z,
\end{align}
where $x$, $y$ and $z$ are the coordinate of the state, $t$ represents time, $\rho$, $\sigma$ and $\beta$ are parameters.
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{3D Line Plot}
\textbf{Example} Lorenz Attractor
\setcounter{subfigure}{0}
\begin{figure}
\centering
\includegraphics[width=6cm]{lorenz_attractor}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Mesh Plot}
Mesh plot is used to visualize 2D scalar fields.
\begin{block}{Syntax}
\begin{itemize}
\item Plot \texttt{Z} as a function of \texttt{X} and \texttt{Y}
\begin{matlabcodebeamer}[numbers=none,frame=none]
mesh(X,Y,Z);
\end{matlabcodebeamer}
\end{itemize}
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Mesh Plot}
\textbf{Example} 3D Sinc function
The 3D sinc function is defined as
\begin{equation}
\sinc(\vx) = \frac{\sin(\| \vx \|)}{\| \vx \|}.
\end{equation}\pause
\setcounter{subfigure}{0}
\begin{figure}
\centering
\includegraphics[width=6cm]{mesh_3D_sinc}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Surface Plot}
Surface plot is mesh plot plus patches.
\begin{block}{Syntax}
\begin{itemize}
\item Plot \texttt{Z} as a function of \texttt{X} and \texttt{Y}
\begin{matlabcodebeamer}[numbers=none,frame=none]
surf(X,Y,Z);
\end{matlabcodebeamer}
\end{itemize}
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Surface Plot}
\textbf{Example} 3D Sinc function
\setcounter{subfigure}{0}
\begin{figure}
\centering
\includegraphics[width=6cm]{surf_3D_sinc}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Surface Plot}
\textbf{Example} 2D Wave Equation
The wave equation is a partial differential equation
\begin{equation}\label{eq:wave_eq}
u_{tt} = c^2 \Delta u - b u_t,\quad \mbox{where}
\end{equation}\pause
\begin{itemize}
\item $c$ is the wave speed
\item $b$ is the damping coefficient
\item $\Delta$ is Laplacian, defined as
\begin{equation}
\Delta u = u_{xx} + u_{yy}.
\end{equation}
\end{itemize}
\pause
We use the Finite Difference Method (FDM) to approximate
\begin{equation}
u_t \approx \frac{u(t+dt) - u(t)}{dt}.
\end{equation}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{Surface Plot}
\textbf{Example} 2D Wave Equation
\setcounter{subfigure}{0}
\begin{figure}
\centering
\includegraphics[width=6cm]{wave_fdm}
\end{figure}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{2D Vector Field}
\begin{block}{Syntax}
\begin{itemize}
\item Plot the vector field \texttt{Zx} and \texttt{Zy} as a function of \texttt{X} and \texttt{Y}
\begin{matlabcodebeamer}[numbers=none,frame=none]
quiver(X,Y,Zx,Zy);
\end{matlabcodebeamer}
\end{itemize}
\end{block}
\end{frame}
%=========================================================================================
\begin{frame}[fragile]
\frametitle{2D Vector Field}