Basic exercises. Array exercises. 1. x = 32:2: x = [ ] a = x + 16 b = x(1:2:end) + 3 c = sqrt(x) or c = x.^(0.5) d = x.^2 or d = x.

Size: px
Start display at page:

Download "Basic exercises. Array exercises. 1. x = 32:2: x = [ ] a = x + 16 b = x(1:2:end) + 3 c = sqrt(x) or c = x.^(0.5) d = x.^2 or d = x."

Transcription

1 Basic exercises 1. x = 32:2:75 2. x = [ ] a = x + 16 b = x(1:2:) + 3 c = sqrt(x) or c = x.^(0.5) d = x.^2 or d = x.*x 3. x = [ ]', y = [ ]' a = y + sum(x) b = x.^y c = x./y z = x.*y w = sum(z) x'*y - w (same thing) 5. The function "rats" just displays the contents of a variable a = 2:2:20 (or whatever max #) b = 10:-2:-4 c1 = 1:5, c2 = 1./c1, rats(c2) d1 = 0:4, d2 = 1:5, d3 = d1./d2, rats(d3) 6. n = 1:100; x = ( (-1).^(n+1) )./ (2*n - 1); y = sum(x) 8. t = 1:0.2:2 a = log(2 + t + t.^2) b = exp(t).*(1 + cos(3*t)) c = cos(t).^2 + sin(t).^2 (all ones!) d = atan(t) e = cot(t) f = sec(t).^2 + cot(t) t = 1790:2000; term = 1 + exp( *(t )); P = /term; plot(t,p) xlabel('year'), ylabel('population') P2020 = /(1 + exp( *( ))) Array exercises 2. A = [ ; ; 3 5 9] x1 = A(1,:) y = A(-1:,:) c = sum(a) d = sum(a,2) or d = sum(a')' N = size(a,1), e = std(a)/sqrt(n) 5. A = [ ; ; ] B = A(:,2:2:) C = A(1:2:,:) c = reshape(a,4,3) or c = A' (they are different but are both 4x3) d = 1./A, rats(d) e = sqrt(a) 6. randn('seed', )

2 F = randn(5,10); N = size(f,1) avg = mean(f) s = std(f) tscore = (avg - 0)./(s/sqrt(N)) None were different at 90% LOC (all < 2.132). Relational/Logical exercises 4. x = [ ] a = x, idxa = x > 0, a(idxa) = 0 b = x, idxb = ~rem(x,3), b(idxb) = 3 c = x, idxc = ~rem(x,2), c(idxc) = 5*c(idxc) 5. x = 1:35; y = zeros(size(x)); idx1 = x < 6; idx2 = (x >= 6) & (x < 20); idx3 = (x >= 20) & (x <= 35); y(idx1) = 2; y(idx2) = x(idx2) - 4; y(idx3) = 36 - x(idx3); disp([x(:) idx1(:) idx2(:) idx3(:) y(:)]) plot(x,y,'o') Loop constructs: The answers here provide one version of the solutions. Alternatives are possible and encouraged, especially where time and efficiency of the code is important. 1. x = [ ] a. total = 0; for j = 1:length(x) total = total + x(j); b. runningtotal = zeros(size(x)); runningtotal(1) = x(1); for j = 2:length(x) runningtotal(j) = runningtotal(j-1) + x(j); c. s = zeros(size(x)); for j = 1:length(x) s(j) = sin(x(j)); 2. A = rand(4,7); [M,N] = size(a); for j = 1:M for k = 1:N if A(j,k) < 0.2 A(j,k) = 0; else A(j,k) = 1; 3. x = [4 1 6], y = [6 2 7]

3 N = length(x); for j = 1:N c(j) = x(j)*y(j); for k = 1:N a(j,k) = x(j)*y(k); b(j,k) = x(j)/y(k); d(j,k) = x(j)/(2 + x(j) + y(k)); e(j,k) = 1/min(x(j),y(k)); c = sum(c); % or use 1.a. loop 4. These code snippets do the job but their repeated use is much more interesting. An example is given for the first exercise. a. total = 0; % initialize current sum (the test variable) count = 0; % initialize the counter (output of the program) while total < 20 % loop until 20 is exceeded count = count + 1; % another loop repeat => another number added x = rand(1,1); total = total + x; % modify the test variable! disp(['it took ',int2str(count),' numbers this time.']) To do this many times, place the above code in a for-loop. Some simple (though perhaps subtle) changes are needed wth respect to retaining the counts for each repeat. Also, the summary has been changed from a single text message to a histogram. Nrep = 1000; % collect 1000 repeats of the above code count = zeros(nrep,1); for j = 1:Nrep total = 0; % reset the test variable each repeat!!! while total < 20 count(j) = count(j) + 1; % use a vector to capture each result total = total + rand(1,1); hist(count,min(count):max(count)) xlabel('number of random numbers from U(0,1) added to make 20') ylabel('count') title(['histogram of results for ',int2str(nrep),' repeats']) b. count = 0; while 1 % infinite loop use count = count + 1; x = rand(1,1); % get a number if (x < 0.85) & (x > 0.8) % check the value break % bail out if in selected range disp(['it took ',int2str(count),' numbers this time.']) c. count = 0; avg = 0; % test variable while abs(avg - 0.5) > 0.01 count = count + 1;

