EGR 103/Fall 2017/Lab 5

From PrattWiki
Jump to navigation Jump to search

Typographical errors

None identified yet!

5.1 Introduction

The main purpose of this lab is to learn more about structured programming, especially iterative structures and logical masks.

5.4.1 Chapra 3.5

The primary goal here is to calculate a series of estimates to the \(\sin(x)\) function using a Maclaurin series.

  • The core of the function will likely be a for loop. There are examples at MATLAB:Iterative_Structures
  • Think carefully about what your scanner variable means and whether you need an external variable. Keep in mind that there are two numbers to keep track of - which term you are on, and what the value of the power of \(x\) and the factorial in the numerator might be. They can be written in terms of each other, or you can use two different variables.
  • Note that your output will have as many entries as the number of terms you asked for - for instance:
>> [Vals, Errs] = SinSeries(pi/6, 5)
Vals =
   5.2360e-01   4.9967e-01   5.0000e-01   5.0000e-01   5.0000e-01
Errs =
  -4.7198e+00   6.5164e-02  -4.2652e-04   1.6262e-06  -4.0560e-09

and

>> [Vals, Errs] = SinSeries(pi/3, 4)
Vals =
   1.0472e+00   8.5580e-01   8.6630e-01   8.6602e-01
Errs =
  -2.0920e+01   1.1806e+00  -3.1163e-02   4.7714e-04

As a result, you need to make sure that your loop is storing each new term in the series in a new entry. On the MATLAB:Iterative_Structures, pay special attention to how the different values are stored in Temperatures.

  • You can actually calculate all the relative errors at once at the very end rather than in the loop if you so choose.
  • Do not change anything about the SinSeriesChecker program! When you want to run it, type
SinSeriesChecker('NetID')

where NetID is your NetID. For instance, for Dr. G it would be:

SinSeriesChecker('mrg')

5.4.2 Chapra 3.10

The main concepts here are using logical masks to create piecewise functions, using different sets of points for mathematical analysis versus graphing, and determining and locating extrema.

5.4.3 Chapra 3.14

The main concept here is also to use logical masks to create a piecewise function and then use that function to make a plot.

5.4.4 Palm 4.44

The main concepts here are using the switch-case-otherwise structure when your code is to run certain lines of codes based on strings, using different point styles if you have five or more lines to graph in black and white, and using scripts and functions together.

5.4.5 Data Logger

The code you need here
Mostly exists on Pundit
(sans the fprintf...)

Four words of caution
To remember when coding:
Columns are not rows!

Sample TempCheck.m Run

From MATLAB:

>> TempCheck('blah')
blah
out =
   3.3524e+02
Readings Minimum Average Maximum
       1  335.24  335.24  335.24
out =
   3.0038e+02
Readings Minimum Average Maximum
       2  300.38  317.81  335.24
out =
   2.7228e+02
Readings Minimum Average Maximum
       3  272.28  302.63  335.24
out =
   3.0576e+02
Readings Minimum Average Maximum
       4  272.28  303.41  335.24
out =
   3.3455e+02
Readings Minimum Average Maximum
       5  272.28  309.64  335.24
out =
   2.6636e+02
Readings Minimum Average Maximum
       6  266.36  302.43  335.24

Sample Text File

In UNIX:

> more MyTemps.txt
   3.3523719e+02
   3.0037886e+02
   2.7227560e+02
   3.0576493e+02
   3.3454886e+02
   2.6636305e+02

General Concepts

This section is not in the lab report but rather has some items in it that span multiple problems in the lab.

Determining and Locating Extrema

See MATLAB:Plotting#Using_Different_Scales and MATLAB:Plotting_Surfaces#Finding_Minima_and_Maxima_in_2-D for some examples. Also see Palm Table 2.1-1.

Logical Masks

See MATLAB:Logical Masks.


Class Document Protection