Docsity

MATLAB Exercises for BME 3400 - Biosystem Analysis, Spring 2009, Lab Reports of Biology

Toggle sidebar
bg1
BME 3400 – Biosystem analysis
Spring 09
Page 1 of 1
MATLAB Exercises
Solve the following exercises using MATLAB and email the m-file to the lab instructor.
You can work individually or in groups of 2 or 3 students. If you have questions, please
email the instructor. The due date is February 13, 2009.
1. Go to the Help menu, and click on MATLAB Help. In the Contents menu, select
MATLAB > Programming > Program control statements. Read the explanation about
how to use loops and flow control functions.
2. Write the code to add all the numbers corresponding to the even indices of an array.
For instance, if the array is specified as x = [1, 3, 5, 10], then 13 should be returned.
Use the program to find the sum of all even integers from 1 to 1000.
3. Explain what the following .m code does:
L = length(x);
for j=1:L;
if x(j)<0,
x(j)=-x(j);
end
end
Rewrite this program without using a for loop.
4. Write a .m file code that implements the following hard-limiting function:
2.0
2.0
tx
2.0
2.0
t
t
For t, use 1000 random numbers generated via the function rand(1,1000). Plot
the signals t and x.
5. Write a program to create a new vector by inserting zeros between adjacent elements
of a vector. For example, if the original vector is defined as x1 = [0, 1, 5, 5, -2], the
program should return: x2 = [0, 0, 1, 0, 5, 0, 5, 0, -2]
a) If the length of the original vector is L, what is the length of the new vector?
b) Extra credit: Instead of inserting zeros, insert numbers corresponding to the
average of their neighbors. So, for the same original vector given above, the
program should return: x3 = [0, 0.5, 1, 3, 5, 5, 5, 1.5, -2]

Partial preview of the text

Download MATLAB Exercises for BME 3400 - Biosystem Analysis, Spring 2009 and more Lab Reports Biology in PDF only on Docsity!

BME 3400 – Biosystem analysis Spring 09

Page 1 of 1

MATLAB Exercises

Solve the following exercises using MATLAB and email the m-file to the lab instructor. You can work individually or in groups of 2 or 3 students. If you have questions, please email the instructor. The due date is February 13, 2009.

  1. Go to the Help menu, and click on MATLAB Help. In the Contents menu, select MATLAB > Programming > Program control statements. Read the explanation about how to use loops and flow control functions.
  2. Write the code to add all the numbers corresponding to the even indices of an array. For instance, if the array is specified as x = [1, 3, 5, 10], then 13 should be returned. Use the program to find the sum of all even integers from 1 to 1000.
  3. Explain what the following .m code does:

L = length(x); for j=1:L; if x(j)<0, x(j)=-x(j); end end

Rewrite this program without using a for loop.

  1. Write a .m file code that implements the following hard-limiting function:

x t

  1. 2

t

t

For t, use 1000 random numbers generated via the function rand(1,1000). Plot the signals t and x.

  1. Write a program to create a new vector by inserting zeros between adjacent elements of a vector. For example, if the original vector is defined as x1 = [0, 1, 5, 5, -2], the program should return: x2 = [0, 0, 1, 0, 5, 0, 5, 0, -2]

a) If the length of the original vector is L, what is the length of the new vector?

b) Extra credit: Instead of inserting zeros, insert numbers corresponding to the average of their neighbors. So, for the same original vector given above, the program should return: x3 = [0, 0.5, 1, 3, 5, 5, 5, 1.5, -2]