0% found this document useful (0 votes)
93 views4 pages

Fall 2012 - Homework 5: Che 3E04 - Process Model Formulation and Solution

This homework assignment involves writing MATLAB code to numerically integrate functions using techniques like trapezoid integration, Richardson extrapolation, and step-size adjustment. Students will write functions to evaluate a test function, calculate integrals using trapezoids, and implement Richardson extrapolation with recursion to integrate the function more accurately. They will integrate the test function from 1 to 10 with varying tolerances and compare the results to MATLAB's built-in integration function to estimate errors. A log-log plot of the estimated error vs tolerance must be submitted.

Uploaded by

harvey
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)
93 views4 pages

Fall 2012 - Homework 5: Che 3E04 - Process Model Formulation and Solution

This homework assignment involves writing MATLAB code to numerically integrate functions using techniques like trapezoid integration, Richardson extrapolation, and step-size adjustment. Students will write functions to evaluate a test function, calculate integrals using trapezoids, and implement Richardson extrapolation with recursion to integrate the function more accurately. They will integrate the test function from 1 to 10 with varying tolerances and compare the results to MATLAB's built-in integration function to estimate errors. A log-log plot of the estimated error vs tolerance must be submitted.

Uploaded by

harvey
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/ 4

ChE 3E04 – Process Model Formulation and Solution

Fall 2012 – Homework 5


Due: Mon, Dec 3, 8:30am in class Note: to be performed in groups of up to three.
Grading:100 pts. Weight: 5% of total course grade.

OBJECTIVES

Learn and demonstrate skills with:


 Trapezoid Integration
 Simpson’s Rules for Integration
 Richardson Extrapolation
 Step-Size Adjustment Integration Algorithms
 Recursion

SUBMISSION

The method of submission of your answer for each question or part of question will vary. Typically,
anything that can be checked by computer will be submitted to Avenue to Learn, and anything
which must be viewed by humans will be submitted in hardcopy.

[A2LQuiz] - This symbol means to submit your answer to the online quiz on Avenue to Learn

[A2LDropBox] - This symbol means to submit your answer to the drop box on Avenue to Learn

[ONPaper] - This symbol means to submit your answer in hard copy.

Always have all names and student numbers on any printed out / hardcopies.

ORAL EXAMINATION – STAND AND DELIVER

This assignment will be different than the previous. Instead of earning points for submitting the
correct answers to the questions, each student must present the solutions to one of the
instructors orally. This means that each of you, individually, must make a 15 minute appointment
for Tuesday Dec 4 [there are no classes that day so there are no excuses – MSAFs will result in
rescheduled appointments]. You will meet with one of the TAs or the professor. During this time,
you will present your code and your written solutions to the instructor, and you will earn points
based on your demonstrated knowledge of the material.

In general, we will be asking critical questions along the way to probe your knowledge, but also to
help you when you get stuck. For example, if you get something wrong, we may be able to ask the
questions in the right way such that you figure out the correct answer on the spot. In fact, it is
possible to get 100% on this assignment even though you have not completed all the questions
because if we judge that, in our opinion, you have complete mastery of how to solve the problem
and know what the outcome would be, then you would earn the points.

1|Page
There are a lot of good things that can come from this. For example, you will get immediate
feedback from the instructors on the key places where you need to improve in order to get ready
for the final exam. Also, sometimes there are just minor tweaks that may make your code work
perfectly that we may be able to get you to correct during the 15 minute oral exam and then thus
earn points.

Here are some things we would expect you to know:

 What the problem is asking you to do. That is, can you explain the problem [both the details
and the point of the problem] to us?
 The fundamental theory that we’re applying in order to solve the problem. That is, can you
explain the equations we are using, why we are using them, why they will work, and other
relevant information?
 A general solution strategy for how the problem is solved. I.e., present the algorithm to us.
For example, perhaps you should be able to sketch how it works.
 The details of the implementation (matlab code) which you used. That is, you should know
each line of it and be able to answer questions about what happens if we change this or that.

The instructors will all have a set of criteria which the student must meet, but they are allowed to
ask whatever questions they need to help get you there. In other words, it’s personal help.

RULES
 You must sign up for a time slot. We’re open pretty much all day Dec 4, and there are three
spots per time block. First come first served.
 You have 15 minutes to present your case. STAND AND DELIVER. There will be a
whiteboard.
 We don’t want powerpoint or rehearsed talks. Just answer our questions.
 If you are late, you simply have less minutes. If you miss it, too bad.
 You still must submit the hardcopy in class and the Matlab code to the A2L Dropbox
 Each group member may bring in photocopies of the hardcopy submission and printouts of
the matlab code. NOTHING ELSE.
 We’ll open up your submitted .m files use those on our computers.
 You have to submit a hardcopy and code to be eligible for an oral exam and thus any chance
