BAHASA PEMROGRAMAN MATLAB as an Engineering Tool & Programming Language a lecture note for Civil Engineering students of PETRA Christian University Doddy.

Slides:



Advertisements
Similar presentations
Getting started with Simulink An introductory tutorial ES205 Analysis and Design of Engineering Systems Rose-Hulman Institute of Technology © R. Layton.
Advertisements

Flow Charts, Loop Structures
Scripts and Flow Control. Scripts So far we have been entering commands directly into the command line But there is a better way Script files (and functions)
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY Matlab® refresher Your objective: to dominate! My objective: to help you dominate!
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Introduction to programming in MATLAB MATLAB can be thought of as an super-powerful graphing calculator Remember the TI-83 from calculus? With many more.
Digital Image Processing Lecture3: Introduction to MATLAB.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
MATLAB File Management. MATLAB User File Management Matlab provides a group of commands to manage user files. For more information, type help iofun. pwd.
© Copyright 2000, Julia Hartman 1 Next An Interactive Tutorial for SPSS 10.0 for Windows © by Julia Hartman Using Command Syntax.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
GTSTRUDL 27 This latest version of GTSTRUDL includes numerous new features, feature enhancements, error corrections, and prerelease features. GTSTRUDL.
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
CMPS 1371 Introduction to Computing for Engineers MatLab.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Scientific Computing Introduction to Matlab Programming.
Math 15 Lecture 9 University of California, Merced Scilab A Short Introduction – No. 3 Today – Quiz #4.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
If you use it, cite it.
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
Chapters 2 & 3 MATLAB Skills This tutorial revisits Examples 3.1 to 3.4 to show how MATLAB can be used to solve the same problems 1.Scatter Plots 2.Other.
Beam Formula If I am given a formula and I am ignorant of its meaning, it cannot teach me anything; but if I already know it, what does the formula teach.
EGR 115 Introduction to Computing for Engineers Introduction to MATLAB Friday 29 August 2014 EGR 115 Introduction to Computing for Engineers.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Files: By the end of this class you should be able to: Prepare for EXAM 1. create an ASCII file describe the nature of an ASCII text Use and describe string.
ENG 1181 First-Year Engineering Program College of Engineering Engineering Education Innovation Center First-Year Engineering Program MAT - Introduction.
Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal.
1 Lecture 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
Getting started with Simulink An introductory tutorial.
Using a set-up file to read ASCII data into Stata
An Interactive Tutorial for SPSS 10.0 for Windows©
Introduction to Matlab
ME 142 Engineering Computation I
Release Numbers MATLAB is updated regularly
What Should I Do if My Style Is Not Included?
Appendix B MathScript Basics
Matlab Training Session 4: Control, Flow and Functions
Basic operations in Matlab
Two-Dimensional Plots
What should I do first MSRDS First Beginner Course - STEP1
Ying shen School of software engineering tongji university
Using Northeast Regional Climate Center (NRCC) Data with WinTR-20
Lecture 1: Introduction
MATH 493 Introduction to MATLAB
MATLAB – What Is It ? Name is from matrix laboratory Powerful tool for
Writing functions in MATLAB
MATLAB – What Is It ? Name is from matrix laboratory Powerful tool for
Review Make sure current directory is set properly Create a diary
Digital Image Processing
Getting Started With Simulink
A Step-by-Step Procedure for Preparing BBS Sheets with Manual Entry of Each Bar is shown here Select BarBeQue 2009 Icon From Desktop Start Program BarBeQue.
Matlab.
CSE 307 Basics of Image Processing
Note on Indexing of Array Elements
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Experiment No. (1) - an introduction to MATLAB
Using Script Files and Managing Data
Scripts In Matlab.
Examples.
Your objective: to dominate! My objective: to help you dominate!
ME 123 Computer Applications I Lecture 5: Input and Output 3/17/03
Presentation transcript:

BAHASA PEMROGRAMAN MATLAB as an Engineering Tool & Programming Language a lecture note for Civil Engineering students of PETRA Christian University Doddy Prayogo, Ph.D.

Course Outline (cont’d) Tutorial 4 (2 weeks) Introduction to programming M-File scripts M-File functions Exercises Reading input from a file Writing output to a file

Tutorial 4 – M-file scripts Series of Matlab command can be saved and automatically executed by using M-file scripts. You can start create a script by accessing “File  New  Script” menu, or simply click on “New Script” button. You will open an Editor Window.

Tutorial 4 – M-file scripts Try to type these commands in Editor Window, then save it with a certain name, for example “run”. Matlab will create an m-file “run.m” in the working directory.

Tutorial 4 – M-file scripts Now, back to Command window, and call the script M-file. Type run  enter.

Tutorial 4 – M-file scripts After inputting necessary data, you should see the typical executed script M-file below.

Tutorial 4 – M-file scripts Fprintf is a command to display, originally from C-language. Some of the format can be seen below. ‘\n’ is a special character to enter a new row in C-language.

Tutorial 4 – M-file scripts All variables executed by script M-file will be recorded in the workspace. Sometimes, this is not desirable.

Tutorial 4 – M-file function You can make similar series of commands, and create your own function. Open another Editor window, and type the followings :  then save with the name ‘luas’

Tutorial 4 – M-file function Through command window try the followings :

Tutorial 4 – M-file Difference between Script & Function M-File:

Tutorial 4 – Exercises Write a script m-file: Input : Length of simple supported beam, Location of downward concentrated load from left support, magnitude of the load. Output : reactions on both supports, maximum bending moment, sketch of moment diagram. Write a function m-file : Input : a, b, c coefficients of 2nd degree polynomial (ax2+bx+c=0). Output : both roots of the polynomial.

Tutorial 4 – Read/Write from/to a text file To execute process repeatedly on many data, it is un-effective if you run script m-file that many times. Instead, data can be prepared as an input text file. Then we can write a script to read the data, process them, and write an output to another file. For example, we want to calculate area and 2nd moment of inertia of 10 rectangular sections. First prepare an input text file (use notepad or matlab editor) and save it (data.txt) in the working directory.

Tutorial 4 – Read/Write from/to a text file Type this script  save “iotext.m”

Tutorial 4 – Read/Write from/to a text file Execute “iotext.m” from Command window. Enter ‘data.txt’ as input text file, and Enter ‘output.txt’ as output text file. Then open the output >>open output.txt (+enter)

Tutorial 4 – Read/Write from/to a text file The output.txt file should be like below :

Tutorial 4 – Exercise Make a script file which read and write from and to text-files. Input text file contains 5 sets of data : Length of simple supported beam (4, 5, 6, 7, 8) Location of downward concentrated load from left (2, 1, 2, 4, 7) Magnitude of concentrated load (1, 2, 3, 4, 5) Out text file contains 5 sets corresponding results: Left support reaction Right support reaction Maximum moment