0% found this document useful (0 votes)
57 views2 pages

Computer Lab 3

This document provides instructions for 3 programming exercises to be completed in MATLAB. The exercises are: 1) Write a function to find the nearest value to a desired value in a vector or matrix. 2) Write a function to apply a symmetric moving average filter to smooth noisy data in a vector. 3) Construct a matrix where the numbers 1,2,3 etc are arranged in a pattern increasing from the outer elements to the center. The document also specifies that the work should be completed in groups and include pseudocode for the MATLAB or Python programs developed.

Uploaded by

german intencipa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views2 pages

Computer Lab 3

This document provides instructions for 3 programming exercises to be completed in MATLAB. The exercises are: 1) Write a function to find the nearest value to a desired value in a vector or matrix. 2) Write a function to apply a symmetric moving average filter to smooth noisy data in a vector. 3) Construct a matrix where the numbers 1,2,3 etc are arranged in a pattern increasing from the outer elements to the center. The document also specifies that the work should be completed in groups and include pseudocode for the MATLAB or Python programs developed.

Uploaded by

german intencipa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Fabián Salazar Algoritmos y Métodos Numéricos

2020-II

Computer Lab 3

EQUIPOS:

1. Ordenador con el software instalado, MATLAB, en lo posible la versión más reciente.

Implemente estas rutinas en MATLAB.

La actividad se diseña para identificar el uso de vectores y matrices a través del lenguaje de
programación que seleccione, en ocasiones encontrará dificultad o facilidad al implementar las rutinas
solicitadas, dependerá de su pericia en la programación para hacer de su tarea algo más sencillo o
complejo. Puede usar cualquiera de los dos compiladores para cada punto.

1. Fun with find. Write a function to return the index of the value that is nearest to a desired
value. The function declaration should be: ind=findNearest(x, desiredVal). x is a vector or
matrix of values, and desiredVal is the scalar value you want to find. Do not assume that
desiredVal exists in x, rather find the value that is closest to desiredVal. If multiple values
are the same distance from desiredVal, return all of their indices. Test your function to make
sure it works on a few vectors and matrices. Useful functions are abs, min, and find. Hint:
You may have some trouble using min when x is a matrix. To convert a matrix Q into a
vector you can do something like y=Q(:). Then, doing m=min(y) will give you the
minimum value in Q. To find where this minimum occurs in Q, do inds=find(Q==m);.

2. Smoothing filter. Although it is a really useful function, Matlab does not contain an easy to
use smoothing filter. Write a function with the declaration: smoothed=rectFilt(x,width). The
filter should take a vector of noisy data (x) and smooth it by doing a symmetric moving
average with a window of the specified width. For example if width=5, then smoothed(n)
should equal mean(x(n-2:n+2)). Note that you may have problems around the edges:
when n<3and n>length(x)-2.
• The lengths of xand smoothedshould be equal.
• For symmetry to work, make sure that width is odd. If it isn’t, increase it by 1 to
make it odd and display a warning, but still do the smoothing.
• Make sure you correct edge effects so that the smoothed function doesn’t deviate
from the original at the start or the end. Also make sure you don’t have any horizontal
Fabián Salazar Algoritmos y Métodos Numéricos
2020-II

offset between the smoothed function and the original (since we’re using a symmetric
moving average, the smoothed values should lie on top of the original data).
• You can do this using a loop and mean (which should be easy but may be slow), or
more efficiently by using conv (if you are familiar with convolution).
• Load the mat file called noisyData.mat. It contains a variable x which is a noisy line.
Plot the noisy data as well as your smoothed version, like below (a width of 11
was used):
3. Matrix Patterns. Construct an 𝑛 × 𝑛 matrix, where you can establish a pattern of 1s,2s,3s, etc
in the outer row-column, successively until you completely fill the matrix. Example: Ask for
the user the size of the matrix (5x5) then automatically generates the following:

• El trabajo se debe entregar en grupos de laboratorios debidamente sustentado


• El laboratorio debe incluir el seudocódigo de los programas desarrollados en MATLAB o
PYTHON

You might also like