% Sample session with MATLAB % (1) GETTING STARTED: % First log into a unity machine with your id and password. % Start an xterm. % Type "add matlab7" at the prompt to ensure that you % will use MATLAB 7 hereafter. This has only to be done once. % Type "matlab" at the prompt % A MATLAB desktop should now appear. % Download the programs "euler.m" and "myfunc.m" % from the course webpage into your home directory. % (2) A SAMPLE SESSION WITH EULER'S method in MATLAB % I assume you now have the MATLAB desktop running % You should type the following lines % in your MATLAB desktop in the following order: % I have interspaced my comments in the discussion . % These comments appear on a line that starts with a % sign. % You need not type these comment lines in your MATLAB desktop. % Kartik's MATLAB session: 31st August 2005 % Let's try to solve the ODE % dy/dx = y(2-y) % y(0) = 3 % for all x in the interval [0 5] % The file 'myfunc.m' contains the function y(2-y) % The intial conditions are x0 = 0, y0 = 3 % x1, the end of my time interval, is 5 % We will first use 10 steps in Euler's method % This is how you call the function euler.m in MATLAB % The output variables xe1,ye1 contain the x and y values % computed in Euler's method [xe1,ye1] = euler(@myfunc,0,3,5,10); % Let's plot xe1 vs ye1 plot(xe1,ye1); % Now we will try 100 steps in Euler's method % So n = 100 % The results are in variables xe2 and ye2 [xe2,ye2] = euler(@myfunc,0,3,5,100); % Let's plot this on a separate figure figure(2); plot(xe2,ye2); % Now let us try to use MATLAB's built in function ode45 % Type "help ode45" for more information % We are interested in solving the ODE over % the interval [0 5] % Also y0 = 3 xspan = [0 5]; yzero = 3; [xm,ym] = ode45(@myfunc,xspan,yzero); figure(3); plot(xm,ym); % Print out the plots and exit MATLAB exit