Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Understanding the Impact of Climate Change on Agriculture, Slides of Linear Algebra

The effects of climate change on agricultural productivity, focusing on extreme weather events, changing precipitation patterns, and the potential for adaptation strategies. It provides insights into the challenges farmers face in adapting to these changes and the role of scientific research in developing sustainable agricultural practices.

Typology: Slides

2021/2022

Uploaded on 09/27/2022

xyzxyz
xyzxyz 🇮🇳

4.8

(24)

309 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MATLAB
Tutorial
You
need
a
small
numb
e
r
of
basic
commands
to
start
using
MATLAB.
This
short
tutorial
describes
those
fundamental
commands.
You
need
to
create
vectors
and
matrices,
to
change
them,
and
to
operate
with
them.
Those
are
all
short
high-level
commands,
because
MATLAB
constantly
works
with
matrices.
I
believe
t
h
a
t
y
ou
will
like
t
h
e
p
o
wer
that
this
software
gives,
to
do
linear
algebra
by
a
series
of
short
instructions:
E
create
E
=
eye(3)
create
u
u
=
E
(:
1)
change
E
E
(3
1)
=
5
multiply
E
v
=
E
u
u
2
1
0
0
3
2
1
3
2
1
0
0
3
2
1
3
4
0
1
0
5
4
0
5
4
0
1
0
5
4
0
5
0
0
1
0
5
0
1
5
The
word
eye
stands
for
the
identity
matrix.
The
submatrix
u
=
E
(:
1)
picks
out
column
1.
The
instruction
E
(3
1)
=
5
resets
the
(3
1)
entry
to
5.
The
command
E
u
multiplies
the
matrices
E
and
u
.
All
these
commands
are
repeated
in
our
list
b
e
l
o
w.
Here
is
an
example
of
inverting
a
matrix
and
solving
a
linear
system:
create
A
create
b
invert
A
solve
Ax
=
b
A
=
ones(3)
+
e
y
e(3)
b
=
A
(:
3)
C
=
inv(
A
)
x
=
A
n
b
or
x
=
C
b
2
3
2 3 2
3 2 3
2 1 1
1
:
75
;
:
25
;
:
25
0
4
1 2 1
5 4
1
5 4
;
:
25
:
75
;
:
25
5 4
0
5
1 1 2
2
;
:
25
;
:
25
:
75
1
The
matrix
of
all
ones
was
added
to
eye(3),
and
b
is
its
third
column.
Then
inv(
A
)
produces
the
inverse
matrix
(normally
in
decimals
for
fractions
use
format
rat
).
The
system
Ax
=
b
is
solved
by
x
=
inv(
A
)
b
,
which
is
the
slow
way.
The
backslash
command
x
=
A
n
b
uses
Gaussian
elimination
if
A
is
square
and
never
computes
the
inverse
matrix.
When
the
right
side
b
equals
the
third
column
of
A
,
the
solution
x
must
be
0
0 1]
0
. (
The
transpose
symbol
0
makes
x
a
c
olumn
vector
.)
Then
A
x
picks
out
the
third
column
of
A
, and
w
e
have
Ax
=
b
.
Here are
a
few
comments. The comment
sym
bol is
%
:
%
The symb
o
ls
a
and
A
are
dierent
:
MATLAB
is
case-sensitive.
%
Type
help
slash
for
a
description
of
how
to
use
the
backslash
symbol.
The
word
help
can
be
followed
by
a
MATLAB
symb
o
l
or
command
name
or
M-le
name.
1
pf3
pf4
pf5

Partial preview of the text

Download Understanding the Impact of Climate Change on Agriculture and more Slides Linear Algebra in PDF only on Docsity!

MATLAB Tutorial

You need a small numb er of basic commands to start using MATLAB This short tutorial describ es those fundamental commands You need to create vectors and matrices to change them and to operate with them Those are all short highlevel commands b ecause MATLAB constantly works with matrices I b elieve that you will like the p ower that this software gives to do linear algebra by a series of short instructions E create E  eye  create u u  E   change E E    multiply E v  E  u u

The word eye stands for the identity matrix The submatrix u  E   picks out column  The instruction E    resets the   entry to  The command E  u multiplies the matrices E and u All these commands are rep eated in our list b elow Here is an example of inverting a matrix and solving a linear system create A create b invert A solve Ax  b A  ones eye b  A  C  inv A x  Anb or

2 3 2 3 2 3 x^2  C^3 ^ b

