Lecture (6) Programming (3) Eng. Osama Talaat 1. Announcement  Previous lecture videos are available at the course link.  Extra Materials.  Survey.

Slides:



Advertisements
Similar presentations
CMPT 100 : INTRODUCTION TO COMPUTING TUTORIAL #5 : JAVASCRIPT 2 GUESSING GAME By Wendy Sharpe 1.
Advertisements

Lecture 14 User-defined functions Function: concept, syntax, and examples © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
SAM 2007 v3.0 The Student Experience Including SAM Projects and Course Assess assignments.
Introduction to Matlab
Lecture (4) Plotting & Programming (1) Eng. Osama Talaat 1.
Functions in MatLab Create a new folder on your Z:drive called MatLab_Class24 Start MatLab and change your current directory to MatLab_Class24 Topics:
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
Why care about debugging? How many of you have written a program that worked perfectly the first time? No one (including me!) writes a program that works.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
3-2 What are relational operators and logical values? How to use the input and disp functions. Learn to use if, if-else and else-if conditional statements.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 19P. 1Winter Quarter MATLAB: Script and.
Right-click on the colored box and remove it.
Example – calculating interest until the amount doubles using a for loop: will calculate up to 1000 years, if necessary if condition decides when to terminate.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
BACS 287 Programming Logic 3. BACS 287 Iteration Constructs Iteration constructs are used when you want to execute a segment of code several times. In.
The Internet. Telnet Telnet means using your computer as a terminal. All commands you type are sent to the host computer you are connected to and executed.
Guidelines for working with Microsoft Visual Studio.Net.
A Visual Introduction to PC SAS. Start SAS by double-clicking on the SAS icon...
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
Noadswood Science,  To know the basics of Python coding and decoding Monday, September 07, 2015.
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
For Loops 2 ENGR 1181 MATLAB 9. For Loops and Looped Programming in Real Life As first introduced last lecture, looping within programs has long been.
Introduction to MATLAB. Windows in MATLAB Command Window – where you enter data, run MATLAB code, and display results Command History - displays a log.
Matlab Class 7 Hristiyan Kourtev & Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS)
INTRODUCTION TO MATLAB LAB# 01
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
SUNY-New Paltz Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz “Lecture 6”
S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: User Input / Output Programming Environment.
1 Flow of control Sequential Executing instructions one by one, in exact order given Selection Choosing to execute a particular set of statements depending.
CMPS 1371 Introduction to Computing for Engineers MatLab.
Open a editor Write/Type the program Save the program with “.c” extension Compile the program (alt + F9) Run/Execute the program (ctrl + F9) Check the.
Compiling a C Program. Before we can begin we must open a telnet session to phobos. There are a number of ways to do this, but the easiest is to click.
Structured Programming: Debugging and Practice by the end of this class you should be able to: debug a program using echo printing debug a program using.
Scientific Computing Introduction to Matlab Programming.
Discussion 4. Labs public MyPoint(double xInit, double yInit ) { MyPoint p = new MyPoint(0, 0); } ClassProblem.java recursive java.lang.StackOverflowError.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
MA/CS 375 Fall 2002 Lecture 3. Example 2 A is a matrix with 3 rows and 2 columns.
Georgia Institute of Technology More on Creating Classes part 2 Barb Ericson Georgia Institute of Technology Oct 2005.
Make a dice challenge! This is a starter activity and should take 5 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.Copy the code below in.
Chapter 23. Copyright 2003, Paradigm Publishing Inc. CHAPTER 23 BACKNEXTEND 23-2 LINKS TO OBJECTIVES Record, Run, Pause, and Delete Macros Record, Run,
CS1109 L AB 3 July 3rd. R OAD M AP Homework submission Review How to use function and scripts While-end Finish last exercise Lab 2 Challenge questions.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
A simple classification problem Extract attributes Pattern Pattern recognition decision x C1 C2.
MySQL Getting Started BCIS 3680 Enterprise Programming.
Introduction to Matlab
All sections to appear here Welcome to my pptPlex Slide Show, this can be executed in either two ways: 1.As a normal PowerPoint slide show: Example hit.
Lecture (5) Programming (2) Eng. Osama Talaat 1. Announcement  M-Files are available:  Download the file from the course page
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Coding Time This is a starter activity and should take about 10 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.Start a script session (Select.
MA/CS 375 Fall 2002 Lecture 2. Motivation for Suffering All This Math and Stuff Try the Actor demo from
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
THE C PROGRAMMING ENVIRONMENT. Four parts of C environment  Main menu  Editor status line and edit window  Compiler message window  “Hot Keys” quick.
EGR 115 Introduction to Computing for Engineers Loops and Vectorization – Part 1 Monday 13 Oct 2014 EGR 115 Introduction to Computing for Engineers.
SCRIPTS AND FUNCTIONS DAVID COOPER SUMMER Extensions MATLAB has two main extension types.m for functions and scripts and.mat for variable save files.
Lecture (7) Introduction to GUI Eng. Osama Talaat 1.
Introduction To Matlab Class 5 Instructors: Hristiyan (Chris) Kourtev and Xiaotao Su, PhD.
WS1-1 ADM , Workshop 1, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 1 INTRODUCTION.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
1 Introduction to Matlab. 2 What is Matlab? Matlab is basically a high level language which has many specialized toolboxes for making things easier for.
MySQL Getting Started BCIS 3680 Enterprise Programming.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators.
MATLAB – More Script Files
Repetition Structures Chapter 9
Scripts & Functions Scripts and functions are contained in .m-files
MATLAB DENC 2533 ECADD LAB 9.
MATLAB – Basic For Loops
Electrical and Computer Engineering Department SUNY – New Paltz
Presentation transcript:

Lecture (6) Programming (3) Eng. Osama Talaat 1

Announcement  Previous lecture videos are available at the course link.  Extra Materials.  Survey. 2

Password  Enter the password.  If the entered password is ‘a13’, display a welcome message ‘Welcome Osama’.  If the entered password is ‘com’, display a welcome message ‘Welcome Hamdy’.  If the entered password is ‘t10’, display a welcome message ‘Welcome Mona’.  Else, Display an error message ‘Wrong password’.  Give the user only 5 unsuccessful trails. 3

%%%%%%%%%%%%%%%%%%%% % Designed by: Eng. Osama Talaat % %%%%%%%%%%%%%%%%%%%% clear all; close all; clc; for k=1:5 pass = input('Please enter password: ','s'); if strcmp(pass,'a13') disp('Welcome Osama') break elseif strcmp(pass,'com') disp('Welcome Hamdy') break elseif strcmp(pass,'t10') disp('Welcome Mona') break else disp(['Wrong password, trial ' num2str(k) ' of 5']) end end 4 What it wrong ?? Break & Continue Ctrl + C

Animation %%%%%%%%%%%%%%%%%%%% % Designed by: Eng. Osama Talaat % %%%%%%%%%%%%%%%%%%%% clear all; close all; clc; [x,y]=meshgrid(-2:0.1:2); z=x.*exp(-x.^2-y.^2); surf(x,y,z) 5

View  Change the angle of view for a figure.  Get the current angles: >> [a,b]=view a = b = 30 6

Animation %%%%%%%%%%%%%%%%%%%% % Designed by: Eng. Osama Talaat % %%%%%%%%%%%%%%%%%%%% clear all; close all; clc; [x,y]=meshgrid(-2:0.1:2); z=x.*exp(-x.^2-y.^2); surf(x,y,z) for az=-37.5:7.5: view(az,30) end 7

Pause  Pause for n seconds: >> pause(n)  Pause till you press any key >> pause 8

Animation %%%%%%%%%%%%%%%%%%%% % Designed by: Eng. Osama Talaat % %%%%%%%%%%%%%%%%%%%% clear all; close all; clc; [x,y]=meshgrid(-2:0.1:2); z=x.*exp(-x.^2-y.^2); surf(x,y,z) pause(1) for az=-37.5:7.5: pause(0.2) view(az,30) end 9

For inside for %%%%%%%%%%%%%%%%%%%%%%% % Designed by: Eng. Osama Talaat % %%%%%%%%%%%%%%%%%%%%%%% clear all; close all; clc; a=randi(30,40,20); c=0; for i=1:size(a,1) for j=1:size(a,2) if(a(i,j)==3) c=c+1; end disp('The number of accurance of 3s:'); disp(c) 10

Game  The program generate a random integer number from 0:15.  The user guess that number, if he was wrong the program will till him that his guess is lower or greater than the number.  Then the user try again, till he give the right guess.  The program will display a congratulation message and the number of trials he took. 11

%%%%%%%%%%%%%%%%%%%% % Designed by: Eng. Osama Talaat % %%%%%%%%%%%%%%%%%%%% clear all; close all; clc; n=randi(15); trials=0; g=-1; while(g~=n) g=input('Enter your guess between 1-15: '); if g>n disp('Your guess is greater, try again!') trials=trials+1 elseif g<n disp('Your guess is smaller, try again!') trials=trials+1 else disp('Congratulations, your guess is right!') trials=trials+1 end 12

While Loop while conditions ________________________ ______ Commands ________ ________________________ end ________________________ ______ Commands ________ ________________________ 13

While & For for x=1:2:100 ________________________ ______ Commands ________ ________________________ end x=1; while x<=100 ________________________ ______ Commands ________ ________________________ x=x+2; end 14

15-Min Break Survey

Functions  To run any script (plotsin.m for example):  Run.  F5  In command window >> plotsin  Create a function: function plotsin(inputs) ________________________ ______ Commands ________ ________________________  The file and the functions names must be the same.  The file must be saved in the current directory. 16

Functions function plotsin(n,f,A) if n>0 %Check positive number of cycles x=[0:0.1:2*pi*n/f]; y=A*sin(f*x); plot(x,y) xlabel('x') ylabel([num2str(A) 'sin(' num2str(f) 'x)']) title('Sine Curve'); grid disp('The amplitude values are: '); disp(y) else disp('The number of cycles must be positive') end disp('Program Terminated !!') 17

Log of any base 18

Log of any base  Try in the command editor: >> a=logn(27,3) Error using logn Too many output arguments.  Create an output for the function: function y=logn(x,n) y=log(x)/log(n);  Check wrong values: function y=logn(x,n) if n<=0 disp('The base must be positive') end y=log(x)/log(n); 19

Log of any base function y=logn(x,n) if n<=0 disp('The base must be positive') return end y=log(x)/log(n); --- OR --- function y=logn(x,n) if n<=0 error('The base must be positive') end y=log(x)/log(n); 20

Insert into a vector function out=insertv(in,new,n) if size(in,1)~=1|size(new,1)~=1 error('Works only with vectors') end if n<=0 error('The index must be positive') end out=[in(1:n-1) new in(n:end)]; 21

Open Selection  You can open the code of some functions of MATLAB.  You can also change in it and save it for yourself or publish it with some rules.  Type any function in the command window.  Select it.  Right click.  Open Selection.  Its code will appear in the editor where you can view, change and save as... 22

MATLAB Tips !!  Tic... Toc %%%%%%%%%%%%%%%%%%%% % Designed by: Eng. Osama Talaat % %%%%%%%%%%%%%%%%%%%% clear all; close all; clc; disp('Press any key to start the stop watch!') pause tic disp('Press any key to stop!') pause toc 23

Close MATLAB  X button.  Code >> exit >> quit  Ctrl + Q 24

GOOD LUCK To be continued in the next lecture … 25