{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 2 Notes

# 12814 script execution script execution 1 a b c d r1

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: use all letters and numbers and the underscore character Example: x1A-New Insight Through Computing a b c d r1 r2 = = = = = = x^2 + 5x + 6 = 0 1; 5; 6; sqrt(b^2 - 4*a*c); (-b - d)/(2*a) (-b + d)/(2*a) Insight Through Computing Assignment Statements Variable Name where to put the value = Script Execution a Arithmetic Expression a b c d r1 r2 a recipe for computing a numerical value = = = = = = 1; 5; 6; sqrt(b^2 -4*a*c); (-b - d)/(2*a) (-b + d)/(2*a) b c d r1 r2 Insight Through Computing Insight Through Computing Script Execution Script Execution 1 a b c d r1 r2 = = = = = = 1; 5; 6; sqrt(b^2 -4*a*c); (-b - d)/(2*a) (-b + d)/(2*a) 1 a b c d a b c d r1 r2 = = = = = = 1; 5; 6; sqrt(b^2 -4*a*c); (-b - d)/(2*a) (-b + d)/(2*a) r1 5 b c d r1 r2 Insight Through Computing a r2 Insight Through Computing 6 1/28/14 Script Execution Script Execution 1 a b c d r1 r2 = = = = = = 1; 5; 6; sqrt(b^2 -4*a*c); (-b - d)/(2*a) (-b + d)/(2*a) a 5 b 6 c d 1 a b c d r1 r2 = = = = = = 1; 5; 6; sqrt(b^2 -4*a*c); (-b - d)/(2*a) (-b + d)/(2*a) a 5 b 6 c 1 d r1 r1 r2 Insight Through Computing r2 Insight Through Computing Script Execution Script Execution 1 a b c d r1 r2 = = = = = = 1; 5; 6; sqrt(b^2 -4*a*c); (-b - d)/(2*a) (-b + d)/(2*a) 1 5 b 6 c 1 d -3 a b c d r1 r2 = = = = = = 1; 5; 6; sqrt(b^2 -4*a*c); (-b - d)/(2*a) (-b + d)/(2*a) r1 r2 Insight Through Computing Insight Through Computing Remember… Instructions are executed in order. In assignment statements, the right hand side is evaluated ﬁrst and then the value is assigned to the variable named on the left hand side. The variables on the right hand side must have values before they can be used in an expression. Insight Through Computing a 5 b 6 c 1 d -3 r1 -2 a r2 Question Time What is the value of X and Y after the following script is executed: X Y X X = = = = 2; 7*X; Y; X + 1; A: X is 5 and Y is 14 C: X is 5 and Y is 21 B: X is 15 and Y is 14 D: X is 15 and Y is 2 Insight Through Computing 7 1/28/14 Question Time Input & Output •  What about input and output? What is the final value of X and Y ? > > > > > X Y X X Y A: = = = = = 8; X; Y; 2*X; Y/2; C: B: X is 8 and Y is 8 X is 16 and Y is 4 D: X is 16 and Y is 16 X is 8 and Y is 4 Insight Through Computing Insight Through Computing % Example 1_1: Surface area of a sphere % A: surface area of the sphere % r: radius of the sphere r= input('Enter the radius: '); A= 4*3.14159*r*r; fprintf('Surface area is %f!\n', A) n༆  variable = input(‘prompt ’) n༆  Lecture 2 Inpu...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online