4 % The following line is one way to update the average. % (count-1)*avg is the sum of the first count-1 numbers % and rand just adds another number. Dividing by count % then gives the new average. avg = ((count-1)*avg + rand(1,1))/count; % modify the test var. % There are other ways to do this and you are encouraged % to come up with them disp(['it took ',int2str(count),' numbers this time.']) 5. while 1 % use of an infinite loop TinF = input('temperature in F: '); % get input if isempty(tinf) % how to get out break TinC = 5*(TinF - 32)/9; % conversion disp(' ') disp([' ==> Temperature in C = ',num2str(tinc)]) disp(' ') IF-block exercises 1. n = 7 gives m = 8 n = 9 gives m = -1 n = -10 gives m = z = 1 gives w = 2 z = 9 gives w = 0 z = 60 gives w = sqrt(60) z = 200 gives w = T = 50 gives h = 0 T = 15 gives h = 31 T = 0 gives h = 1 4. x = -1 gives y = -4 x = 5 gives y = 20 x = 30 gives y = 120 x = 100 gives y = 400

5 Arithmetic: >> 7+9 >> 3*2 >> 2(3+4) >> 2+3*4 >> (2+3)*4 >> 2^3 >> 21/7 >> ans*2 >> 3,14 >> 3.14 >> pi >> 2/3 >> format long >> 2/3 >> pi >> round(ans) >> ceil(3.1) >> floor(3.1) >> help >> help ops >> helpwin >> helpdesk Exercises: 1. Compute the sum of the product of 3 and 4 and the difference between 9 and Convert the binary numbers and to the decimal form. Hint: use 2^j.

6 3. Use helpwin or helpdesk to find a matlab command that does the conversion in previous exercise. Hint: search for binary. 4. Express pi rounded to 3 decimals. Hint: round 1000*pi. ================= Variables: >> a=3 >> b=5; (What is the effect of ; here?) >> b >> c=a+2*b; >> c=c+1 >> c=a*d; >> base=3 >> height=5 >> area=base*height/2 >> a_minus_b=a-b >> who >> whos >> help who >> help whos >> clear >> who ================== Vectors/lists: >> v=[ ] >> v(3) >> v(3)=8

7 >> v(5) >> w=[ ] >> v+w >> v-w >> v+1 >> 2*w >> w/4 >> sum(w) >> v*w >> v.*w >> w.^2 >> [v w] >> ans' >> u=1:4 >> u=0:2:10 >> u=0:3:9 >> u=0:3:10 >> u=0:.2:.6 >> u(2:3) >> help linspace >> linspace(0,1,6) Exercises: 1. Define a price list for magazines, movie, cd, and a corresponding list of how many of these items you consume during a year. Then use these lists to compute a list of the total cost for each of the three items and the total cost. 2. Test whether N ~= N^2/2 and 1+2^2+3^2+..+N^2 ~= N^3/3. Hint: first define x=1:n and use sum. What does ~= mean?

8 ====================== Matrices: >> m=[1 2 3; 4 5 6] >> m(2,1) >> m(1,3) >> m(1,3)=7 >> v >> w >> [v;w] >> v' >> ans(3) >> w' >> [v' w'] >> ans' >> [v';w'] >> who >> help save >> save junk >> clear >> who >> load junk >> who

9 False (=0) / True (=1): >> 2<3 >> 2>3 >> -3<2 >> 1+1 = = 2 >> 2 = = 3 >> 2 ~= 3 ================== Conditional statements: >> i=1; >> if i = = 1 disp('i is one'); >> i=2 >> if i = = 1 disp('i is one'); >> if i = = 1 disp('i is one'); else disp('i is not one'); >> help if ====================== Script files: >> edit (type disp('hi') and save file as hello.m) >> hello Replace disp('hi') by code that sorts a list/vector v=[a b], that is, gives v=[a b] if a < b and v=[b a] if b < a, for example if v(1) < v(2) v=v; elseif v(2) < v(1) v=[v(2) v(1)]; v or more elegantly

10 if v(2) < v(1) v=[v(2) v(1)]; v and save as MyFirstSort.m. Test the script file with >> v=[2 1] >> MyFirstSort >> MyFirstSort What happens in the two code versions if v(1)=v(2)? =================== Loops, for and while: Write code that makes the computer count to a given number N, for example. i=0; while i < N i=i+1; disp(i) Save as CountToN.m. Test with >> N=10; >> CountToN Alternative code construction for i=1:n disp(i) Save as CountToN2.m and test with >> CountToN2 Exercises: 1. a) Get the computer to count only the odd numbers up to N. Hint: elegant to use the for loop with i=1:2:n. b) Get the computer to count backwards from N down to 1, first with a "for loop" (hint: elegant to just replace i=1:n by i=n:-1:1), then with a "while loop". 2. Write code that for a given number N tests whether N = N^2/2 by computing N and N^2/2, and display their difference and ratio. What is the ratio for N=1000? Explain why two numbers with a considerable difference can have a ratio very close to one!

11 3. Given natural numbers m and n, have matlab find p and r with 0<=r < n such that m=pn+r. Try the following code p=0; r=m; while r>=n p=p+1; r=m-p*n; disp(['m=' num2str(p) 'n+' num2str(r)]) 4. Check if a turtle starting at 0 ever reaches 1. Consider and test the following code and explain the outcome! pos=0; while pos<1 step=(1-pos)/2; pos=pos+step; disp(pos) 5. How would the following code work? while 1<2 disp('this will go on forever') Try it! If you run into problem you can always press Ctrl-C 6. Try and then seek to understand the following code? while 1 disp('what is 3+4?') answer=input(''); if answer == 7 disp('correct') return else disp('wrong, but you get another chance.') >> help input ============================ Computer arithmetic: >> eps (a very small positive number in the computer. The smallest?) >> eps/2 >> eps/

