First steps in developing codes,functions and scripts as well as to know how to import files and use them in a very strong mathematical environment.
Lots os examples shown.

© All Rights Reserved

26 views

First steps in developing codes,functions and scripts as well as to know how to import files and use them in a very strong mathematical environment.
Lots os examples shown.

© All Rights Reserved

- Gold Price Prediction Using Radial Basis Function Neural Network
- Black Scholes vs Binomial Example
- Estimators.Maximum Likelihood and method of moments
- Simulations of Random Variables
- standard 2 3
- lab ex. 1
- Comm2_2012
- Blaise8 UK AllDownload
- 17-LineDrawing
- Mathematics Class 12 Sy (Kerala)
- 8.CS6202 - Programming and Data Structures-I - CSE - PREMALATHA
- Leopold
- Syllabus Class 12
- Putting Advanced Array Formulas to Work - Excel
- Lista1-GA Geometria Analítica UFSC
- awt
- Assignment 2 Matlab Q2
- Chapter 2-A Numeric, Cells and Structure Arrays
- Generics
- p_1

You are on page 1of 5

A=[1 2 3; 2 4 6] a matrix with 2 rows and 3 columns with 1 2 3 on the first row,2 4 6 on the second .

If you write A=[1,2,3,4,5,6] or A=[1 2 3 4 5 6]it will reside in a vector with 6 elements.

A A transpose

For A= [1, 2, 3, 4] size (A) will give 1 4(one row and 4 columns)

If [r, c] = size (A) then r=1 c=4.

TRIL and TRIU functions

Tril (A) gives the lower triangular matrix derived from the initial matrix.

Triu (A) gives the upper triangular matrix ~.

3 2 2

For example if A=1 2 1 tril (A) gives 0 above the main diagonal.

2 4 1

OPERATIONS ON ARRAY

1) Max (A), Min (A) computes as its name says the maximum of the array A and its minimum

respectively.

2) Sort (A) sorts a vector. You can sort the vector in ascending order or descending order.

E.g. A= [1 -1 2 -2] the code sort (A, descend) gives [2 1 -1 -2]

Exercise: Sort a vector until the middle of it in ascending order, and then in descending order the

remaining part.

Response:

e.g. b= [1 -9 7 2 8 5 10 -1 9 3];

The code z=[sort(b(1:(length(b)/2))),sort(b(length(b)/2+1:length(b)),'descend')] gives

Z = -9

8 10

3 -1

3) Adding a number to an array by <b+ value> increases all elements by that value.

Here b is the previous vector. Mean (b) gives the arithmetic mean, std (b) gives the standard deviation

and sum(b) the sum of all elements.

4) [c, I]=max (b) returns the maximum of the array and its corresponding index.

MATRIX OPERATIONS

Saddle points in matrices:

Lets take for example a payoff matrix resulted from actions of two players in a two-player game:

If we look for a saddle point then we seek if min(max(A))=max(min(A))

If not, we dont have any, if we have then the index is found by the following lines:

1. [b, I]=max(A) // This indicates the position of the maximum in every column.

If I= 2 4 3 1 that means on the first column the maximum is attained on the 2nd row, on the 2nd column

the maximum is attained on the 4th row,etc.

2. run again [b, I]=min(max(A)).That will give you the position in which the minimum is attained

from the maximums shown before. If I=1 that means you have the max(min ) value on the 1st

column and the 2nd row, because from 1) I[1]=2.

If the index is the same, that index is the position of the saddle point.

1) Select the nonnull elements of a vector and find the arithmetic mean of them. Compare the

means obtained by eliminating the zeros and by not eliminating them.

R: mean(x(find(x))) and mean(x(find(x)))-mean(x)

2) Find the non-null elements of a matrix A, and the nonnull elements of the diagonal, and the

third column. Count them.

R: find(A),find(diag(A)), find(A(:,3)), and for counting them we use length(find(A))

3) Count how many elements are bigger than a value

Solution: length(find(A>value))

4) Find a way to print out the following triangle

1

1

Solution: S=cell(1,4)

S(1:4)={[1],[1 2],[1 2 3],[1 2 3 4]}

For i=1:4

Disp(S{i}),end.

5. Add to a matrix A a specified number of rows equal to [1 1 1 1]

Solution: After declaring A, we write n=the number desired and

For I = 1:n

A[I + size(A,1),:]=[1 1 1 1]

End.

6. a) Delete a row from the matrix: Response:

A (no,: )=[];

