08.07.2015 Views

Introduction to MATLAB 7 for Engineers Chapter 1 An ... - FET

Introduction to MATLAB 7 for Engineers Chapter 1 An ... - FET

Introduction to MATLAB 7 for Engineers Chapter 1 An ... - FET

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example of a <strong>for</strong> LoopWrite a script file <strong>to</strong> determine how many terms arerequired <strong>for</strong> the sum of the series 5k 2 –2k, k = 1, 2, 3, …<strong>to</strong> exceed 10,000. What is the sum <strong>for</strong> this many terms?<strong>to</strong>tal = 0;k = 0;while <strong>to</strong>tal < 1e+4k = k + 1;<strong>to</strong>tal = 5*k^2 - 2*k + <strong>to</strong>tal;enddisp(’The number of terms is:’)disp(k)disp(’The sum is:’)disp(<strong>to</strong>tal)1-54The sum is 10,203 after 18 terms.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!