Computational Photonics, Summer Term 2012, Abbe School of Photonics, FSU Jena, Prof. Thomas Pertsch

Similar documents
Computational Photonics, Summer Term 2014, Abbe School of Photonics, FSU Jena, Prof. Thomas Pertsch

EE 301 Signals & Systems I MATLAB Tutorial with Questions

MATLAB TUTORIAL WORKSHEET

Computational Photonics, Seminar 01 on Introduction into MATLAB, Page 1

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

Computational Finance

Chapter 7: Programming in MATLAB

Math Scientific Computing - Matlab Intro and Exercises: Spring 2003

7 Control Structures, Logical Statements

ARRAY VARIABLES (ROW VECTORS)

Introduction to MATLAB

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

LECTURE 0: Introduction and Background

MATH2070: LAB 3: Roots of Equations

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

MATLAB Lecture 4. Programming in MATLAB

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

Physics 326G Winter Class 2. In this class you will learn how to define and work with arrays or vectors.

How to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands

Introduction to MATLAB

MATLAB NOTES. Matlab designed for numerical computing. Strongly oriented towards use of arrays, one and two dimensional.

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

EL2310 Scientific Programming

Matlab and Octave: Quick Introduction and Examples 1 Basics

Basic MATLAB Tutorial

Introduction to Matlab

Introduction to Matlab

ROSE-HULMAN INSTITUTE OF TECHNOLOGY

Matlab Tutorial and Exercises for COMP61021

Fall 2014 MAT 375 Numerical Methods. Introduction to Programming using MATLAB

APPM 2460: Week Three For, While and If s

Introduction to Engineering gii

MATH 5520 Basics of MATLAB

MATH 3511 Basics of MATLAB

Matlab Introduction. Scalar Variables and Arithmetic Operators

Assignment #2: False Position Method

Precalculus Notes Unit 1 Day 1

Introduction to Matlab

Computer Worksheet 4

Introduction to MATLAB. Arturo Donate

f( x ), or a solution to the equation f( x) 0. You are already familiar with ways of solving

EGR 111 Introduction to MATLAB

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

A QUICK INTRODUCTION TO MATLAB

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

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started

Matlab Examples. (v.01, Fall 2011, prepared by HP Huang)

Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017

EE 350. Continuous-Time Linear Systems. Recitation 1. 1

Introduction to Matlab (CSE)

Introduction to Matlab

A very brief Matlab introduction

Math 56 Homework 1. Matthew Jin. April 3, e n 10+ne. = O(n 1 ) n > n 0, where n 0 = 0 be- 10+ne

Student Exploration: Translating and Scaling Functions

Homework #6 Brief Solutions 2012

Repetition Structures Chapter 9

Numerical Methods Lecture 7 - Optimization

AN INTRODUCTION TO MATLAB

Numerical Methods Lecture 1

Minima, Maxima, Saddle points

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Exercises C-Programming

Programming Basics and Practice GEDB029 Decision Making, Branching and Looping. Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029

SECTION 5: STRUCTURED PROGRAMMING IN MATLAB. ENGR 112 Introduction to Engineering Computing

Today s topics. Announcements/Reminders: Characters and strings Review of topics for Test 1

Fondamenti di Informatica

Introduction to MATLAB 7 for Engineers

Flow Control. Statements We Will Use in Flow Control. Statements We Will Use in Flow Control Relational Operators

Writing MATLAB Programs

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

Desktop Command window

4.0 Programming with MATLAB

Getting to Know Maple

MATLAB for beginners. KiJung Yoon, 1. 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA

(Creating Arrays & Matrices) Applied Linear Algebra in Geoscience Using MATLAB

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin

MATLAB SUMMARY FOR MATH2070/2970

Matlab course at. P. Ciuciu 1,2. 1: CEA/NeuroSpin/LNAO 2: IFR49

MATLAB Tutorial Matrices & Vectors MATRICES AND VECTORS

A brief introduction to SCILAB

Control Structures. March 1, Dr. Mihail. (Dr. Mihail) Control March 1, / 28

Justify all your answers and write down all important steps. Unsupported answers will be disregarded.

Introduction to MATLAB for Engineers, Third Edition

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

Welcome. Please Sign-In

The Mathematics of Big Data

MATLAB Operators, control flow and scripting. Edited by Péter Vass

EL2310 Scientific Programming

Chapter 1 Introduction to MATLAB

Eng Marine Production Management. Introduction to Matlab

Introduction to MATLAB programming: Fundamentals

Introduction to GNU-Octave

One-dimensional Array

University of Alberta

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

Generalized barycentric coordinates

Introduction to MATLAB

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

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

Transcription:

Computational Photonics Seminar 02, 30 April 2012 Programming in MATLAB controlling of a program s flow of execution branching loops loop control several programming tasks 1

Programming task 1 Plot the sinc-function which is defined as sin(x)/x within the interval of [-3pi,+3pi] using 301 points. Try to avoid in an appropriate manner the singularity which occurs at x =0! Necessary functions: colon operator: : division element by element:./ v=0 sine: sin function for ploting a function: plot

Programming task 2 Write down and test a program to compute the sum of all the elements of a matrix. Header of the program: function sm=supersum(a) % Sum over all elememnts of a matrix % Command sm=supersum (A) % A: arbitrary 2D-matrix Commands you will need: sum, (size) Test with: A=magic(9); Compute the sum of all the elements of a magic square.

Controlling the flow of a program branching if branching conditional execution of a commands Evaluation of a logical expression and a subsequent evaluation of a set of commands if the logical expression is true, otherwise there might be an alternative with else, otherwise nothing Notation: if log. expression 1 set of commands 1 elseif log. expression 2 set of commands 2 else set of commands 3 Example: if a>b else max=a; max=b;

Controlling the flow of a program loops I for - loop Iterative repetion of a set of commands for a predefined number of times Notation: for control variable = starting value : terminating value set of commands Example: factorial=1; for i=2:n factorial=factorial*i;

Controlling the flow of a program loops II while - loop Iterative repetion of a set of commands as long as a certain logical expression remains true. Notation: while logical expression set of commands Example: factorial=1; i=2 while i<=n factorial=factorial*i; i=i+1;

Controlling the flow of a program loop control I continue - command Pass control to the next iteration of FOR or WHILE loop. It avoids all commands that do appear subsequently in the present loop. Notation: while logical expression 1 set of commands 1 if logical expression 2 continue set of commands 2

Controlling the flow of a program loop control II break - command Terminates the execution of WHILE or FOR loop. It does not execute any of the commands that would appear subsequently within the loop. Notation: while logical expression 1 set of commands 1 if logical expression 2 break set of commands 2

Programming task 3 Computation of the root of a function within a predefined interval by using the bisection method What is given: What we are looking for: continuous function f(x) boundaries of an interval xa and xb Value of x with f(x)=0 Application of the bisection method: Reducing the interval which includes a root successively by a factor of 2. a1 a2 b3 b2 b1

Programming task 3b Write an extension to the previous bisection program to ensure that the case of multiple roots is properly handled by the program. For this purpose separate the interval into a predefined number of intervals and search individually for the roots.