Matematik och Datavetenskap, Chalmers Tekniska Högskola och Göteborgs Universitet

Start Matlab. Type `matkfkb` and `setmatlabpath`
(to set the search path), then
type `mathguide` (or `matteguiden`) and press the button
"Integration".

Choose a function f(x) from the menu, press interpolate and then integrate. Begin with a large step (h=0.1) because it is easier to see what happens then.

Move the i.p. control from right to left and middle to see three choices of interpolation point.

Change ua to see what happens.

u(a)=u

according to the algorithm in the Fundamental Theorem of Calculus. You must use the template my_int.m.

Remember that the algorithm is

*x*_{0}=*a*

*U(x*_{0}*)*=*u _{a}*

*x _{i}=x_{i-1}+h*

Close and restart Matlab WITHOUT typing `matkfkb` and
`setmatlabpath`. These commands set the search path to
directories that we do not want to use now.

**Note:** The teachers are not allowed to help you find syntax
errors. You must always make sure you understand what you are doing.
Write only one command at a time and test it on the command line
before you put it in your m-file.

We begin by learning about the commands `feval` and `fplot`.
Type the following commands and make sure that you understand what
they do.

`
>> cos(pi)
>> cos(3.14)
>> x=3.14
>> cos(x)
>> feval('cos',3.14)
>> f='cos'
>> f
>> x
>> feval(f,x)
>> fplot('cos',[0,pi])
>> fplot(f,[0,pi])
>> I=[0,pi]
>> fplot('f',I)
(oops! something is wrong here)
`

Next write a function file that computes the function
*y=*1+*x*^{2}. Start the Matlab editor and type:

`
function y=func1(x)
y=1+x^2;
`

Save the program in the file `func1.m`. Then type the
following commands:

`
>> func1(3)
>> feval('func1',3)
>> fplot('func1',I)
>> g='func1'
>> fplot(g,I)
>> feval(g,2)
`

Now start to write the program `my_int` using the template
my_int.m.

Test your program on several functions for which you know the exact
solution. Plot the function *U(x)* by typing `plot(x,U)`. Use a
very large step (*h*=1 or *h*=0.1) in the beginning when you test the
program, because then it is easier to see if the program does the right
thing. (Choose examples from the exercises in the book.)

Do at least five examples. Make sure that you understand everything.

Erase your program `my_int` and write it again until you
really understand it. The goal is not that you should have a correct
program, but that you should understand how this program is written.
(This will be on the exam!)

Write down what you do in a clear way, so that you can repeat it when you prepare for the exam. Each student must have her/his own copy of the program and know how it was written. (This will be on the exam!)

- Choose three simple examples that can be used to test the program.
- Compute the solution symbolically (by hand).
- Write a function file for each example.
- Solve the problem numerically with
`my_int`. - Compare the symbolical solution and the numerical solution by plotting them in the same window.

`/stig`

Last modified: Thu Oct 23 15:06:28 MEST 2003