12 >> help eps >> 1+eps = = 1 >> 1+eps/2 = = 1 >> a=10 >> a=a^2 (repeat, first until matlab changes to number representation of the form d.dddde+ddd, and make sure you can interprete this, then until matlab gets exhausted..) >> Inf=Inf+1 >> Inf*2 >> Inf/2 >> 1/eps >> 1/0 >> -1/0 (seems as if 0 is somewhat positive after all, strange..) >> 0/0 (Not a Number, without any reasonable interpretation..) >> Inf-Inf >> Inf/Inf >> 0*Inf Exercises: 1. Seek the largest number less than Inf, according to matlab. ======================== Composite conditions: >> 0<=1 >> 1<=1 >> 1<2 1>2

13 >> 1<2 & 1>2 >> ~(1<2)

14 Strings: >> s=1+2 >> s='1+2' >> eval(s) >> f='2*x' >> eval(f) >> x=7 >> eval(f) >> f(2) >> f(3) >> ['text1' 'text2'] >> ['text' 7] >> ['text' num2str(7)] >> help num2str >> disp(['f(x)=' num2str(eval(f))]) >> help disp >> whos ============================== Elementary graphics: >> x=0:.2:1 >> y=x.^2 >> plot(x,y) >> plot(x,1-x/2) >> plot(x,sin(10*x)) >> x=0:.01:1; >> plot(x,sin(10*x))

15 >> xlabel('x') >> ylabel('y') >> xlabel('x_1'); ylabel('x_2') >> title('my first plot') >> hold on >> plot(x,x.^2) >> grid on >> clf >> subplot(211); plot(x,sin(10*x)) >> subplot(212); plot(x,x.^2) >> get(gcf) ============================ Search priorities: >> max(2,1) >> max=[1 2 3;4 5 6] >> max(2,1) >> clear max >> max(2,1) >> hello ( I assume that your hello.m file is intact with the text disp('hi') ) >> hello=5; >> hello >> who >> clear hello >> hello

16 >> path >> help path >> dir >> ls >> help ls >> help dir >> help mkdir >> mkdir m-files >> help cd >> cd m-files >> dir >> edit ( type disp('hi from hello in m-files') and save as hello.m ) >> hello >> cd.. >> hello (the idea is that you will now get a 'hi' from your old hello.m file) ======================== Documentation: >> help max >> edit

1) Generate a vector of the even numbers between 5 and 50.

1) Generate a vector of the even numbers between 5 and 50. MATLAB Sheet 1) Generate a vector of the even numbers between 5 and 50. 2) Let x = [3 5 4 2 8 9]. a) Add 20 to each element. b) Subtract 2 from each element. c) Add 3 to just the odd index elements. d)

More information

A Tutorial on Matlab Ch. 3 Programming in Matlab

A Tutorial on Matlab Ch. 3 Programming in Matlab Department of Electrical Engineering University of Arkansas A Tutorial on Matlab Ch. 3 Programming in Matlab Dr. Jingxian Wu wuj@uark.edu OUTLINE 2 Plotting M-file Scripts Functions Control Flows Exercises

More information

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices Introduction to Interactive Calculations Matlab is interactive, no need to declare variables >> 2+3*4/2 >> V = 50 >> V + 2 >> V Ans = 52 >> a=5e-3; b=1; a+b Most elementary functions and constants are

More information

QUICK INTRODUCTION TO MATLAB PART I

QUICK INTRODUCTION TO MATLAB PART I QUICK INTRODUCTION TO MATLAB PART I Department of Mathematics University of Colorado at Colorado Springs General Remarks This worksheet is designed for use with MATLAB version 6.5 or later. Once you have

More information

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial 1 Matlab Tutorial 2 Lecture Learning Objectives Each student should be able to: Describe the Matlab desktop Explain the basic use of Matlab variables Explain the basic use of Matlab scripts Explain the

More information

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix. MATLAB Tutorial 1 1 Department of Mathematics and Statistics, The University of New Mexico, Albuquerque, NM 87131 August 28, 2016 Contents: 1. Scalars, Vectors, Matrices... 1 2. Built-in variables, functions,

More information

Introduction to Matlab

Introduction to Matlab NDSU Introduction to Matlab pg 1 Becoming familiar with MATLAB The console The editor The graphics windows The help menu Saving your data (diary) Solving N equations with N unknowns Least Squares Curve

More information

Introduction to GNU-Octave

Introduction to GNU-Octave Introduction to GNU-Octave Dr. K.R. Chowdhary, Professor & Campus Director, JIETCOE JIET College of Engineering Email: kr.chowdhary@jietjodhpur.ac.in Web-Page: http://www.krchowdhary.com July 11, 2016

More information

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP) Digital Signal Processing Prof. Nizamettin AYDIN naydin@yildiz.edu.tr naydin@ieee.org http://www.yildiz.edu.tr/~naydin Course Details Course Code : 0113620 Course Name: Digital Signal Processing (Sayısal

More information

Introduction to MATLAB for Numerical Analysis and Mathematical Modeling. Selis Önel, PhD

Introduction to MATLAB for Numerical Analysis and Mathematical Modeling. Selis Önel, PhD Introduction to MATLAB for Numerical Analysis and Mathematical Modeling Selis Önel, PhD Advantages over other programs Contains large number of functions that access numerical libraries (LINPACK, EISPACK)

