7_pdfsam_2 - The incorrect result would be computed, but...

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

View Full Document Right Arrow Icon
>> x=2 x= 2 >> y=x+5 y= 7 If you have not supplied a value for x , Matlab will return a syntax error: >> y=x+5 ??? Undefined function or variable ’x’. Precedence of operations involving variables Consider the computation of the area of a trapezoid whose parallel sides are of length b 1 and b 2 and whose height is h : A = ( b 1 + b 2 ) h 2 Matlab statement: area = 0.5*(base_1 + base_2)*height; Deleting the parentheses: area = 0.5*base_1 + base_2*height; This would compute A = b 1 2 + b 2 h
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The incorrect result would be computed, but there would be no error messages, as the command has been written in correct Matlab syntax. Style: writing arithmetic expressions • Use parentheses often Consider the equation to convert from temperature in Fahrenheit ( T F ) to temperature in Celsius ( T C ): T C = 5 9 ( T F − 32) This is computed correctly by the Matlab command: TC = 5/9*(TF-32) 20...
View Full Document

Ask a homework question - tutors are online