21 août 2014 · A vector in MATLAB is a 1-dimensional numerical array Arbitrary The anonymous function can be assigned to a variable and evaluated as a
Previous PDF | Next PDF |
[PDF] Lecture 1 Vectors, Functions, and Plots in Matlab - Ohio University
enter a row vector in Matlab, type the following in the command window: ≫ v = [0 1 2 3] One that we will use a lot is the anonymous function, which is a way
[PDF] Step 0: Write in a Script Vectors in Matlab
31 jan 2019 · Recall that a vector is a list of elements (often numbers or functions) that is We would write down this function in Matlab with an anonymous
[PDF] Anonymous functions and Intro to Matrices
row column” over and over until you remem- ber Using my example matrix A, if I typed A(2,3) into the command line, Matlab would return 6, since it's in the 2nd
[PDF] MATLAB - WSU Math Department
This anonymous function accepts a single input x, and implicitly returns a single output, an array the same size as x that contains the squared values • Find the
[PDF] MATLAB Programming
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, and xPC Matrix Concatenation Functions Constructing an Anonymous Function
[PDF] Introductory MATLAB - METU
Anonymous functions (A 8) MATLAB stands for MATrix LABoratory because its basic data ele of the information that is used for the elements of the vector
[PDF] Introduction to MATLAB - NTNU
21 août 2014 · A vector in MATLAB is a 1-dimensional numerical array Arbitrary The anonymous function can be assigned to a variable and evaluated as a
[PDF] Computational Methods in Physics 1 Introduction to MATLAB
The length(vector) and size(matrix) functions in MATLAB are used to find array For the user-defined functions, you can use inline ('function','independent
[PDF] anova for categorical data
[PDF] anova for categorical data in r
[PDF] anova for categorical variables
[PDF] ansi 1/3 octave bands
[PDF] ansi c
[PDF] ansi c 11 pdf
[PDF] ansi c plotter
[PDF] ansi c standard
[PDF] ansi c vs c99 vs c11
[PDF] ansi c99 standard pdf
[PDF] ansi one third octave bands
[PDF] answer key ccna
[PDF] answer key new headway upper intermediate workbook
[PDF] answer key solutions upper intermediate workbook
IntroductiontoMATLAB
NumericalMathematics(TMA4215)
EirikHoelHøiseth
21August, 2014
www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 2WhatisMA TLAB?
- Highle velprogramminglanguage. - Simpletouse ,but significantlyslowerthan lowerlevel languageslike C++andJava. - Initiallya toolfor matrixcomputations (MATrixLABorator y), thatev olvedintoaplatformforscientificcomputing. - Hugescientificlibr ary. - Expensivelicense. www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 3Numbers
MATLABsupportsall theusualnumbers:
- Integers - Realnumbers - Complexnumbers Canmixintegers ,complex numbers,andreal numbersaswelik e.Example:
>>3.47*4-(5+4i) ans=8.8800-4.0000i
Note:Bothiandjcanbeused forthe imaginaryunit.
www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 4Storageofnumbers
- Bydefault anintegeristreatedandstored asareal number. - Realnumbers are,bydef ault,storedwithdoubleprecision (roughly16digits accuracy). - Acomplex numberisstoredas2 realnumbers(realand imaginarypart). www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 5Variables
Definition:V ariable
Avariableisareferencetoanobject. Theassignmentoper ator,=, isused toassigna valueto avar iable. Note:Variablesneednotbedeclaredbeforethe yareused.Example:Assignment
>>x= 2; >>y= x%xandyrefertodifferentobjects y= 2 www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 6Arrays
Definition:Arr ays
Anarrayisadatastructure .Itconsists ofacollection ofelements. Inanarr ayof dimensionnthepositionof anelement inmemory is givenbyan orderedsetofnindices.Note:InMATLAB allvariablesref ertoarr ays.
www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 7Definition:Scalars
Definition:Scalar
AscalarinMATLAB isa0-dimensionalarr ayholdingasingle value.Example:Creatingn umerical scalars
>>x= 3.4; >>y= 5+4i; www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 8Vectors
Definition:V ector
AvectorinMATLAB isa1-dimensionaln umericalarray.
Arbitraryvectorscanbecreatedusing thesquarebrac ket[]Wedistinguishbetweentw otypes:
- Rowvector:Elementssepar atedby acommaorspace - Columnvector :Elementssepar atedby asemicolon. Note:Acolumnv ectorisoften madebytransposingarow vector.Example:Creatingv ectors
>>x= [3 ,4, -1];%Rowvectoroflength3 >>y= [3+i;2-2i];%Columnvectoroflength2; www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 9GeneratingEqually spacedvectors
Thecolonoperator ,:,isuseful forcreating equallyspacedreal vectors: - a:bforb!acreates[a,a+1,...,a+m],wherem="b#a$. - a:d:bforrealdcreates[a,a+d,...,a+md],where m="(b#a)/d$,assuming(b#a)/d!0. Analternativ eisthebuiltinMATLAB functionlinspace: - linspace(a,b,n)createsaro wvector ofnequallyspaced pointsbetween aandb. www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 10Matrices
Definition:Matrix
AmatrixinMATLAB isa2-dimensionaln umericalarray.
Matricescanbecreatedsimilar lytov ectorsusingsquare brack ets: - Elementsina roware separatedb yacommaorspace - Rowsareseparatedb yasemicolon. Note:Vectorsandnumeric scalarscanbe thoughtofasmatrices.Example:Creating matrices
>>A= [3 21; 47-1];%Matrixhas2rowsand3columns www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 11Generatingcommonmatrices
BuiltinMA TLABfunctionsused togeneratesomefrequentlyused matrices: - zeros(n,m)generatesann%mmatrixofzeros. - ones(n,m)generatesann%mmatrixofones. - eye(n)generatesann%nidentitymatrix. - rand(n,m)generatesann%mrandommatrix. Note:Onlyneedto statethelength ofonedimension ifthematr ix issquare, e.g.zeros(n). www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 12Basicmatrixoperations
Themostcommon operationsare:
- +and#additionandsubtraction. matrixmultiplication. - ˆmatrixpowerforsquarematrices. - /and\matrixrightandleftdivision x.Similarly b/Asolvesthelinearsystem xA=bforx. •Preferabletomultiplyingbytheinv erse,e .g.(Aˆ(-1))*band b*(Aˆ(-1))respectively. - Puttingaperiodbeforetheoperatorgiv esthecorresponding elementwiseoperations:. ,.ˆ,./and.\. www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 13Usefulvectoroperations
Foravectorv
- sum(v)andprod(v)computesthesumandproduct respectivelyoftheelementsin v. - length(v)givesthelengthofv. - max(v)andmin(v)findsthemaximumandminimumofthe elementsinv. - normcomputesnorms ,e.g.norm(v)forthevector2-nor m. - diff(v)computesav ectorofdiff erencesofneighbouring elementsinv. - sort(v)sortstheelementsin vinascendingorder .Note:Mostofthese arealsoapplicab letomatr ices.
www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 14Usefulmatrixoperations
ForamatrixA
- A'andA.'givetheconjugatetranspose andtranspose respectivelyofA. - diagcanbeused togenerate diagonalmatrices andextr act diagonalsfrommatr ices. - size(A)givesthesizeof A. - eig(A)computestheeigenvaluesandeigenvectorsofA - cond(A)computestheconditionnumber ofA Note:Manyothersexist,and thelistedones oftenhaveadditional optionalf eatures. www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 15Indexing
Definition:Inde xing
Indexingintoanarr ayis ameansofselectingasubset ofthe elements. MATLABusesone-basedindexing, whichmeans theindicesstar t at1. Note:Indexingisanimportant programming toolinMA TLAB. www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 16Indexing:Vectors
- Togetthen-thelementinav ectorb,write b(n) - Letabeav ectorcontainingv alidindicesofthevector b.Then b(a)andahavethesamelength,andelementiofthev ector b(a)iselementa(i)ofb.Specialcases: •b(1:n)givesthenfirstelementsofb. •b(m:n)withm&nisthesub vectorfrom b(m)andupto b(n).Example:Indexing vectors
>>x= [1 020 30];%Vectortobeindexed >>x( [3,1])%Newvector ans= 3010www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 17
Indexing:Matrices
Definition:Subscr iptindexing
Withsubscriptindexingformatrices,w egiveanindex(orv ectorof indices)for eachofthetwodimensions ,separated bycomma, insideparentheses. Thefirstindexrefersto therows,andthe secondtothecolumns.Note:Thisisthe commonwa yofinde xingmatrices .
Somespesificcases:
- Theelementin them-thro wandn-thcolumn ofamatr ixAis indexedasA(m,n). - :isshorthand for1:end,andcan beused todenoteall rows orcolumns. E.g.A(1:n,:)extractsthefirstnrowsofA. www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 18Indexing:Matrices
Definition:Linear indexing
Withlinearindexing weindexasif thematrixwasa vector. The matrixbeingindex edistreated asifitselementsarestrungoutin a longcolumnvector . Note:Theresultingsub vectorhas thesameformastheindex vector. www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 19Example:Indexing
>>A= [13 5;7 911] A= 1357911
>>A( 2,2:3)%Subscriptindexing ans= 911
>>A( 3:5)%Linearindexing ans= 395
www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 20