More information

Lecturer: Keyvan Dehmamy

Lecturer: Keyvan Dehmamy MATLAB Tutorial Lecturer: Keyvan Dehmamy 1 Topics Introduction Running MATLAB and MATLAB Environment Getting help Variables Vectors, Matrices, and linear Algebra Mathematical Functions and Applications

More information

C =

C = file:///c:/documents20and20settings/ravindra/desktop/html/exercis... 1 of 5 10/3/2008 3:17 PM Lab Exercise 2 - Matrices Hyd 510L, Fall, 2008, NM Tech Programmed by J.L. Wilson, Sept, 2008 Problem 2.1 Create

More information

Matlab Lecture 1 - Introduction to MATLAB. Five Parts of Matlab. Entering Matrices (2) - Method 1:Direct entry. Entering Matrices (1) - Magic Square

Matlab Lecture 1 - Introduction to MATLAB. Five Parts of Matlab. Entering Matrices (2) - Method 1:Direct entry. Entering Matrices (1) - Magic Square Matlab Lecture 1 - Introduction to MATLAB Five Parts of Matlab MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-touse

More information

MATLAB Workshop Dr. M. T. Mustafa Department of Mathematical Sciences. Introductory remarks

MATLAB Workshop Dr. M. T. Mustafa Department of Mathematical Sciences. Introductory remarks MATLAB Workshop Dr. M. T. Mustafa Department of Mathematical Sciences Introductory remarks MATLAB: a product of mathworks www.mathworks.com MATrix LABoratory What can we do (in or ) with MATLAB o Use like

More information

Programming 1. Script files. help cd Example:

Programming 1. Script files. help cd Example: Programming Until now we worked with Matlab interactively, executing simple statements line by line, often reentering the same sequences of commands. Alternatively, we can store the Matlab input commands

More information

Matlab and Psychophysics Toolbox Seminar Part 1. Introduction to Matlab

Matlab and Psychophysics Toolbox Seminar Part 1. Introduction to Matlab Keith Schneider, 20 July 2006 Matlab and Psychophysics Toolbox Seminar Part 1. Introduction to Matlab Variables Scalars >> 1 1 Row vector >> [1 2 3 4 5 6] 1 2 3 4 5 6 >> [1,2,3,4,5,6] Column vector 1 2

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab By:Mohammad Sadeghi *Dr. Sajid Gul Khawaja Slides has been used partially to prepare this presentation Outline: What is Matlab? Matlab Screen Basic functions Variables, matrix, indexing

More information

A QUICK INTRODUCTION TO MATLAB

A QUICK INTRODUCTION TO MATLAB A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Basic operations and a few illustrations This set is independent from rest of the class notes. Matlab will be covered in recitations and occasionally

More information

MATLAB PROGRAMMING LECTURES. By Sarah Hussein

MATLAB PROGRAMMING LECTURES. By Sarah Hussein MATLAB PROGRAMMING LECTURES By Sarah Hussein Lecture 1: Introduction to MATLAB 1.1Introduction MATLAB is a mathematical and graphical software package with numerical, graphical, and programming capabilities.

More information

MATLAB Second Seminar

MATLAB Second Seminar MATLAB Second Seminar Previous lesson Last lesson We learnt how to: Interact with MATLAB in the MATLAB command window by typing commands at the command prompt. Define and use variables. Plot graphs It

More information

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Intro to matlab getting started Basic operations and a few illustrations This set is indepent from rest of the class notes. Matlab will be covered

More information

Mini-Project System Simulation over AWGN Using BPSK Modulation

Mini-Project System Simulation over AWGN Using BPSK Modulation Mini-Project System Simulation over AWGN Using BPSK Modulation Part I: MATLAB Environment Due Date: June 5, 2006. This exercise will guide you to realize the basic operating environment. Some useful instructions

More information

Practice Reading for Loops

Practice Reading for Loops ME 350 Lab Exercise 3 Fall 07 for loops, fprintf, if constructs Practice Reading for Loops For each of the following code snippets, fill out the table to the right with the values displayed when the code

More information

1. Register an account on: using your Oxford address

1. Register an account on:   using your Oxford  address 1P10a MATLAB 1.1 Introduction MATLAB stands for Matrix Laboratories. It is a tool that provides a graphical interface for numerical and symbolic computation along with a number of data analysis, simulation

More information

What is Matlab? The command line Variables Operators Functions

What is Matlab? The command line Variables Operators Functions What is Matlab? The command line Variables Operators Functions Vectors Matrices Control Structures Programming in Matlab Graphics and Plotting A numerical computing environment Simple and effective programming

More information

! The MATLAB language

! The MATLAB language E2.5 Signals & Systems Introduction to MATLAB! MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to -use environment. Typical

More information

Introduction to MATLAB

Introduction to MATLAB Quick Start Tutorial Introduction to MATLAB Hans-Petter Halvorsen, M.Sc. What is MATLAB? MATLAB is a tool for technical computing, computation and visualization in an integrated environment. MATLAB is

More information

Introduction to MATLAB

Introduction to MATLAB ELG 3125 - Lab 1 Introduction to MATLAB TA: Chao Wang (cwang103@site.uottawa.ca) 2008 Fall ELG 3125 Signal and System Analysis P. 1 Do You Speak MATLAB? MATLAB - The Language of Technical Computing ELG