b) Delete more consecutive rows from matrix:

A (no1:no2,: )=[]

c) Delete a selection of rows from a matrix:

E.g. deleting rows 3 and 5 from matrix.

A ([3, 5], : ) = []

d) Delete a selection of columns from a matrix: A(:, [3,5])=[] for example.

7. Print the following output:

1 2

2 3

2 1

Solution: S=cell (3, 1);

S (1:3) = {[1 2];[2 3 4];[2 1]}

For i=1:3

Disp (S {i}), end

8 . Write to a txt file a table containing this information:

29,30,32

33,33,100,91

43,44,91

R: S=cell(3,1);

S(1:3)={[29 30 32];[33 33 100 91];[43 44 91]}

T=table(S);

Writetable(T,text.txt,WriteVariableNames,false)

1. Sum of two numbers:

We create a file scipt called: sum.m

prompt1 = Give the first number ;

x= input(prompt1);

prompt2 = Give the 2nd number :

y= input(prompt2);

s=x+y;

disp(The sum of the two numbers is: ),disp(s);

then from the command line type <sum>

2. Triangle area

function a=triarea(b,h)

a=0.5*(b.*h);

And you appeal from the command line triarea(10,4) or a=triarea(10,4) etc.

3. Function with multiple outputs

create a function that computes the area and perimeter of a rectangle:

function [a,p]= rectangle(l1,l2)

a=l1*l2;

p=2*(l1+l2)

end

from the command line type [area,perimeter]=rectangle(10,9) e.g. or whatever you want.

4. Nested functions

function [m,s] = stat2(x)

n = length(x);

m = avg(x,n);

s = sqrt(sum((x-m).^2/n));

end

function m = avg(x,n)

m = sum(x)/n;

end

values=[11 21 22 21 31]

and [average,stdev]=stat(values)

function prod = product(n)

temp=1;

if(n>1)

temp = n * product(n-1);

end

prod=temp;

end

Q: What happens if I change temp=1 with temp=0?

The value retained by the function product at first is 0,and then changes as the function is

sequentially executed.

- Gold Price Prediction Using Radial Basis Function Neural NetworkUploaded byAbdurrahman Muttaqiin
- Black Scholes vs Binomial ExampleUploaded byTheodor Munteanu
- Estimators.Maximum Likelihood and method of momentsUploaded byTheodor Munteanu
- Simulations of Random VariablesUploaded byTheodor Munteanu
- standard 2 3Uploaded byapi-318707664
- lab ex. 1Uploaded byRooth Adajet
- Comm2_2012Uploaded byDr-Raghad Al-Faham
- Blaise8 UK AllDownloadUploaded bybad_ghoul134111
- 17-LineDrawingUploaded byJack Oliver
- Mathematics Class 12 Sy (Kerala)Uploaded byctbiju
- 8.CS6202 - Programming and Data Structures-I - CSE - PREMALATHAUploaded byKarthi Kannan
- LeopoldUploaded byManuel Montenegro Pérez
- Syllabus Class 12Uploaded bysanjeev kumar
- Putting Advanced Array Formulas to Work - ExcelUploaded bynksuthar5399
- Lista1-GA Geometria Analítica UFSCUploaded byMatematica Gaussiana
- awtUploaded byPuspala Manojkumar
- Assignment 2 Matlab Q2Uploaded byBazin Tsegaye
- Chapter 2-A Numeric, Cells and Structure ArraysUploaded byMuhammad Shehzad Kamal
- GenericsUploaded bygajugg@gmail.com
- p_1Uploaded byDeepansh Sachdeva
- List View Embedded ControlsUploaded byqueperrito9314
- MatricesUploaded byRenee Chelsea B. Cruz
- bini-cime.pdfUploaded byImron Mashuri
- Constant and Variable TypesUploaded byWael M. Fathallah
- 5 - ArraysUploaded byNeeru Redhu
- ArraysUploaded byThajid Ibna Rouf Uday
- pseudo-dynamic techniques.pdfUploaded bySSS
- pratibha-29-06-2019.pdfUploaded bysrikanth yadav
- 1-s2.0-S0022460X03004218-main.pdfUploaded byshashank soni
- Math Course DescriptionUploaded byVictor Hugo Viana

