Lecture 3 Notes

# The breakpoint is randomly selected on average how

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: tera=on for k=1:4 L = (L + W)/2; end + + + + A = input(‘A:’); nSteps = input(‘nSteps:’); L = A; W = A/L; W = A/L; for k=1:nSteps L = (L + W)/2; end 47 1/30/14 W = A/L; 48 1/31/14 To repeat something N =mes: To repeat something N =mes: N = _____ N = _____ for i = 1:N for i = 1:N Put the something here. Put the something here. end The Loop “body” end 1/30/14 49 1/30/14 To repeat something N =mes: N = _____ for i = 1:N 50 Example: “Accumulate” a solution % Average 10 numbers from user input The “count variable” Put the something here. The Loop “body” N= 10; % number of data values total= 0; % current sum (initialized to zero) for k= 1:N % read and process input value num= input('Enter a number: '); total= total + num; end ave= total/N; % average of n numbers fprintf('Average is %f\n', ave) end 1/30/14 51 1/30/14 52 Another Example Remember to initialize % Average 10 numbers from user input N= 10; % number of data values total= 0; % current sum (initialized to zero) for k= 1:n % read and process input value num= input('Enter a number: '); total= total + num; end ave= total/N; % average of n numbers fprintf('Average is %f\n', ave) for k = 1:10 x = rand; fprintf(‘%10.6f\n’,x)) end Displays 10 random numbers. 1/30/14 53 1/30/14 54 1/31/14 E.g., Built- In Func=on rand The statement 0.579736 0.609194 0.256451 0.246079 0.149936 0.564178 0.027311 0.790830 0.437630 0.997130 x = rand assigns a “random” number betwe...
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