Lecture 3 Notes

N incr 13014 27 13014 28 if construct if else

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ng point) decimal—whole number exponential general—Matlab chooses a format character string %f %d %e %g %c %s r= input(‘Enter radius: ’) 20 fprintf(‘Increase ’) fprintf(‘is %f inches\n’, x) fprintf(‘Position (%d,%d)\n’, x,y) Examples: %f %15.2f 27 1/30/14 28 1/30/14 Using what we’ve reviewed •  Remark Matlab prints the values of an expression unless it ends with a semi- colon ; This is very handy for prototyping! 1/30/14 Code modifica=on example 23 1/30/14 24 1/31/14 % Example 1_1: Surface area of a sphere % A: surface area of the sphere % r: radius of the sphere Modify the program to calculate the increase in surface area given an increase in the radius of a sphere. r= input('Enter the radius: '); A= 4*pi*r*r; fprintf('Surface area is %f!\n', A) Use miles for the radius, and inches for the radius increase. Note: 1 mile = 5280 feet 1/30/14 1/30/14 % Modified 1_2: Surface area increase % given an increase in the radius 26 % Modified 1_2: Surface area increase % given an increase in the radius r= input('Enter radius r in miles: '); delta= input('Enter delta r in inches: '); r= input('Enter radius r in miles: '); delta= input('Enter delta r in inches: '); newr= r + ((delta/12)/5280); A= 4*pi*r^2; newA= 4*pi*newr^2; incr= newA - A; fprintf('Increase in mile^2 is %f.\n', incr) 1/30/14 27 1/30/14 28 if construct If-else c...
View Full Document

This document was uploaded on 03/11/2014 for the course CSCI 004 at Brown.

Ask a homework question - tutors are online