- Cheapest to deliver bondUploaded byTheodor Munteanu
- Implied Risk Premia and Factor AllocationUploaded byTheodor Munteanu
- Risky Bonds and CDS Valuation in PythonUploaded byTheodor Munteanu
- Double Barrier Options PricingUploaded byTheodor Munteanu
- French Language Build-upUploaded byTheodor Munteanu
- Financial Engineering in PythonUploaded byTheodor Munteanu
- Numerical Methods for Solutions of Equations in PythonUploaded byTheodor Munteanu
- Recursive LU Factorization of a Matrix in PythonUploaded byTheodor Munteanu
- Stochastic Calculus for Finance (Exam 5)Uploaded byTheodor Munteanu
- Stochastic Calculus for Finance (Exam 9)Uploaded byTheodor Munteanu
- Numerical Methods to Solve Systems of Equations in PythonUploaded byTheodor Munteanu
- Probability Distributions in PythonUploaded byTheodor Munteanu
- How Much Costs a Nobel Peace PrizeUploaded byTheodor Munteanu
- Financial Accounting and AnalysisUploaded byTheodor Munteanu
- UN BlacklistUploaded byTheodor Munteanu
- Stochastic Calculus for Finance(Exam 7)Uploaded byTheodor Munteanu
- Stochastic Calculus for Finance(Exam 6)Uploaded byTheodor Munteanu
- Stochastic Calculus for Finance(Exam 10)Uploaded byTheodor Munteanu
- Stochastic Calculus for Finance(Exam 4)Uploaded byTheodor Munteanu
- Stochastic Calculus for Finance(Exam 2)Uploaded byTheodor Munteanu
- Stochastic Calculus for Finance (Exam 11)Uploaded byTheodor Munteanu
- Stochastic Calculus for Finance(Exam 1)Uploaded byTheodor Munteanu
- Stochastic Calculus for Finance (Exam 3)Uploaded byTheodor Munteanu
- Stochastic Calculus for Finance (Exam 8)Uploaded byTheodor Munteanu
- Final Assigment - Taib.pdfUploaded byTheodor Munteanu
- Financial Accounting and Analysis(Stage 4)Uploaded byTheodor Munteanu
- Financial accounting (Stage 6)Uploaded byTheodor Munteanu
- Financial Analysis and Accounting(Stage 5)Uploaded byTheodor Munteanu
- Financial Accounting and Analysis (Stage 2)Uploaded byTheodor Munteanu
- Financial Analysis and Accounting (Stage 3)Uploaded byTheodor Munteanu

- Full TextUploaded byNOTIS64
- AB-6387Uploaded byMaitry Shah
- Testing Safety Critical Control Systems v1 7Uploaded byyvj_20006373
- HJ3100 Manual Rev. G - UlUploaded byScott
- Thermodynamics 1 - Properties of Pure SubstancesUploaded byFlorasaurus17
- Understanding JND MOS PSNRUploaded byCarlos Inostroza
- Hazardous Area Classification-BasicsUploaded byharry_chem
- Abb Photovoltaic ProductsUploaded byChristian Merchan
- 8004762g1Uploaded byFabian Francia
- Cassandra Internals Overview by Sam Tunnicliffe (1)Uploaded byRajul Srivastava
- Global Impact of Gas FlaringUploaded bySiva Shankar
- Microprocessor Based System of Automatic Synchronizer ReportUploaded bykarnatisharath
- Australia ScholarshipUploaded bykcloo
- Humidite TheseUploaded byIlie-Alin Colesa
- Cism8 Im Module 3Uploaded bySajjad Pasha Mohammad
- SP Imran Ahmed KhanUploaded bymansoorahmed86
- Enamine reactionUploaded byLiliana Capulín
- Elc2013 MatsubaraUploaded byNatanael Mojica
- Hai 2014 - Aw109-119 Cab Pw206c Pw207c Pt6b-37a Engine UpdateUploaded byHELIFAN139
- Emerson PRV Wireless MonitoringUploaded byKieran Kueh
- 2142.pdfUploaded byjordano_br43
- G0 Security Products Catalogue Jan2015Uploaded byAlexandru Schengen Dorin
- BC619 ALE TechnologyUploaded bykknair22_741899349
- UART DescriptionUploaded byJoly Sinha
- R MOD 18-Configuring CIFSUploaded byNilber Roberto Benites Moriano
- Bus Reservation SystemUploaded byAndrew Meyer
- M8L10Uploaded byjuandavillareal
- Cast_ironUploaded bygaby908
- Chapter 2.pdfUploaded byAbera Mamo
- SDH Interface With STM-1 ShelfUploaded byKazeem K. Adedayo