



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
1 / 7
This page cannot be seen from the preview
Don't miss anything!
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
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
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
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
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
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
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
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
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
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