More information

Lecture 2 Selection and Looping. Program control, if-else, logical expressions, for loop

Lecture 2 Selection and Looping. Program control, if-else, logical expressions, for loop Lecture 2 Selection and Looping Program control, if-else, logical expressions, for loop Overview Review Program control if-else statement Relational and logical operators Logical expressions for loop statement

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB The language of technical computing AM 581 Computational Laboratory Department of Applied Mechanics, IIT Madras MATLAB: technical computing language & interactive environment for

More information

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms:

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms: Appendix A Basic MATLAB Tutorial Extracted from: http://www1.gantep.edu.tr/ bingul/ep375 http://www.mathworks.com/products/matlab A.1 Introduction This is a basic tutorial for the MATLAB program which

More information

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures Introduction to Octave/Matlab Deployment of Telecommunication Infrastructures 1 What is Octave? Software for numerical computations and graphics Particularly designed for matrix computations Solving equations,

More information

MATLAB INTRODUCTION. Risk analysis lab Ceffer Attila. PhD student BUTE Department Of Networked Systems and Services

MATLAB INTRODUCTION. Risk analysis lab Ceffer Attila. PhD student BUTE Department Of Networked Systems and Services MATLAB INTRODUCTION Risk analysis lab 2018 2018. szeptember 10., Budapest Ceffer Attila PhD student BUTE Department Of Networked Systems and Services ceffer@hit.bme.hu Előadó képe MATLAB Introduction 2

More information

Math 375 Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau)

Math 375 Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau) Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau) January 24, 2010 Starting Under windows Click on the Start menu button

More information

Getting started with MATLAB

Getting started with MATLAB Getting started with MATLAB You can work through this tutorial in the computer classes over the first 2 weeks, or in your own time. The Farber and Goldfarb computer classrooms have working Matlab, but

More information

21-Loops Part 2 text: Chapter ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie

21-Loops Part 2 text: Chapter ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie 21-Loops Part 2 text: Chapter 6.4-6.6 ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie While Loop Infinite Loops Break and Continue Overview Dr. Henry Louie 2 WHILE Loop Used to

More information

MATLAB Introductory Course Computer Exercise Session

MATLAB Introductory Course Computer Exercise Session MATLAB Introductory Course Computer Exercise Session This course is a basic introduction for students that did not use MATLAB before. The solutions will not be collected. Work through the course within

More information

Objectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014

Objectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014 PS 12a Laboratory 1 Spring 2014 Objectives This session is a tutorial designed to a very quick overview of some of the numerical skills that you ll need to get started. Throughout the tutorial, the instructors

More information

Objectives. 1 Basic Calculations. 2 Matrix Algebra. Physical Sciences 12a Lab 0 Spring 2016

Objectives. 1 Basic Calculations. 2 Matrix Algebra. Physical Sciences 12a Lab 0 Spring 2016 Physical Sciences 12a Lab 0 Spring 2016 Objectives This lab is a tutorial designed to a very quick overview of some of the numerical skills that you ll need to get started in this class. It is meant to

More information

Introduction to Matlab. High-Level Computer Vision Summer Semester 2015

Introduction to Matlab. High-Level Computer Vision Summer Semester 2015 Introduction to Matlab High-Level Computer Vision Summer Semester 2015 Informations TAs: Siyu Tang, email: tang@mpi-inf.mpg.de Wei-Chen Chiu, email: walon@mpi-inf.mpg.de Subscribe to the mailing list:

More information

A Quick Tutorial on MATLAB. Zeeshan Ali

A Quick Tutorial on MATLAB. Zeeshan Ali A Quick Tutorial on MATLAB Zeeshan Ali MATLAB MATLAB is a software package for doing numerical computation. It was originally designed for solving linear algebra type problems using matrices. It's name

More information

Introduction to MATLAB

Introduction to MATLAB 58:110 Computer-Aided Engineering Spring 2005 Introduction to MATLAB Department of Mechanical and industrial engineering January 2005 Topics Introduction Running MATLAB and MATLAB Environment Getting help

More information

Finding, Starting and Using Matlab

Finding, Starting and Using Matlab Variables and Arrays Finding, Starting and Using Matlab CSC March 6 &, 9 Array: A collection of data values organized into rows and columns, and known by a single name. arr(,) Row Row Row Row 4 Col Col

More information

Introduction to Computer Programming with MATLAB Matlab Fundamentals. Selis Önel, PhD

Introduction to Computer Programming with MATLAB Matlab Fundamentals. Selis Önel, PhD Introduction to Computer Programming with MATLAB Matlab Fundamentals Selis Önel, PhD Today you will learn to create and execute simple programs in MATLAB the difference between constants, variables and

More information

Numerical Methods for Civil Engineers

Numerical Methods for Civil Engineers Numerical Methods for Civil Engineers Lecture 3 - MATLAB 3 Programming with MATLAB : - Script m-filesm - Function m-filesm - Input and Output - Flow Control Mongkol JIRAVACHARADET S U R A N A R E E UNIVERSITY

More information

Introduction to PartSim and Matlab

Introduction to PartSim and Matlab NDSU Introduction to PartSim and Matlab pg 1 PartSim: www.partsim.com Introduction to PartSim and Matlab PartSim is a free on-line circuit simulator that we use in Circuits and Electronics. It works fairly

More information

SIMPLE MATLAB EXERCISES-key

