MATLAB
MATLAB
1. Matlab Variables
= Assignment Operator
Variable Names-
1. Start with a letter 2. Contain only letters, numbers and underscores
3. Are case sensitive
2. Creating Vectors
Vectors- Lists of numbers
x= [2,3,-1,5,18] Row Vector (Uses Commas)
xcol= [2;3;-1;5;18] Column Vector (Uses Semicolons)
Plot function: plot(x,y)
Vector begins with start value. Spacing is constant. Vector ends with the last value in
range.
x=-2:2; (By default spacing of one)
4. Functions
scatter (to visualise data)
imread (import an image)
lu (LU decomposition of the matrix)
Mathematical functions such as sin can take Vectors or Matrices as input
a=min(v) ..minima function for the entries of a vector
[a,I]=min(v) … Gives the location of the minima as well
5. MATLAB as a calculator
Matrix Multiplication
Now, ‘I’ stores the truth values for the condition v<0.005 for each value of v. So ‘I’
is an array of size same as that of v.
Now to change these specific values which are below the threshold, we simply
say v(I)= 8 .. (Some value)
● FOR loop
n = 1:6 basically states how many times the loop will run, after each run, n will
be incremented.
● IF ELSE statement
Important: You should have the end statement after if to mark the end of the statement.
● Creating Multiple Plots
● Annotations
So to solve such equations what we do is convert the Higher-Order ODEs into a System
of First Order ODEs. We start by creating new variables. One for x and subsequently
one for each derivative term excluding the highest derivative. Say we call them x1 and
x2. These are new variables. Then we use the definition of x1 and x2 to reexpress the
original higher-order ODE into an equation in x1 and x2