Computing Information

Dec. 07, 2004 News: The m-files from the tutorial are here (note the name change): runu.m   uN.m
Nov. 29, 2004 News: Here are some files for the example we did today in class: run.m   f.m   fN.m
Put run.m, f.m, and fN.m into the same folder.  Go to that folder
      and type "run" at the matlab prompt.  This will do the step function we
      did in class today.  Notice that the max norm of the error is constant
      (~1) and the squares sum norm of the error goes down as N increases.
        
run.m:
clear;

% example:
%        {  0    if -1<x<0
% f(x) = {
%        {  1    if 0<x<1
%
x=-1:.01:1;

% plot partial sums for N=3, 6, and 20: fN(x,3), fN(x,6), and fN(x,20)
% also plot the exact: f(x)
fexact=f(x);
fN3=fN(x,3);
fN6=fN(x,6);
fN20=fN(x,20);
figure(1);
plot(x,fexact,'k-',x,fN3,x,fN6,x,fN20);
legend('N=\infty','N=3','N=6','N=20','Location','Best');
title('Plotting N=3,6,20');
xlabel('x');
ylabel('f_N');


% now plot the error for each one
figure(2);
plot(x,abs(fexact-fN3),x,abs(fexact-fN6),x,abs(fexact-fN20));
legend('N=3','N=6','N=20','Location','Best');
title('Plotting error for N=3,6,20');
xlabel('x');
ylabel('e_N');

% now print out the max of the absolute value of the error and the squared
% sum of the error
disp('The max errors are:');
disp(['N=' num2str(norm(fexact-fN3,inf))]);
disp(['N-' num2str(norm(fexact-fN6,inf))]);
disp(['N-' num2str(norm(fexact-fN20,inf))]);
disp('The squared sum errors are:');
disp(['N=' num2str(norm(fexact-fN3,2))]);
disp(['N-' num2str(norm(fexact-fN6,2))]);
disp(['N-' num2str(norm(fexact-fN20,2))]);
f.m
function out=f(x)
%
% generates the values of the piecewise function f(x)

for j=1:length(x)
  if(x(j)<0)
    out(j)=0;
  elseif(x(j)>=0)
    out(j)=1;
  end
end
fN.m
function out=fN(x,N)
%
% computes the Nth partial sum of the fourier series for f(x)
%
out=zeros(size(x)); % initialize output
L=x(end);

a0=1;               % for a0
out=out + a0/2;
fprintf('\n Adding...(to %d)',N);   % print statement
for n=1:N
  fprintf('..%d',n);                % print statement
  k=2*n-1;
  an=0;
  bn=2/(k*pi);
  out = out + an*cos(k*pi*x/L) + bn*sin(k*pi*x/L);
end
fprintf('\n');                      % print statement
Nov. 19, 2004 News: Here is the test.m from class.
Test.m
        
Run:
>> test (now change s if you want and don't close the plot) >> hold on; >> test
      %

      clear;

      L=1;          % length of interval
      s=51;         % number of terms to plot

      x=-L:.01:L;

      f = 0*x;      % initialize f

      % terms from a0
      f = f + 0;

      % terms from an
      for n=1:2:s   % odd terms
        f = f + 0*cos(n*(pi/L)*x);
      end

      % terms from bn
      for n=1:2:s   % odd terms
        f = f + (4/(n*pi))*sin(n*(pi/L)*x);
      end

      plot(x,f,'b-');  % blue solid
      
General

There are many computing resources available that will aid in your exploration and understanding of differential equations. The main software packages the we recommend are

All can be found in the general computing labs on campus and available for purchase at significantly reduced rates for students. Throughout the course we will reference these various software packages when applicable.

Matlab is used extensively in the scientific computing community, is fairly easy to learn, and quite robust offering packages for visualization, numerical linear algebra, numerical differential equations and limited sybolic computation. For primers on matlab, we recommend:

Maple is primarily a used for symbolic computation and competes more with Mathematica. It can be used for plotting and easily finding analytic solutions. Here are some helpful tutorials:

Mathematica is widely used in education and has an extensive help network. Some tutorials include:

Direction Fields
Plotting direction fields with Matlab, Mathematica, and Maple: [.pdf]
Maple/Matlab Tutorials

I will give a tutorial on the following dates:

Time Topic Location Handout
TBA TBA TBA  

The intent of these sessions is to learn the basics of the application. Please bring questions if you have them. Also, these are not mandatory, but will be quite helpful (I hope!). Arrive late or leave early...it is suppose to be informal. With the computer lab available, we will go through some prepared worksheets and work interactively on them together. See you there!