Computing for Engineers
Computing for Engineers ENGR 1731
Popular in Course
Popular in General Engineering
This 3 page Class Notes was uploaded by Mrs. Alaina Hermiston 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 30 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.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 10/12/15
E NGR 1731 Computing for Engineers Mechanical and Electrical Engineering technology Lecture 10 Strings fprintf function if elseif else structure Prof AlbaaFlores 2182009 Documentation in Programs Examples 1 Poor program descriptions of Lab 5 are Jane Doe ENGR 1731C Lab 5 February 12 2009 96 This iab teaches the basics of switcbscasesotberwl39se and how it is used 96 John Doe 96 Engr 1731C 96 Lab 5 021209 as This program will calculate the given runction with the number x Jane Doe ENGR 1731C Lab 5 021209 as This lab will ask user to inputa number to convert itto a dirrerent one as requested by theuser Documentation in programs cont 2A Good program description of Lab 5 is Program name lab5m lane Doe February 52 0 ENGR 1731c Lab 5 SNl39tcbsCasesotberwl39se structure This program perrorms various calculator functions The functions itpertorrns are sine ine tangent square root cos inverse souare natural log and common log log 10 e e e e gee e e e e Request for the number to be processed xl39nput 39Enter the numberx39 Documentation in programs cont 3 An excellent program description of Lab 5 is Program name lab5m created unFebruary 122009 by Jane Doe quoto quoto ENGR 1731C Lab 5 Switchrczserutherwlse Structure as This program perrorrnsvariouscalculatorrunctions The runctions it perrorms are sine co sinetangent square root inverse square natural logandcommonlog log 10 as input variable as x numberto be processed quoto if the function to evziuzte lslelE cosine urtzngent thenthe number as x should be given in radians output Variable as v istherunctionorthe numberx as The allowed runctionsrorthisprogram are as s or s rorsine c or c rorcosin t orT rortangent as r or rorsouar i orl furlx a or o fursquared as l or L rornaturallog o or o rorlog 1000 as Requestfurthe number to be processed xinputtnterthe numberx eroot Strings A string is a set of characters llettersl that form an army lorstringl The string is actually a vectorwhose components are the numeric codes forthe letters codes are ASCIIl The length ofS is the numberofcharacters A quotation within the string is indicated by two quotes Syntax letters 39Any characters39 Strings cont sentence wordl wordZ word3 concatenate character arrays word 1 wordz word3 mto a new character array sentence Examples msg 39You39 39are39 39rlghtl39 name 39Thomas39 39 R 39 39Lee39 5 39Hello39 39Yes39 39No39 39Goodbye39l Outside 1nput39It 13 sunny 7 y or N 39 39539 2182009 fprintf Write formatted function Tne prmcu function WiH piace output anthe screen with the Specified format Requires a conversion characterlar eacn variabielhalwiii be senua the screen mveman hammer so Singie haratter m Denmai mutater isigne i u apanennai notation using a inwertase e as in 1a1seuui u apanennai notation using an upperrase r as m 1 1415mm u Fixe rpmntrmtatmn u Stringnftharatters fpr intf Examples fpzauttfi 39calox as Number 5 stringlarmalieieuersnatnumbers a means demmai numberna format is spem ed 951 5f xrpmntlarmat Tne 1 means minimum all integer the 5 means 5 digits mne ngnmnne decimai paint n means newime fprintf Examples rarmr earar m1 1 a m2 1 1 3 w a an texcz vellaw x e 55 y 355 rammed a s m1 1 a me u 1 3 w err r y Usingthe Matlabfunciton fprintf s Th1 example computes the cublc e an array of numbers to 5 th lucrements of 05 memay rhe reeu1renr array an Not very user r1ena1y amar dlspi ThE eume unermr 1e 1 m a more user r1ena1y armar fprlncii ThE Duh unermr 1a 12 15 n r Vi fprlncii ThE Duh unermr 1a 12 13 n r Vi Decision Making amp Loops 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 progmm Decision Implementation In order to implement the decision statement in MATLAB we have three different structures a If structure b If elseif else structure c The Switch or Case structure 2182009 if Structure The if statement is used to test the value of a variabl If the result of the test is true then the list of commands inside the structure is executed if it is false the list of commands is not executed 0 If structure syntax if condition commands end if Structure Commands Conditions that can be Tested Some of the types of conditions that a variable can be tested for are Value equal Value not equal Value positive Value negative Value largerthan Value less than If else Structure The tfelse statement is used to test the value of a variable Ifthe result of the test is true then one list of commands is executed if it is false the second list of commands is executed if condition commands 1 else commands 2 end ifelse Structure True False Commands 2
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'