The matrix of all ones was added to eye and b is its third column Then invA pro duces the inverse matrix normally in decimals for fractions use format rat  The system Ax  b is solved by x  inv A  b which is the slow way The backslash command x  Anb uses Gaussian elimination if A is square and never computes the inverse matrix When the right side b equals the third column of A the solution x must b e  ^0  The transpose symbol  makes x a column vector Then A  x picks out the third column of A and we have Ax  b Here are a few comments The comment symb ol is   The symb ols a and A are dierent  MATLAB is casesensitive  Typ e help slash for a description of how to use the backslash symb ol The word help can b e followed by a MATLAB symb ol or command name or Mle name

Note The command name is upp er case in the description given by help but must b e lower case in actual use And the backslash Anb is dierent when A is not square  To display all  digits typ e format long The normal format short gives  digits after the decimal  A semicolon after a command avoids display of the result A  ones will not display the    identity matrix  Use the uparrow cursor to return to previous commands

How to input a row or column vector

u     has one row with three comp onents a   matrix v      has three rows separated by semicolons a   matrix v    ^0 or v  u^0 transposes u to pro duce the same v w   generates the row vector w      with unit steps u    takes steps of to give u    

How to input a matrix a row at a time

A      has two rows always a semicolon b etween rows A    also pro duces the matrix A but is harder to typ e   B     ^0 is the transpose of A Thus AT^ is A^0 in MATLAB

How to create sp ecial matrices

diagv  pro duces the diagonal matrix with vector v on its diagonal to eplitzv  gives the symmetric constantdiagonal matrix with v as rst row and rst col umn to eplitzw  v  gives the constantdiagonal matrix with w as rst column and v as rst row onesn gives an n  n matrix of ones

Numb ers and matrices asso ciated with A

detA is the determinant if A is a square matrix rankA is the rank numb er of pivots  dimension of row space and of column space sizeA is the pair of numb ers m n traceA is the trace  sum of diagonal entries  sum of eigenvalues nullA is a matrix whose n  r columns are an orthogonal basis for the nullspace of A orthA is a matrix whose r columns are an orthogonal basis for the column space of A

Examples

E  eye  E      creates a    elementary elimination matrix E  A subtracts  times row of A from row  B  A b creates the augmented matrix with b as extra column E  eye  P  E    creates a p ermutation matrix Note that triuA trilA  diagdiagA equals A

Builtin Mles for matrix factorizations all imp ortant

L U P   luA gives three matrices with P A  LU e  eig A is a vector containing the eigenvalues of A S E   eig A gives a diagonal eigenvalue matrix E and eigenvector matrix S with AS  S E  If A is not diagonalizable to o few eigenvectors then S is not invertible Q R   qrA gives an m  m orthogonal matrix Q and m  n triangular R with A  QR

Creating Mles

Mles are text les ending with m which MATLAB uses for functions and scripts A script is a sequence of commands which may b e executed often and can b e placed in an mle so the commands do not have to b e retyp ed MATLABs demos are examples of these scripts An example is the demo called house Most of MATLABs functions are actually mles and can b e viewed by writing type xxx where xxx is the name of the function 

To write your own scripts or functions you have to create a new text le with any name you like provided it ends with m so MATLAB will recognize it Text les can b e created edited and saved with any text editor like emacs EZ or vi A script le is simply a list of MATLAB commands When the le name is typ ed at the MATLAB prompt the contents of the le will b e executed For an mle to b e a function it must start with the word function followed by the output variables in brackets the function name and the input variables

Examples

function CmultA rrankA C  A^0  A Save the ab ove commands into a text le named multm Then this funtion will take a matrix A and return only the matrix pro duct C  The variable r is not returned b ecause it was not included as an output variable The commands are followed by  so that they will not b e printed to the MATLAB window every time they are executed It is useful when dealing with large matrices Here is another example function V D rpropertiesA This function nds the rank eigenvalues and eigenvectors of A m nsizeA if mn V DeigA rrankA else disp Error The matrix must be square  end Here the function takes the matrix A as input and only returns two matrices and the rank as output The is used as a comment The function checks to see if the input ma trix is square and then nds the rank eigenvalues and eigenvectors of a matrix A Typing propertiesA only returns the rst output V the matrix of eigenvectors You must typ e V D rpropertiesA to get all three outputs

axis a b c d will scale the graph to lie in the rectangle a  x  b c  y  d To title the graph or lab el the xaxis or the y axis put the desired lab el in quotes as in these examples title height of satellite xlabel time in seconds y label height in meters The command hold keeps the current graph as you plot a new graph Rep eating hold will clear the screen To print or save the graphics window in a le see help print or use print Pprintername print d lename