at points.

HOW TO SIGN UP FOR A TIME SLOT

1. Go to: http://doodle.com/zs87tr7qyf52q35u
2. Type your name in the box that says "Your name"
3. Select an available time slot
4. IMPORTANT: scroll all the way to the right and click "save"
You should see a screen that says "Thanks, your choices have been submitted"

HOW TO CHANGE YOUR SELECTION


1. Go to the link above
2. Hover your mouse over your name on the list.
3. Click the "pencil" (edit) button.
4. Select the slot you want
5. IMPORTANT: scroll all the way to the right and click "save"

2|Page
QUESTIONS

In this assignment, you will write a program in MATLAB which uses trapezoid integration,
Richardson’s extrapolation, and a step-size adjustment mechanism to create a robust integration
program which maximizes accuracy while minimizing the number of function evaluations. The
program should be applicable to any arbitrary scalar function f(x) and only require the tolerance (ε)
and domain limits (xmin and xmax) to be specified as inputs. This is very close to a “professional”
numerical integrator which forms the heart of just about any piece of numerical software used
throughout industry.

To do this, we can use the algorithm derived in class and break the pieces up into baby steps. To
start with, we will use the following test function:

( ) ( [ ]) for 1≤x≤10 (eq 1)

As a review from class, here is the overview of the strategy:

 To save time, create a function which computes f(x) given x.


 Create a function which gives the trapezoid integral of f(x) from point a to b.
 Create a function which integrates from c-d by using trapezoids with Richardson
extrapolation. Then, if the accuracy is not good enough, it breaks the c to d region in half,
and then calls itself on those two half regions.
 Create a main function which just handles plots and whatever.

Q1) Write the above function in an .m file so that given x as an input it returns f(x). Hint, it pretty
much should be only two lines long. This just makes it easy to make function calls to it, and lets us
swap out for new functions very easily by making only one change.

Q2) Write a new matlab function which will approximate the following integral…

∫ ( ) (eq 2)

…using one big trapezoid approximation. Note that if b and a are close together, this will be a good
approximation for the area under the curve. As a hint, this function should only require about two
lines of code. The function should take a and b as parameters (the stuff you pass into the function).

Q3) Now, write a new matlab function which uses Richardson extrapolation to make a higher-order
approximation of eq 2. As discussed in class:

1. Estimate the integral from a to b using a trapezoid


2. Estimate the integral from a to b using two trapezoids (“left half” and “right half”).
3. If those two integrals are within some tolerance of each other: (i.e, if |I1 – I2| < tol)
a. Perform a Richardson extrapolation using the step 1 and 2 result to get the best
approximation for the integral from a to b.
4. Else

3|Page
a. Call this same function recursively using the left and right halves of the integral.
This will effectively half the stepsize in the region a to b.
5. HINTS:
a. This function should accept a, b, and the tolerance as a parameter.
b. My solution is ten lines long to give you an idea of scale. Yours can be longer or
shorter as long as it works.
c. You will use recursion as discussed in class.
d. It might help you to debug by outputting the values of a, b, and the integral to the
command terminal each time this function runs. For example, consider adding the
line:
fprintf('Now integrating from %g to %g\n', a, b);

Similarly, maybe you want to add similar print statements where you either accept
or break the integral down into parts.

Q4) Finally, write a program which calls your function in Q3 to integrate of eq1 from 1 to 10 with a
tolerance of 0.2.

Q5) Estimate the “exact” integral of eq1 from 1 to 10 using matlab’s built in quad function. As an
example, if the function you made in Q1 was called Q1.m, you could use the command:

BestIntegral = quad(@Q1, 1, 10)

The quad function does essentially the same algorithm that you are using in this assignment, except
that it uses Simpson’s rules instead of trapezoids. Note that to use quad, your Q1 function needs
accept vectors, so put dots before your operators: log(x.^2./(1+x)) + sin(cos(x.^2))

Q6) Report the estimated error between your result and the “professional” version using the Q5
result as your estimate for the “actual” result. [ONPaper]

Q7) Modify your program to make a log-log plot the estimated error of your integral as the
tolerance changes from 10-1 to 10-7. Submit this plot and all code to Avenue to Learn and in hard
copy. [A2LDropBox] [ONPaper]

Note, you can use the loglog command in matlab just like you would use the plot
command to make a log-log plot.

Note an easy way to get points relative to a log-log plot from 10-1 to 10-7 is to use the
command logspace(-1, -7). This will create a vector of points from 10-1 to 10-7.

Q8) Now, go back and modify your code so that instead of trapezoids, Simpsons 1/3 rule is used.
Repeat question Q7 and add the estimated error using Simpsons to the plot (so you can see
simpsons and trapezoids both). Note that Richardson’s Extrapolation for Simpsons is not the same,
its:

4|Page

You might also like