Functions
Table of Contents
What is a Function? .
Symbolic Expressions .
Plugging into Symbolic Functions .
Derivatives of Symbolic Functions .
Derivatives and Plugging .
Function Handles .
Function M-Files .
1
1
1
2
2
3
4
What is a Function?
There are tw
What is a Function M-File?
Table of Contents
A Simple Function M-File . 1
The General Idea . 2
A (More) Complicated Function M-File . 3
Suppose you wished to write your own function which you could access every time you loaded up Matlab. Suppose it
couldn
Publishing
Table of Contents
What is publishing? .
Example .
Basic Structure .
Blank Lines .
1
1
3
3
What is publishing?
MATLAB's publish feature is a powerful tool that allows you to create nicely formatted documents
from your m-files. We used publish to
Basic Programming
Table of Contents
Introduction .
Displaying Stuff - disp .
Condition - if .
Loop - for .
More Examples of Loop - for .
Loop - while .
The General Idea when Comparing Successive Values .
Closing .
Obtaining and Running Matlab
Table of Contents
Three Ways . 1
Version . 1
First you'll have to get Matlab.
Three Ways
There are three primary ways in which you can obtain Matlab, they are as follows:
1. Free, as a student, through the university. To do th
Basic Commands
Table of Contents
Help! . 1
Arithmetic and More . 2
Precision and Other Display Stuff . 3
Here are some basic commands to get you started.
Help!
One of the most useful and useless commands in Matlab is the help command. It is sometimes usef
What Can We Do with
a Function M-File?
Table of Contents
Multiple Parameters .
Passing Functions to Functions .
A More Complicated Example .
Documenting Your M-File .
1
1
2
3
Multiple Parameters
Function M-files can take more than a single variable as an
Symbolic Solutions
Table of Contents
The Symbolic Approach .
Solving One Equation Symbolically .
Which Variable to Solve For? .
Solving When Not Equal to Zero .
Solving a System of Equations Symbolically .
Order of The Variables in the Solution .
1
1
2
2
Symbolic Variables
Table of Contents
Declaring .
Factoring Polynomials .
Using pretty .
Expanding .
Simplifying .
Do I Have to Declare Symbolic? .
1
1
2
2
2
3
In the previous section we learned how to create and use Matlab variables for storing numerical
Table of Contents
More With Functions .
Differentiation of Functions .
Integration of Functions .
Numerical Integration .
The matlabFunction command .
Graphing .
Finding Roots .
1
1
2
2
3
4
6
More With Functions
Now that you know two of the three ways to
Solving Equations Numerically
Table of Contents
What are Numerical Methods? .
Solving an Equation Numerically using fzero .
Choosing Well .
Why the Single Quotes? .
Is that it? .
1
1
2
2
2
Next we'll talk a little about what to do when symbolic approaches
Differentiation
Table of Contents
Using diff .
Higher Derivatives .
A Different Variable .
Wait, that Second Parameter? .
Plugging Stuff In - Using subs .
Plotting Derivatives .
1
1
1
2
2
3
Differentiation is the most important thing in calculus so let's
format long;
mypw(3,3)
ans =
0
mypw(4,3)
ans =
1
mypw(1,5)
ans =
-1
mytaylor(@(x) sin(x),0,2,5)
ans =
0.933333333333333
mytaylor(@(x) 1./x,1,5,7)
ans =
-13107
mynewton(@(x) x.^2-7,3,4)
ans =
2.645751311064591
mynewton(@(x) exp(x)-2,4,8)
ans =
1
0.69314718
Math 206 Project 2
First Submission due Thu 26 September 2013 at 11:59pm
Second Submission due Sun 29 September 2013 at 11:59pm
Covers:
This project covers up through Chapter 15 of the tutorial.
What to Submit:
For this project you will need to create and
Math 206 Project 3
First Submission due Thu 10 October 2013 at 11:59pm
Second Submission due Sun 13 October 2013 at 11:59pm
What to Submit:
For this project you will need to create and submit a collection of ve function m-les as listed on the next
page.
G
Math 206 Project 1
First Submission due Thursday 12 September 2013 at 11:59pm
Second Submission due Sunday 15 September 2013 at 11:59pm
Covers:
This project covers up through Chapter 7 of the tutorial.
What to Submit:
For this project you will need to cre
Script M-Files
Table of Contents
What is a Script M-File? . 1
A Simple Script M-File . 1
A Note about Script M-Files . 3
What is a Script M-File?
Before we proceed further consider that when you're writing a Matlab project which involves typing a
bunch of
Differential Equations
Table of Contents
Introduction .
Having No Independent Variable. .
Initial Value Problems .
Plotting a solution. .
Compound Example .
An Example with Variables .
1
1
2
2
3
3
Introduction
Matlab is quite powerful when it comes to sol
Integration
Table of Contents
Indefinite Integrals .
Where's the +C? .
Definite Integrals .
Approximating Integrals .
Using quad .
1
1
1
1
2
Integration can be indefinite or definite. Matlab can do both. If the definite integration is too tricky or imposs
Plotting Curves
Table of Contents
Using ezplot .
Changing the Window Size .
Equations .
An Alternate Command .
1
1
3
4
Using ezplot
A picture is worth 1000 words. Let's learn how to get Matlab to show us some graphs. The easiest way is
to use a command ca
Storing Values
Table of Contents
Declaring Variables as Values .
Accessing Stored Values .
Altering Variables Depending on Themselves .
A Warning About Stored Variables .
Using ans .
Clearing the Variable List .
Semicolons at the end! .
1
1
2
3
3
4
4
Like