Computing for Engineers
Computing for Engineers ENGR 1731
Popular in Course
Mr. Durward Gleason
verified elite notetaker
Popular in General Engineering
verified elite notetaker
This 3 page Class Notes was uploaded by Mr. Durward Gleason on Monday October 12, 2015. The Class Notes belongs to ENGR 1731 at Georgia Southern University taught by Maria Alba-Flores in Fall. Since its upload, it has received 20 views. For similar materials see /class/222069/engr-1731-georgia-southern-university in General Engineering at Georgia Southern University.
Reviews for Computing for Engineers
Report this Material
What is Karma?
Karma is the currency of StudySoup.
Date Created: 10/12/15
E NGR 731 Computing for Engineers Mechanical and Electrical Engineering Technology Lecture 9 Decision making switch case otherwise structure Prof AlbaeFlores 2182009 Decision Making Decisions In most engineering applications we need to make decisions in order to solve the problem Most decisions are based on the value of some parameter When we write the MATLAB program used to find the result the decisions will be used to control the execution the program Decision Implementation In order to implement the decision statement in MATLAB we have three different structures a The SWItch Case structure b If structure c If elseif structure CASE Statement also known as switch or select statement The purpose of a CASE statement is to allow the value of a variable or expression to control the flow of progmm execution I The first line contains the actualword quot switchquot followed by eitherthe name ofa variable or some other expression I This Va riable or expression is referred to as the quotcontrol Va riablequot of the case statement I Afterthis first line thefollowing lines define one or more blocks of code that represent possible bmnchesthat program execution maytake Each block beginswith a line containing the case keyword followed by a Valuethatthe control variable may have lfthe value ofthe control variable matches this value program execution will execute the corresponding block of code If notthe value specified in the next block if presentl is examined and the process repeats 2182009 Genera rurm ume switch case othezwi 59 structure swuch expresson ass value 1 smremenrsI case value 2 srarememz case value 3 Statements 3 omerwrse Statemenksn The foHoww39ng examp e shows how to use the case Statementfm Mat ab F1nput39Enter a oneeuagae number x 39 svnutch x alsrla 39Yuu typed zeru39 case 9 d15play3915 a perfect square39 aae 2 d15play3915 an even number39 case 3 ease 5 case 7 uaapxaywa a prlne number 9352 4 uaapxaywa a perfect Square 9352 a dlsplavl li an even number othervnse dlsplavl Onlv slngleedlg numbers are alluvied Lab 5 Description Write a program in MATLAB that asksthe user to provide the following Calculate the respective function ofthe umberxaccording to the list given below Displaythe result and function performed us for the Cllculator Letter Function 5 mem c c smem T tangenttx R squareroot mverse 11m Q re L naturaHog mm o common og ogmm A Mallab code that can be use to solve the problem in Lab 5 i 2182009 ec x i nczlun ca calculac i aaani e a a toc eoaan i e r oc tangenc i acne e nece neane accmo ena iprlncii The angle F v5 has a as v5 n rxruxtryi Notes about gt strings gt formatting variables gt the fprlnt function Strings A slrmgis a setaftharatters ieuers that form an array or string The stnng is attuaiiy a vector whose components are the numenc tadesfarthe ietters cones are ascm e i gth S rsthe h en o number aftharactersA ouotatron wrthrnthe stnng is rnor s cateo by two ouote Syntax leccece 39Any characters39 Strings cont n wocdl w d ward3 s cancacenacee cnacaecec accaye ace 1 wordz traces ntu a new cnacaccec accay eencence 39Ynu 39are39 39rlghtl39 name 39Tnomae39 39R 39 39Lee39 5 e 39Hellu39 39Yes39 39No39 39Guudbye39 fprintf Write formatted function The tpcancu function wiii piste output onthe screen wrth the specrneo format Requires a conversion characterfor each variabiethatwiii be sent to the screen am2mm Character on Singietharatter m Detimai natatransr Exvnnentiai natatmn iusrng a iowercase e as in aaasemui u Expnnentiai natatmn iusrng an uppercase c as in 3 1415mm a rrxeocporntnotatron as stnng or characters Prinu culux sc nan 9s 96d 1 fpr intf Examples iv ite an maaaec c sc n xed stringfarmat re ietters natnumbers means oecrmai number no format is specmeo ans Minimum of 1 rnteger sf fixcpmnlfarmal The 1 me the 5 me ns 5 orgrts tothe nght afthe oecrmai paint means new ime