SIMPLE MATLAB EXERCISES-key SIMPLE MATLAB EXERCISES-key ARITHMETICS OPERATIONS AND USER-DEFINED FUNCTIONS Express the following mathematical operations in MATLAB language For x = 3, y = 1.5, z = -7, calculate G, H and J: 1.- G 3

More information

Chapter 2. MATLAB Basis

Chapter 2. MATLAB Basis Chapter MATLAB Basis Learning Objectives:. Write simple program modules to implement single numerical methods and algorithms. Use variables, operators, and control structures to implement simple sequential

More information

Course Layout. Go to https://www.license.boun.edu.tr, follow instr. Accessible within campus (only for the first download)

Course Layout. Go to https://www.license.boun.edu.tr, follow instr. Accessible within campus (only for the first download) Course Layout Lectures 1: Variables, Scripts and Operations 2: Visualization and Programming 3: Solving Equations, Fitting 4: Images, Animations, Advanced Methods 5: Optional: Symbolic Math, Simulink Course

More information

Lecture 1: Hello, MATLAB!

Lecture 1: Hello, MATLAB! Lecture 1: Hello, MATLAB! Math 98, Spring 2018 Math 98, Spring 2018 Lecture 1: Hello, MATLAB! 1 / 21 Syllabus Instructor: Eric Hallman Class Website: https://math.berkeley.edu/~ehallman/98-fa18/ Login:!cmfmath98

More information

MATLAB Vocabulary. Gerald Recktenwald. Version 0.965, 25 February 2017

MATLAB Vocabulary. Gerald Recktenwald. Version 0.965, 25 February 2017 MATLAB Vocabulary Gerald Recktenwald Version 0.965, 25 February 2017 MATLAB is a software application for scientific computing developed by the Mathworks. MATLAB runs on Windows, Macintosh and Unix operating

More information

LabVIEW MathScript Quick Reference

LabVIEW MathScript Quick Reference Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics LabVIEW MathScript Quick Reference Hans-Petter Halvorsen, 2012.06.14 Faculty of Technology, Postboks

More information

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name: 1 Matlab Tutorial 1- What is Matlab? Matlab is a powerful tool for almost any kind of mathematical application. It enables one to develop programs with a high degree of functionality. The user can write

More information

Dr. Iyad Jafar. Adapted from the publisher slides

Dr. Iyad Jafar. Adapted from the publisher slides Computer Applications Lab Lab 5 Programming in Matlab Chapter 4 Sections 1,2,3,4 Dr. Iyad Jafar Adapted from the publisher slides Outline Program design and development Relational operators and logical

More information

Introduction to MATLAB Step by Step Exercise

Introduction to MATLAB Step by Step Exercise Large list of exercise: start doing now! 1 35: Basic (variables, GUI, command window, basic plot, for, if, functions) 36 40: Medium (functions) 41 45: Medium (matrices) 46 51: Medium (plot) 52 55: Medium

More information

LECTURE 1. What Is Matlab? Matlab Windows. Help

LECTURE 1. What Is Matlab? Matlab Windows. Help LECTURE 1 What Is Matlab? Matlab ("MATrix LABoratory") is a software package (and accompanying programming language) that simplifies many operations in numerical methods, matrix manipulation/linear algebra,

More information

Basic MATLAB Tutorial

Basic MATLAB Tutorial Basic MATLAB Tutorial http://www1gantepedutr/~bingul/ep375 http://wwwmathworkscom/products/matlab This is a basic tutorial for the Matlab program which is a high-performance language for technical computing

More information

AN INTRODUCTION TO MATLAB

AN INTRODUCTION TO MATLAB AN INTRODUCTION TO MATLAB 1 Introduction MATLAB is a powerful mathematical tool used for a number of engineering applications such as communication engineering, digital signal processing, control engineering,

More information

MATLAB BASICS. Macro II. February 25, T.A.: Lucila Berniell. Macro II (PhD - uc3m) MatLab Basics 02/25/ / 15

MATLAB BASICS. Macro II. February 25, T.A.: Lucila Berniell. Macro II (PhD - uc3m) MatLab Basics 02/25/ / 15 MATLAB BASICS Macro II T.A.: Lucila Berniell February 25, 2010 Macro II (PhD - uc3m) MatLab Basics 02/25/2010 1 / 15 MATLAB windows Macro II (PhD - uc3m) MatLab Basics 02/25/2010 2 / 15 Numbers, vectors

More information

2 Amazingly Simple Example Suppose we wanted to represent the following matrix 2 itchy = To enter itchy in Matla

2 Amazingly Simple Example Suppose we wanted to represent the following matrix 2 itchy = To enter itchy in Matla Superlative-Laced Matlab Help for ECE155 Students Brian Kurkoski kurkoski@ucsd.edu October 13, 1999 This document is an introduction to Matlab for ECE155 students. It emphasizes the aspects of Matlab that

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Dr./ Ahmed Nagib Mechanical Engineering department, Alexandria university, Egypt Spring 2017 Chapter 4 Decision making and looping functions (If, for and while functions) 4-1 Flowcharts

More information

Programming in Mathematics. Mili I. Shah

Programming in Mathematics. Mili I. Shah Programming in Mathematics Mili I. Shah Starting Matlab Go to http://www.loyola.edu/moresoftware/ and login with your Loyola name and password... Matlab has eight main windows: Command Window Figure Window

