Lisp Workpage 1: Simple Calculations
hypotsq = a^2 + b^2 hypot = sqrt(a^2 + b^2) vol = (4/3)*pi*a^3 (answer: vol is 113.097336)(You must convert these to Lisp notation, using nested S-expressions, with the function first. Square root is "sqrt". Lisp has no built-in sqr function, though we can easily write one.) Problem 9.2: More numeric computations. Do > (setq a 1L0) > (setq b -1L0) > (setq c -1L0)and separately use setq to assign each of the two items below: r1 = (-b + sqrt(b^2 - 4*a*c))/(2*a) r2 = (-b - sqrt(b^2 - 4*a*c))/(2*a)(Putting an "L0" at the of the constants will force the arithmetic to be done as long doubles.) Problem 9.3: Let (x1,y1) = (1,0), (x2,y2) = (0,0), and (x3,y3) = (-1,1) be the coordinates of the three vertices of a triangle. Be careful: Each equation that follows is in ordinary notation, not Lisp notation. Convert each of these to Lisp notation, using setq for assignment, and using S-expressions, with the function first. a = sqrt((x2 - x1)^2 + (y2 -y1)^2)and similarly for b and c, to give lengths of the sides of a triangle. Then set alpha equal to the angle opposite side a as given by the formula: alpha = arccos( (b^2 + c^2 - a^2) / (2*b*c)).and similarly for beta and gamma, to give the three angles of the triangle. Finally set sum = alpha + beta + gamma sumdeg = (180/pi)*sumThe final answer, sumdeg, should be approximately equal to the sum of the angles of the triangle (which is, of course 180 in degrees). Revision date: 2013-10-27. (Please use ISO 8601, the International Standard Date and Time Notation.) |