EGR 103/Fall 2015/Lab 4

From PrattWiki
Jump to navigation Jump to search

The following document is meant as an outline of what is covered in this assignment.

Typographical Errors

None yet!

Specific Problems

Palm Figure 6.1-1, p. 264

The main goals here are to learn how to put italics and math in labels and titles and how to put text on a plot.

Chapra Problem 3.5

The primary goal here is to calculate a series of estimates to the \(\cos(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] = CosSeries(pi/6, 5)
Vals =
   1.0000e+00   8.6292e-01   8.6605e-01   8.6603e-01   8.6603e-01
Errs =
  -1.5470e+01   3.5833e-01  -3.2885e-03   1.6129e-05  -4.9180e-08

and

>> [Vals, Errs] = CosSeries(pi, 4)
Vals =
   1.0000e+00  -3.9348e+00   1.2391e-01  -1.2114e+00
Errs =
   2.0000e+02  -2.9348e+02   1.1239e+02  -2.1135e+01

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.

Chapra Problem 4.1

The primary goals here are to re-use an iterative solver with a different iterator and to present the information in a table generated for LaTeX by MATLAB.

  • The code on page 94 of the Chapra book, in Figure 4.2, is incredibly useful and important. You will need to have it memorized eventually, but for now focus on understanding how it does what it does.
  • One difference between your code and the code in the book is that your original sol will be set equal to the first input, called a instead of x in your code. This will happen on the line under the comment % initialization
  • One more difference will be on the line where sol gets updated. Make sure you understand where and how the update is happening in the original code with the original iterator, then re-write it for your iterator.
  • The page on MATLAB:LaTeX_Table_Writer really will be helpful; note that the RunDivAvg.m code already has comments where you need to make changes.
  • The section on MATLAB:LaTeX_Table_Writer#Saving_to_a_File will explain what the fopen and fclose functions, as well FID variable, do.

3D Projections

The primary goal here is to present a graphical representation of a 3-dimensional curve using both isometric and orthographic projections.

General Concepts

Use Piazza to let the instructors know what general concepts you would like more information on for this lab.