100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Summary Matlab () $0.00

Summary

Summary Matlab ()

 29 views  6 purchases
  • Course
  • Institution

This document is an extensive summary of the introduction to Matlab. Everything is explained step by step, with examples.

Preview 4 out of 37  pages

  • February 23, 2021
  • 37
  • 2019/2020
  • Summary
avatar-seller
INTRODUCTION IN MATLAB
AND PROGRAMMING


Summary of Matlab


PRE-MASTER CEM/CME
ENGINEERING TECHNOLOGY




DOCUMENT NUMBER
01 – WILCO JONKER




2019-2020

,INTRODUCTION IN MATLAB AND PROGRAMMING
Pre-masters CEM / CME


1. Matlab Basics and Introduction:

Een paar commando’s om de ‘actuele stand van zaken’ op te vragen of te
beïnvloeden:

- format loose geeft meer ruimte tussen lijnen van uitkomst
- format compact geeft minder ruimte tussen lijnen van uitkomst
- format short geeft korte uitkomst
- format long geeft lange uitkomst

Format ‘short’ and ‘long’ can possibly complemented with G or E

- who opvragen van alle variabelen met een waarde
- size(x) geeft de afmetingen (aantal rijen, kolommen) van x
- clear x1 verwijder de variabele x1
- clear all verwijder de waarden van alle variabelen
- clc veegt het scherm schoon (idem: Clear Command Window)

clear verwijdert alles uit ‘Workspace’ en clc verwijdert alles uit ‘Command
Window’.

A(i,j) het element in de 'i' rij, 'j' kolom
A(:,j) 'j' kolom van A
A(i,:) 'i' rij van A


- Cancel the current execution of a command with “CTRL + C”
- Use the keys ↑ and ↓ to scroll through previous commands
- Use “CTRL + R” to command out a long block
- NaN = Not a Number


-------------------------------Array Commands------------------------------

find Finds indices of nonzero elements.
length Computers number of elements.
linspace Creates regularly spaced vector.
max Returns largest element.
min Returns smallest element.
prod Product of each column.
size Computes array size.
sort Sorts each column.
sum Sums each column.
Mod An integer m is a multiple applies to a certain integer n.

abs geeft de absolute waarde.
round geeft het dichtstbij gelegen geheel getal.
rank bepaalt de rang van een matrix.
size bepaalt het aantal rijen en kolommen van een matrix.
norm berekent de norm van een matrix of van een vector.
rand(m,n) geeft een (m x n)-matrix met randomgetallen, uniform verdeeld
tussen 0 en 1.
A’ geeft de getransponeerde van de matrix A.
A(:) zet alle kolommen van A onder elkaar in een vector.
ones(m,n) geeft een matrix van dimensie m x n met allemaal eentjes.
zeros(m,n) geeft een matrix van dimensie m x n met allemaal nullen.
fliplr(A) draait de matrix A om in de links/rechts richting.
flipud(A) draait de matrix A om in de onder/boven richting.

---------------------------------------------------------------------------

PAGE 1|36

,INTRODUCTION IN MATLAB AND PROGRAMMING
Pre-masters CEM / CME


2. Matlab Vectors:

We call a sequence of numbers a (row) vector.
The number of rows and columns determines the dimensions (‘size’) of the
matrix: a m-by-n matrix consists of m rows and n columns.


number vector matrix
5 [3 8 5] 3 8 4
[2 5 8 ]
7 5 5
1 2 3

1-by-1 1-by-3 4-by-3

- Difference between successive elements
vector = [initial value : difference : end value]
- Difference is equal to 1
vector = [initial value : end value]
- Linspace, equally distribute elements over the given interval
[initial value , end value] including endpoints (default: 100 elements)
Example: x = linspace(0,1,7) 7 elements between 0 to 1 equally distributed

- zeros(m,n) where all elements are 0
- ones(m,n) where all elements are 1
- rand(m,n) elements randomly chosen between 0 and 1
- randi(max_value,m,n) elements are integers from interval [1,max_value]

Examples:
zeros(1,8) één rij en 8 kolommen
zeros(2,8) twee rijen en 8 kolommen
randi(6,1,5) maximum waarde 6, 1 rij, 5 kolommen


COLUMN VECTOR AND ROW VECTOR
x= [1,2,3,4,5] or x= [1 2 3 4 5] row vector
x= [1;2;3;4;5] column vector
x= [1,2;3,4;5,6;7,8] command for row and column vector

Use always commas to put components of a vector function in a row vector,
because the use of spaces only is very ‘fault-sensitive’.

Difference rand en randi
rand: geeft getallen tussen 0 en 1
randi: geeft integers (gehele getallen)


--------------------------------- rand ------------------------------------

v= rand(20,1) geeft 20 getallen (tussen 0 en 1) en 1 column

v= rand(10,2) geeft 10 getallen (tussen 0 en 1) en 2 columns


--------------------------------- randi -----------------------------------

v= randi(10,1) geeft 1 getal tussen 0 en 10

v= randi(30,2) geeft 4 getallen (matrix) tussen 0 en 30



PAGE 2|36

, INTRODUCTION IN MATLAB AND PROGRAMMING
Pre-masters CEM / CME

v= randi(30,1,10) geeft 1 row, 10 columns met getalen tussen 0 en 30
dus 10 getallen tussen 0 en 30

v= randi(30,12,1) geeft 12 rows, 1 column met getalen tussen 0 en 30

v= randi(20,2,10) geeft 2 rows, 10 columns met getalen tussen 0 en 20

v= randi([-10,10],1,20) geeft 1 row, 10 columns met getallen tussen -10 en
10 gebruik blokhaken [ ] en ,


------------------------- max/min and location/index ----------------------
v= [7 8 3 1 5 7 6]

- Find the maximum value of vector v
maximum= max(v)

- Find the minimum value of vector v
minimum= min(v)

- Calculate the average of vector v
average= mean(v)

- Determine the greatest value of vector v and the corresponding index
[maximum,location]= max(v)

- Determine ONLY the location of the greatest value
location= find(v == max(v))

- How many elements of v are smaller than 5 and give their index.
a= find(v<5);
smaller= length(a)

- How many elements of v are smaller than 5.
smaller= sum(v<5)


------------------------- Vector odd and even -----------------------------
v= [1:25]

INDEX
- Delete all elements with an even index
v_delete_even = v(1:2:end)

- Delete all elements with an odd index
v_delete_odd = v(2:2:end)

ELEMENTS
- Delete all even elements (show all odd elements)
v_delete_even_elements = v(mod(v,2)~=0)

- Delete all odd elements (show all even elements)
v_delete_odd_elements = v(mod(v,2)==0)


------------------------- Manipulate or expand vector ---------------------

v= [-3.5 3.5 4.0 5.0 -3.5 0 -15.0]

- Replace the first three elements for [-2,7,-4]
v(1:3) = [-2 7 -4]


PAGE 3|36

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller WilcoJonker. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $0.00. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

64438 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
Free  6x  sold
  • (0)