Difference between revisions of "EGR 103/Fall 2014/Lab 4"
m |
|
(No difference)
|
Revision as of 17:41, 14 September 2014
This page is meant to serve as the basis for a self-guided tour of the various parts of Lab 4. It will include relevant links and example for each problem.
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.
- Information on how to labels axes and the title, including using italics: MATLAB:Plotting#General_Plotting_Tips
- Information on putting text on a plot is at: MATLAB:Plotting#Putting_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:
>> [X, Y] = CosSeries(0, 3)
X =
1 1 1
Y =
0 0 0
and
>> [X, Y] = CosSeries(3*pi/5, 4)
X =
1.0000e+00 -7.7653e-01 -2.5052e-01 -3.1282e-01
Y =
4.2361e+02 -1.5129e+02 1.8930e+01 -1.2299e+00
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, calleda
instead ofx
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
andfclose
functions, as wellFID
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.
- You will need to use the
subplot
command, which is described in MATLAB:Plotting#The_subplot_Function - You will not have an iterative structure here...at least, you do not need one.