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.
Remember that the algorithm is
U(xi)=U(xi-1) + h f(xi-1)
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.
>> fplot('f',I) (oops! something is wrong here)
Next write a function file that computes the function y=1+x2. Start the Matlab editor and type:
Save the program in the file func1.m. Then type the following commands:
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!)