SlideShare a Scribd company logo
1 of 14
Download to read offline
Matlab Notes Part 1
Austin Baird
UNC Department of Mathematics
UNC Department of Biology
January 15, 2014
Introduction
• Matlab is a lot like a calculator!
• we can compute things like 3 · 2
• Arithmetic is preformed in order of operations (just like a
calculator)
• Matrices and matrix operations are where Matlab excels
• Today we will:
• Understand the basic Desktop environment
• Preform basic arithmetic
• use built in functions
• Create matices and write our first code
Desktop Basics
Desktop Basics
• Current Folder: This is where the files you are working
with will be stored. Note: you can navigate from the folder
you’re in to any folder you desire by clicking the magnifying
glass.
• Command Window: This is where you can calculate,
receive error messages, or print output from your
programs. Commands are input at the symbol.
• try to calculate things right now!
• Workspace: This is where variables are stored and will tell
you things about them (what they equal, how big a matrix is
ect.)
• Command History: This is where the commands you’ve
issued most recently will appear. ↑ on your keyboard will
scroll through these commands.
• Refer to the text (Matlab intro) for more detailed instruction.
Troubleshooting
• Often times things won’t work.
• One Common problem is that a variable you thought was
free is actually associated with a value.
• Try the command clear. This will clear all the variables
in the Workspace.
Try and do some computing and assign
variables to values.
Arrays
• Matlab = Matrix Laboratory, so do things with matrices!
• Create your first matrix!
• a = [1234], Row Vector!
• Indexing in matlab begins with 1 (NOT 0)
• Add more rows: a = [1234; 2345; 3456]
• Note This also works: a = [1, 2, 3, 4; 2, 3, 4, 5; 3, 4, 5, 6]
• We can call values from this array:
• a(1, 2)
• 2
• Or assign a value to a particular position:
• a(1, 2) = 10
• The notation is (row, column)
Array Creating Functions
• There are ways to automatically create an array(matrix) in
matlab:
• a = zeros(3, 2)
• Creates an array of all zeros (this is good for data
management if you want a set size for your matrix
• a = linspace(0, 1, 100)
• This creates a vector which has 100 points filled in between
0 and 1.
• a = 0 : 0.1 : 1
• this creates an array which has mesh width equal to 0.1
• How do we model functions in Matlab?
Array Operations
• Colon operator:
• a = [123; 234; 456]
• The colon denotes start:end. Note: if you just place a
colon it will select everything.
• Select the first two rows of our matrix:
• a(1 : 2, :)
• What does a(1, :) do?
• We can also add to each element of the array:
• a − a
• a − 10
• We can do traditional and element wise multiplication of
matrices:
• traditional: a ∗ a, element wise: a. ∗ a
• In a similar way you can do other things element wise to a
matrix ex.: a. ∧ 3
Discrete Functions
• In math things are continuous, in Matlab (and in
computational science in general) This is not the case.
• To compute and evaluate functions we need a Domain and
their corresponding function values Range
• To get a Domain in Matlab we must “discretize” our
continuous domain.
• We do this by creating a “mesh width” = size of our spacing
in our discretization
• ex: x = linspace(0, 1, 10) what is our mesh width dx
(x(2)-x(1))? is it always equal? Must consider this!
• ex: x = 0 : 0.1 : 1 what is our mesh width dx?
Evaluating Functions
• Now that we have a discretized version of the x-axis we
can now evaluate a function!
• Matlab has many built in functions (sin, cos, tan, exp...)
• y = sin(x)
• We now have a set of range values, how do we know that
this is right? Graph?
• plot this function: plot(y)
• In general the resolution of our function is dependent upon
our mesh width
• How small is enough, how big is too big? Does any mesh
width work?
• A quick and dirty estimate of the error between two arrays:
max(a − b) will select the max error between the arrays
(infinity norm).
• Plot sin over one period and experiment with different
mesh widths and their effects
Our First Program
• Matlab files are denoted by a .m at the end of the name.
• Documentation is very very important! % is how you
comment lines (these will not be read by the computer)
• Notice that to run the code Matlab asks you whether to add
folder to path or to change to directory, both work.
• Just type the name of the code in the command line to get
the program to run.
How to Run
Output
Homework
• Read sections 1-17 to 1-23
• Email me by Tuesday at 12:01am a onyen.m file which
when run does the following ( and is commented at the top
of the file with your full name and who you worked with, if
anyone):
• Generates a figure which plots y = sin(x) + c for ten values
of c (all on the same figure).
• Generates the figure in section 1-23.

More Related Content

What's hot

Lines and planes in space
Lines and planes in spaceLines and planes in space
Lines and planes in spaceFaizan Shabbir
 
Linear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorialLinear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorialJia-Bin Huang
 
Writing Fast MATLAB Code
Writing Fast MATLAB CodeWriting Fast MATLAB Code
Writing Fast MATLAB CodeJia-Bin Huang
 
Introduction to programming in MATLAB
Introduction to programming in MATLABIntroduction to programming in MATLAB
Introduction to programming in MATLABmustafa_92
 
Threads and Synchronization in c#
Threads and Synchronization in c#Threads and Synchronization in c#
Threads and Synchronization in c#Rizwan Ali
 
Introduction to programming using mat ab
Introduction to programming using mat abIntroduction to programming using mat ab
Introduction to programming using mat abAhmed Hisham
 
Alg II Unit 3-6-solvingsystemsmatrices
Alg II Unit 3-6-solvingsystemsmatricesAlg II Unit 3-6-solvingsystemsmatrices
Alg II Unit 3-6-solvingsystemsmatricesjtentinger
 
Alg II 3-6 Solving Systems - Matrices
Alg II 3-6 Solving Systems - MatricesAlg II 3-6 Solving Systems - Matrices
Alg II 3-6 Solving Systems - Matricesjtentinger
 
Matlab-Data types and operators
Matlab-Data types and operatorsMatlab-Data types and operators
Matlab-Data types and operatorsLuckshay Batra
 
6nullables in c#
6nullables in c#6nullables in c#
6nullables in c#Sireesh K
 
9 Hierarchical Clustering
9 Hierarchical Clustering9 Hierarchical Clustering
9 Hierarchical ClusteringVishal Dutt
 

What's hot (19)

Lines and planes in space
Lines and planes in spaceLines and planes in space
Lines and planes in space
 
Matlab lec1
Matlab lec1Matlab lec1
Matlab lec1
 
Linear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorialLinear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorial
 
Writing Fast MATLAB Code
Writing Fast MATLAB CodeWriting Fast MATLAB Code
Writing Fast MATLAB Code
 
Introduction to programming in MATLAB
Introduction to programming in MATLABIntroduction to programming in MATLAB
Introduction to programming in MATLAB
 
Matlab vectors
Matlab vectorsMatlab vectors
Matlab vectors
 
Threads and Synchronization in c#
Threads and Synchronization in c#Threads and Synchronization in c#
Threads and Synchronization in c#
 
Introduction to programming using mat ab
Introduction to programming using mat abIntroduction to programming using mat ab
Introduction to programming using mat ab
 
Matlab tut2
Matlab tut2Matlab tut2
Matlab tut2
 
Alg II Unit 3-6-solvingsystemsmatrices
Alg II Unit 3-6-solvingsystemsmatricesAlg II Unit 3-6-solvingsystemsmatrices
Alg II Unit 3-6-solvingsystemsmatrices
 
Alg II 3-6 Solving Systems - Matrices
Alg II 3-6 Solving Systems - MatricesAlg II 3-6 Solving Systems - Matrices
Alg II 3-6 Solving Systems - Matrices
 
matlab
matlabmatlab
matlab
 
Matlab-Data types and operators
Matlab-Data types and operatorsMatlab-Data types and operators
Matlab-Data types and operators
 
6nullables in c#
6nullables in c#6nullables in c#
6nullables in c#
 
Matlab tutorial 1
Matlab tutorial 1Matlab tutorial 1
Matlab tutorial 1
 
Lec2
Lec2Lec2
Lec2
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Logical vectors
Logical vectorsLogical vectors
Logical vectors
 
9 Hierarchical Clustering
9 Hierarchical Clustering9 Hierarchical Clustering
9 Hierarchical Clustering
 

Similar to Matlab pt1

Similar to Matlab pt1 (20)

Matlab Tutorial.ppt
Matlab Tutorial.pptMatlab Tutorial.ppt
Matlab Tutorial.ppt
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
 
Lecture 01 variables scripts and operations
Lecture 01   variables scripts and operationsLecture 01   variables scripts and operations
Lecture 01 variables scripts and operations
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Mit6 094 iap10_lec01
Mit6 094 iap10_lec01Mit6 094 iap10_lec01
Mit6 094 iap10_lec01
 
EE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manualEE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manual
 
MATLAB & Image Processing
MATLAB & Image ProcessingMATLAB & Image Processing
MATLAB & Image Processing
 
Matlab guide
Matlab guideMatlab guide
Matlab guide
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
 
Mat lab workshop
Mat lab workshopMat lab workshop
Mat lab workshop
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
 
INTRODUCTION TO MATLAB for PG students.ppt
INTRODUCTION TO MATLAB for PG students.pptINTRODUCTION TO MATLAB for PG students.ppt
INTRODUCTION TO MATLAB for PG students.ppt
 
MATLAB_CIS601-03.ppt
MATLAB_CIS601-03.pptMATLAB_CIS601-03.ppt
MATLAB_CIS601-03.ppt
 
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyond
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Image processing
Image processingImage processing
Image processing
 
MATLAB INTRODUCTION
MATLAB INTRODUCTIONMATLAB INTRODUCTION
MATLAB INTRODUCTION
 
Matlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - IMatlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - I
 
Basic matlab for beginners
Basic matlab for beginnersBasic matlab for beginners
Basic matlab for beginners
 
MATLAB workshop lecture 1MATLAB work.ppt
MATLAB workshop lecture 1MATLAB work.pptMATLAB workshop lecture 1MATLAB work.ppt
MATLAB workshop lecture 1MATLAB work.ppt
 

Recently uploaded

Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAroojKhan71
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfadriantubila
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...amitlee9823
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% SecurePooja Nehwal
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramMoniSankarHazra
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfMarinCaroMartnezBerg
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 

Recently uploaded (20)

Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
 
Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 

Matlab pt1

  • 1. Matlab Notes Part 1 Austin Baird UNC Department of Mathematics UNC Department of Biology January 15, 2014
  • 2. Introduction • Matlab is a lot like a calculator! • we can compute things like 3 · 2 • Arithmetic is preformed in order of operations (just like a calculator) • Matrices and matrix operations are where Matlab excels • Today we will: • Understand the basic Desktop environment • Preform basic arithmetic • use built in functions • Create matices and write our first code
  • 4. Desktop Basics • Current Folder: This is where the files you are working with will be stored. Note: you can navigate from the folder you’re in to any folder you desire by clicking the magnifying glass. • Command Window: This is where you can calculate, receive error messages, or print output from your programs. Commands are input at the symbol. • try to calculate things right now! • Workspace: This is where variables are stored and will tell you things about them (what they equal, how big a matrix is ect.) • Command History: This is where the commands you’ve issued most recently will appear. ↑ on your keyboard will scroll through these commands. • Refer to the text (Matlab intro) for more detailed instruction.
  • 5. Troubleshooting • Often times things won’t work. • One Common problem is that a variable you thought was free is actually associated with a value. • Try the command clear. This will clear all the variables in the Workspace. Try and do some computing and assign variables to values.
  • 6. Arrays • Matlab = Matrix Laboratory, so do things with matrices! • Create your first matrix! • a = [1234], Row Vector! • Indexing in matlab begins with 1 (NOT 0) • Add more rows: a = [1234; 2345; 3456] • Note This also works: a = [1, 2, 3, 4; 2, 3, 4, 5; 3, 4, 5, 6] • We can call values from this array: • a(1, 2) • 2 • Or assign a value to a particular position: • a(1, 2) = 10 • The notation is (row, column)
  • 7. Array Creating Functions • There are ways to automatically create an array(matrix) in matlab: • a = zeros(3, 2) • Creates an array of all zeros (this is good for data management if you want a set size for your matrix • a = linspace(0, 1, 100) • This creates a vector which has 100 points filled in between 0 and 1. • a = 0 : 0.1 : 1 • this creates an array which has mesh width equal to 0.1 • How do we model functions in Matlab?
  • 8. Array Operations • Colon operator: • a = [123; 234; 456] • The colon denotes start:end. Note: if you just place a colon it will select everything. • Select the first two rows of our matrix: • a(1 : 2, :) • What does a(1, :) do? • We can also add to each element of the array: • a − a • a − 10 • We can do traditional and element wise multiplication of matrices: • traditional: a ∗ a, element wise: a. ∗ a • In a similar way you can do other things element wise to a matrix ex.: a. ∧ 3
  • 9. Discrete Functions • In math things are continuous, in Matlab (and in computational science in general) This is not the case. • To compute and evaluate functions we need a Domain and their corresponding function values Range • To get a Domain in Matlab we must “discretize” our continuous domain. • We do this by creating a “mesh width” = size of our spacing in our discretization • ex: x = linspace(0, 1, 10) what is our mesh width dx (x(2)-x(1))? is it always equal? Must consider this! • ex: x = 0 : 0.1 : 1 what is our mesh width dx?
  • 10. Evaluating Functions • Now that we have a discretized version of the x-axis we can now evaluate a function! • Matlab has many built in functions (sin, cos, tan, exp...) • y = sin(x) • We now have a set of range values, how do we know that this is right? Graph? • plot this function: plot(y) • In general the resolution of our function is dependent upon our mesh width • How small is enough, how big is too big? Does any mesh width work? • A quick and dirty estimate of the error between two arrays: max(a − b) will select the max error between the arrays (infinity norm). • Plot sin over one period and experiment with different mesh widths and their effects
  • 11. Our First Program • Matlab files are denoted by a .m at the end of the name. • Documentation is very very important! % is how you comment lines (these will not be read by the computer) • Notice that to run the code Matlab asks you whether to add folder to path or to change to directory, both work. • Just type the name of the code in the command line to get the program to run.
  • 14. Homework • Read sections 1-17 to 1-23 • Email me by Tuesday at 12:01am a onyen.m file which when run does the following ( and is commented at the top of the file with your full name and who you worked with, if anyone): • Generates a figure which plots y = sin(x) + c for ten values of c (all on the same figure). • Generates the figure in section 1-23.