[PDF] Introduction to MATLAB - Numerical Mathematics (TMA4215)





Previous PDF Next PDF



matlab-basic-functions-reference.pdf

Create diagonal matrix from vector x=diag(A). Get diagonal elements of matrix Anonymous Functions. % defined via function handles fun = @(x) cos(x.^2)./abs ...



Anonymous functions and Intro to Matrices

put all of your code inside a Matlab function file which can sometimes be annoying if you're trying Accessing elements of a matrix is similar to a vector



Anonymous functions and Intro to Matrices

put all of your code inside a Matlab function file which can sometimes be annoying if you're trying Accessing elements of a matrix is similar to a vector



Print Preview

MATLAB workers so that each worker contains only a part of the array. Yet ... function 11-239 troubleshooting programs 6-52. W wait function 11-241.



MATH 3670 - Intro to Scientific Computation - Fall 2017 Lab 6

Note the syntax of an anonymous function. It specifies the name of the argument of most MATLAB functions can be vectors and the usual result is applying the.



Lecture 1 Vectors Functions

http://www.ohiouniversityfaculty.com/youngt/IntNumMeth/lecture1.pdf



Bucknell University Using ODE45 MATLAB Help

generated by an inline or anonymous function. tspan. 2-element vector defining the range of integration ([to tf]) or can be a vector of 



Introduction to Matlab

Note that most of these function will work on one number or if applied to a vector or Matlab help page on anonymous functions for an example). 2.7 Further ...



A MATLAB Tutorial

12 авг. 2016 г. The MATLAB function diff calculates the difference between successive elements of a vector ... anonymous function or a MATLAB function or a user ...



Ordinary Differential Equations

17 сент. 2013 г. A more compact version uses matrix multiplication in an anonymous function ... Matlab function ellipke and also use numerical quadrature with ...



Ordinary Differential Equations

17 sept. 2013 The Matlab function defining the differential equation has t and y as input arguments and should return f(t y) as a column vector.



Anonymous functions and Intro to Matrices

put all of your code inside a Matlab function file which can sometimes be annoying Matrix columns are separated by commas or spaces



matlab-basic-functions-reference.pdf

Definition of a character vector. "This is a string". Definition of a string str1 + str2. Append strings. Defining and Changing Array Variables.



Lecture 1 Vectors Functions

http://www.ohiouniversityfaculty.com/youngt/IntNumMeth/lecture1.pdf



Chapter 7 - User-Defined Functions and Function Files

dimensions of the arguments since the arguments can be scalars



Second 340 Matlab assignment Vector operations with Matlab You

Besides these vector functions Matlab has many functions which work on scalar or anonymous function which can be evaluated using fewer keystrokes and ...



MATLAB Programming

MATLAB Simulink



A MATLAB Tutorial

29 janv. 2015 3 Anonymous Functions Strings





Introduction to MATLAB - Numerical Mathematics (TMA4215)

21 août 2014 A vector in MATLAB is a 1-dimensional numerical array. Arbitrary vectors can be ... The anonymous function can be assigned to a variable and.

IntroductiontoMATLAB

NumericalMathematics(TMA4215)

EirikHoelHøiseth

21August, 2014

www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 2

WhatisMA 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 3

Numbers

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 4

Storageofnumbers

- Bydefault anintegeristreatedandstored asareal number. - Realnumbers are,bydef ault,storedwithdoubleprecision (roughly16digits accuracy). - Acomplex numberisstoredas2 realnumbers(realand imaginarypart). www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 5

Variables

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 6

Arrays

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 7

Definition:Scalars

Definition:Scalar

AscalarinMATLAB isa0-dimensionalarr ayholdingasingle value.

Example:Creatingn umerical scalars

>>x= 3.4; >>y= 5+4i; www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 8

Vectors

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 9

GeneratingEqually 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 10

Matrices

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 11

Generatingcommonmatrices

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 12

Basicmatrixoperations

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 13

Usefulvectoroperations

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 14

Usefulmatrixoperations

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 15

Indexing

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 16

Indexing: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= 3010
www.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 18

Indexing: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 19

Example:Indexing

>>A= [13 5;7 911] A= 135
7911
>>A( 2,2:3)%Subscriptindexing ans= 911
>>A( 3:5)%Linearindexing ans= 395
www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 20

Charactersandstrings

Definition:Char acter

Acharacterisaninter pretednonnegative integer.

Acharacter iswrittenbyenclosing itin"single" quotationmarks, e.g.'a'.

Definition:Str ing

Astringisav ectorofchar acters.

Astring iswritteninthesame way asasinglecharacter, e.g. 'Thisis astring',andcan beindex edjustlik eanor malvector. www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 21

Logicals

Definition:Logical

Alogicalisa datatypewhich canonlyha vethe valuetrueor false. - true(logical1)and false(logical0)e valuateto 1and0 respectivelywhenusedincomputations . - Anyrealnonzeron umberbecomes truewhile0becomes false,whencon verted toorusedasalogical.

Logicaloperators:

- &(and)and|(or)combinelogical values. - '(not)gives thelogicalnegationofthelogical valuethat follows.

Note:Alsowor kelementwisewithmatrices.

www.ntnu.noEirikHoelHøiseth, IntroductiontoMA TLAB 22

Logicalexpression

Logicalsfrequentlyar iseasthe resultofalogicalexpression

Definition:Logicale xpression

Alogicalexpression isane xpressionthatcan onlyevaluatetotr uequotesdbs_dbs14.pdfusesText_20
[PDF] another way to say whatever you want

[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