Frequently asked questions and answers.



 
    1. How does Matlab solve the cooling problem using eulerc.m?
There are two ways to solve problems using Matlab. >> y(1)=200; T=200; KK=50; h=T/KK; t(1)=0;
>>  for k=1:KK                                                                 % Euler's method
             y(k+1)=y(k)+h*feul(t(k),y(k));                      % Need to use feul.m
             t(k+1)=t(k)+h;                                                     % t(k) is the time array, y(k) is the approximate
        end                                                                               % solution at t=t(k).
>>   plot(t,y)

However, when we quit Matlab, all the information is gone. You have re-type them again if you want to it again! If you have a typo, you also have to retype them again.

>> eulerc.m

Matlab will search the file and executes the Matlab command in the file line by line. It is the exactly th esame as you would type them in. After you quit Matlab, the file is still there, you can redo it or modify it whenever you want.  This kind of files are called Matlab script files, which contains Matlab commands.
 


    2. I type feul within Matlab but got an error message.  What is the problem?
feul.m defines a Matlab function feul(t,y),  the format is:
function y = feul(t,y)
which takes inputs t and y and return a function value. In matlab, the usage is

>> feul(1,2)

ans =

    2.6216
 
In Lesson 2, the function is called when we need the function value at f(t(k),y(k))

y(k+1)=y(k)+h*feul(t(k),y(k));

 3. I have three files  tayde.m,  ftay.m,  ftayu.m  that all have a parameter c, how do I just make one change  in one file, and other files will autamatic take the change?

Use global command:  In tayde.m before you define c, type

           global c                                                         % Added line.
           c = 2/155;
           ...............

In  ftay.m, add a line

           function ftay = ftay(t,x)
             global c                                                      % Added line
            ftay = c*(102 - x);

In  ftayu.m, add a line:

            function ftayu = ftayu(t,x)
                    global c                                                 % Added line
                    ftayu = -c;