Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
63 views

Matlab Basics: Exercise 3 (Loops and Conditional Statements)

This document provides instructions for writing MATLAB code to perform common statistical calculations and loops. Specifically it asks the reader to: 1. Write a function called find_ave.m that calculates the average of a vector by summing its components and dividing by its length. 2. Write a function called std_dev.m that calculates the standard deviation of a vector by calling find_ave.m, computing the differences of each value from the average, squaring them, summing them, and taking the square root. 3. Write a function called increment.m that uses a loop to increment a counter variable from 0 to the input value n. 4. Examine and run code from the textbook that

Uploaded by

yared4
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Matlab Basics: Exercise 3 (Loops and Conditional Statements)

This document provides instructions for writing MATLAB code to perform common statistical calculations and loops. Specifically it asks the reader to: 1. Write a function called find_ave.m that calculates the average of a vector by summing its components and dividing by its length. 2. Write a function called std_dev.m that calculates the standard deviation of a vector by calling find_ave.m, computing the differences of each value from the average, squaring them, summing them, and taking the square root. 3. Write a function called increment.m that uses a loop to increment a counter variable from 0 to the input value n. 4. Examine and run code from the textbook that

Uploaded by

yared4
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Matlab Basics: Exercise 3 (Loops and Conditional Statements)

1.) Write an m-file called find_ave.m that reads in a vector x and outputs
the average of the components of x. Design this so x can be a vector
of any length by setting n=length(x) (since you will need to divide the
sum of those components by the number of components).
2.) Write an m-file that computes the standard deviation of a vector called
std_dev.m. The function should read in a vector x and then call
find_ave.m to get the average. To compute the standard deviation we
need to compute s

1
n 1

( x(i) x
i 1

average

)2

where here n=length(x)

and x(i) is the i-th component of x (In other words the i-th entry in our
list of numbers) and xaverage is the average you would get by calling
find_ave.m.
3.) Write an m-file called increment.m that first set counter=0 and then in
a loop adds one onto counter n times. You can write this so n is
your input. The final value of counter should be n.
4.) Look at the code on page 281 of the text (or page 19 of the MATLAB
tutorial). Code this up and play with it! What does it do?

You might also like