More information

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab MATH 495.3 (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab Below is a screen similar to what you should see when you open Matlab. The command window is the large box to the right containing the

More information

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline MATLAB Tutorial EE351M DSP Created: Thursday Jan 25, 2007 Rayyan Jaber Modified by: Kitaek Bae Outline Part I: Introduction and Overview Part II: Matrix manipulations and common functions Part III: Plots

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB 1 Introduction to MATLAB A Tutorial for the Course Computational Intelligence http://www.igi.tugraz.at/lehre/ci Stefan Häusler Institute for Theoretical Computer Science Inffeldgasse

More information

Scientific Functions Complex Numbers

Scientific Functions Complex Numbers CNBC Matlab Mini-Course Inf and NaN 3/0 returns Inf David S. Touretzky October 2017 Day 2: More Stuff 0/0 returns NaN 3+Inf Inf/Inf 1 -Inf, -NaN 4 Scientific Functions Complex Numbers Trig: Rounding: Modular:

More information

INTRODUCTION TO NUMERICAL ANALYSIS

INTRODUCTION TO NUMERICAL ANALYSIS INTRODUCTION TO NUMERICAL ANALYSIS Cho, Hyoung Kyu Department of Nuclear Engineering Seoul National University 0. MATLAB USAGE 1. Background MATLAB MATrix LABoratory Mathematical computations, modeling

More information

Getting started with MATLAB

Getting started with MATLAB Sapienza University of Rome Department of economics and law Advanced Monetary Theory and Policy EPOS 2013/14 Getting started with MATLAB Giovanni Di Bartolomeo giovanni.dibartolomeo@uniroma1.it Outline

More information

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY What is MATLAB? MATLAB (MATrix LABoratory) developed by The Mathworks, Inc. (http://www.mathworks.com) Key Features: High-level language for numerical

More information

MATLAB tutorial for physicists

MATLAB tutorial for physicists MATLAB tutorial for physicists 0011 0010 1010 1101 0001 0100 1011 Year 2009 Robert Scholten Outline Why MATLAB? MATLAB through example: 1. Signal processing: vectors, 2d plotting 2. Image processing: arrays

More information

A General Introduction to Matlab

A General Introduction to Matlab Master Degree Course in ELECTRONICS ENGINEERING http://www.dii.unimore.it/~lbiagiotti/systemscontroltheory.html A General Introduction to Matlab e-mail: luigi.biagiotti@unimore.it http://www.dii.unimore.it/~lbiagiotti

More information

Introduction to MATLAB

Introduction to MATLAB to MATLAB Spring 2019 to MATLAB Spring 2019 1 / 39 The Basics What is MATLAB? MATLAB Short for Matrix Laboratory matrix data structures are at the heart of programming in MATLAB We will consider arrays

More information

Practice Reading if Constructs

Practice Reading if Constructs ME 350 Lab Exercise 4 Fall 2017 if constructs, while loops Practice Reading if Constructs What is the output of the following command sequences? Some of the sequences may print messages that are not correct

More information

Octave Tutorial Machine Learning WS 12/13 Umer Khan Information Systems and Machine Learning Lab (ISMLL) University of Hildesheim, Germany

Octave Tutorial Machine Learning WS 12/13 Umer Khan Information Systems and Machine Learning Lab (ISMLL) University of Hildesheim, Germany Octave Tutorial Machine Learning WS 12/13 Umer Khan Information Systems and Machine Learning Lab (ISMLL) University of Hildesheim, Germany 1 Basic Commands Try Elementary arithmetic operations: 5+6, 3-2,

More information

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano MATLAB Lesson I Chiara Lelli Politecnico di Milano October 2, 2012 MATLAB MATLAB (MATrix LABoratory) is an interactive software system for: scientific computing statistical analysis vector and matrix computations

More information

Some elements for Matlab programming

Some elements for Matlab programming Some elements for Matlab programming Nathalie Thomas 2018 2019 Matlab, which stands for the abbreviation of MATrix LABoratory, is one of the most popular language for scientic computation. The classical

More information

Introduction to Unix and Matlab

Introduction to Unix and Matlab Introduction to Unix and Matlab 1 Introduction to the Unix System 1.1 Login Pick any machine in Room 451; the screen is probably dark. If so, press the [return] key once or twice. You should see something

More information

Introduction to MATLAB

Introduction to MATLAB UNIVERSITY OF CHICAGO Booth School of Business Bus 35120 Portfolio Management Prof. Lubos Pastor Introduction to MATLAB The purpose of this note is to help you get acquainted with the basics of Matlab.

More information

AMS 27L LAB #2 Winter 2009

AMS 27L LAB #2 Winter 2009 AMS 27L LAB #2 Winter 2009 Plots and Matrix Algebra in MATLAB Objectives: 1. To practice basic display methods 2. To learn how to program loops 3. To learn how to write m-files 1 Vectors Matlab handles

More information

MATLAB TUTORIAL FOR MATH/CHEG 305

MATLAB TUTORIAL FOR MATH/CHEG 305 MATLAB TUTORIAL FOR MATH/CHEG 305 February 1, 2002 Contents 1 Starting Matlab 2 2 Entering Matrices, Basic Operations 2 3 Editing Command Lines 4 4 Getting Help 4 5 Interrupting, Quitting Matlab 5 6 Special

More information

Flow Control. Spring Flow Control Spring / 26

Flow Control. Spring Flow Control Spring / 26 Flow Control Spring 2019 Flow Control Spring 2019 1 / 26 Relational Expressions Conditions in if statements use expressions that are conceptually either true or false. These expressions are called relational

More information

Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr A0B17MTB Matlab Part #1 Miloslav Čapek miloslav.capek@fel.cvut.cz Filip Kozák, Viktor Adler, Pavel Valtr Department of Electromagnetic Field B2-626, Prague You will learn Scalars, vectors, matrices (class

More information

Matrix Manipula;on with MatLab

Matrix Manipula;on with MatLab Laboratory of Image Processing Matrix Manipula;on with MatLab Pier Luigi Mazzeo pierluigi.mazzeo@cnr.it Goals Introduce the Notion of Variables & Data Types. Master Arrays manipulation Learn Arrays Mathematical

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab What is Matlab The software program called Matlab (short for MATrix LABoratory) is arguably the world standard for engineering- mainly because of its ability to do very quick prototyping.

More information

TOPIC 6 Computer application for drawing 2D Graph

TOPIC 6 Computer application for drawing 2D Graph YOGYAKARTA STATE UNIVERSITY MATHEMATICS AND NATURAL SCIENCES FACULTY MATHEMATICS EDUCATION STUDY PROGRAM TOPIC 6 Computer application for drawing 2D Graph Plotting Elementary Functions Suppose we wish

More information

50 Basic Examples for Matlab

50 Basic Examples for Matlab 50 Basic Examples for Matlab v. 2012.3 by HP Huang (typos corrected, 10/2/2012) Supplementary material for MAE384, 502, 578, 598 1 Ex. 1 Write your first Matlab program a = 3; b = 5; c = a+b 8 Part 1.

More information

Introduction to Engineering gii

Introduction to Engineering gii 25.108 Introduction to Engineering gii Dr. Jay Weitzen Lecture Notes I: Introduction to Matlab from Gilat Book MATLAB - Lecture # 1 Starting with MATLAB / Chapter 1 Topics Covered: 1. Introduction. 2.

More information

A Brief Introduction to MATLAB

A Brief Introduction to MATLAB A Brief Introduction to MATLAB MATLAB (Matrix Laboratory) is an interactive software system for numerical computations and graphics. As the name suggests, MATLAB was first designed for matrix computations:

More information

Matlab Tutorial and Exercises for COMP61021

Matlab Tutorial and Exercises for COMP61021 Matlab Tutorial and Exercises for COMP61021 1 Introduction This is a brief Matlab tutorial for students who have not used Matlab in their programming. Matlab programming is essential in COMP61021 as a

More information

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Introduction to Matlab. By: Hossein Hamooni Fall 2014 Introduction to Matlab By: Hossein Hamooni Fall 2014 Why Matlab? Data analytics task Large data processing Multi-platform, Multi Format data importing Graphing Modeling Lots of built-in functions for rapid

More information

Innovation in Financial Analytics

Innovation in Financial Analytics Innovation in Financial Analytics www.finaquant.com % general help >>help % general help >>help % elementary math functions >>help elfun % how while works >>help while % search for keywords >>lookfor optimization

More information

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS 1 6 3 Matlab 3.1 Fundamentals Matlab. The name Matlab stands for matrix laboratory. Main principle. Matlab works with rectangular

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 2 Basic MATLAB Operation Dr Richard Greenaway 2 Basic MATLAB Operation 2.1 Overview 2.1.1 The Command Line In this Workshop you will learn how

More information

EE168 Handout #6 Winter Useful MATLAB Tips

EE168 Handout #6 Winter Useful MATLAB Tips Useful MATLAB Tips (1) File etiquette remember to fclose(f) f=fopen( filename ); a = fread( ); or a=fwrite( ); fclose(f); How big is a? size(a) will give rows/columns or all dimensions if a has more than

More information

Short Version of Matlab Manual

Short Version of Matlab Manual Short Version of Matlab Manual This is an extract from the manual which was used in MA10126 in first year. Its purpose is to refamiliarise you with the matlab programming concepts. 1 Starting MATLAB 1.1.1.

More information

Lecture 2 Introduction to MATLAB. Dr.Tony Cahill

Lecture 2 Introduction to MATLAB. Dr.Tony Cahill Lecture 2 Introduction to MATLAB Dr.Tony Cahill The MATLAB Environment The Desktop Environment Command Window (Interactive commands) Command History Window Edit/Debug Window Workspace Browser Figure Windows

More information

Basic Graphs. Dmitry Adamskiy 16 November 2011

Basic Graphs. Dmitry Adamskiy 16 November 2011 Basic Graphs Dmitry Adamskiy adamskiy@cs.rhul.ac.uk 16 November 211 1 Plot Function plot(x,y): plots vector Y versus vector X X and Y must have the same size: X = [x1, x2 xn] and Y = [y1, y2,, yn] Broken

More information

Brief Matlab tutorial

Brief Matlab tutorial Basic data operations: Brief Matlab tutorial Basic arithmetic operations: >> 2+7 ans = 9 All basic arithmetic operations covered (+, -, *, ^). Vectors and matrices Vectors: x = [1 2 3 4 5] x = 1 2 3 4

More information

Spring 2010 Instructor: Michele Merler.

Spring 2010 Instructor: Michele Merler. Spring 2010 Instructor: Michele Merler http://www1.cs.columbia.edu/~mmerler/comsw3101-2.html MATLAB does not use explicit type initialization like other languages Just assign some value to a variable name,

More information

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment What is MATLAB? MATLAB PROGRAMMING Stands for MATrix LABoratory A software built around vectors and matrices A great tool for numerical computation of mathematical problems, such as Calculus Has powerful

More information