11_pdfsam_2 - >> average_cost =...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Commas and semicolons can be used to place multiple commands on one line, with commas producing display of results, semicolons supressing Percent sign (%) begins a comment, with all text up to the next line ignored by Matlab Three periods ( ... ) at the end of a command indicates that the command continues on the next line. A continuation cannot be given in the middle of a variable name. Example 2.4 Use of punctuation >> screws = 36 screws = 36 >> items items = 90 >> items = screws + bolts + rivets items = 94 >> screws=32, bolts=18; rivets=40; % multiple commands screws = 32 >> items = screws + bolts + rivets; >> cost = screws*0.12 + bolts*0.18 + rivets*0.08;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: >> average_cost = cost/. .. % command continuation items average_cost = 0.1142 2.3 Basic Mathematical Functions Matlab supports many mathematical functions, most of which are used in the same way you write them mathematically. Elementary math functions (enter help elfun for a more complete list): abs(x) Absolute value | x | sign(x) Sign, returns − 1 if x < 0, 0 if x = 0, 1 if x > exp(x) Exponential e x log(x) Natural logarithm ln x log10(x) Common (base 10) logarithm log 10 x sqrt(x) Square root √ x rem(x,y) Remainder of x/y . For example, rem(100,21) is 16. Also called the modulus function. 24...
View Full Document

Ask a homework question - tutors are online