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

ALA-B, 2003, studio 1.1 - 1.2

Home, w 1, w 2, w 3, w 4, w 5, w 6, w 7. Matlab: analysis, linear algebra, facit.

The integral

Do not print this file!! Read it from the computer screen.

1. Illustration of "The Fundamental Theorem of Calculus".

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.

2. My integral.

You will write a Matlab program that solves the initial value problem
u'(x)=f(x), a<x<b,
u(a)=ua

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

Remember that the algorithm is

x0=a
U(x0)=ua

xi=xi-1+h
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.

>> 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+x2. 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!)

3. Test

Each student must demonstrate to the studio teacher that he/she can do the following: This is the obligatory work of week 2. Write this down for your individual folder and demonstrate it to your studio teacher before the end of week 2.

/stig


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