echo off;
% NUMERICAL METHODS by John H. Mathews
% Algorithm 9.1 (Euler's Method).
% Section  9.2,  Euler's Method, Page 435
% PRENTICE HALL, INC. © 1992
echo on; clc; format long; hold off; clear

% This program implements Euler's method

% for solving the initial value problem

%     y' = f(t,y)    with    y(a) = y0

% Define and store the function f(t,y)  in the M-file  f.m
% function z = f(t,y)
% z = (t-y)/2;

delete f.m
diary f.m; disp('function z = f(t,y)');...
           disp('z = (t-y)/2;');...
diary off;

f(0,0); % Remark. f.m and meuler.m are used for Algorithm 9.1
%pause   % Press any key to continue.

%clc;
%  Place the endpoints of [a,b] in  a  and  b.

%  Place the initial value y(a) in  ya.

%  Place the number of subintervals in  m.

a  = 0;
b  = 3;
ya = 1;
m  = 6;

[T,Y] = meuler('f',a,b,ya,m);
points = [T;Y];

%pause  % Press any key to see the list of solution points.

%clc;, clg;
%c = 0;
%d = 1.75;
%axis([a b c d]);...
plot(T,Y,'-g');...
hold on;...
%plot([a b],[0 0],'b',[0 0],[c d],'b');...
if m<=30,
  plot(T,Y,'or');
end;...
xlabel('t');...
ylabel('y');...
title('Euler`s solution to y` = f(t,y)');...
grid;...
axis;...
%hold off;...
%shg; pause  % Press any key to continue.

Mx1 = 'Euler`s solution to y` = f(t,y).';
Mx2 = '     t(k)               y(k)';
clc,echo off
diary output,...
disp(''),disp(Mx1),...
disp(''),disp(Mx2),disp(points'),diary off,echo on


%%pause  % Press any key to see the list of solution points.

%hold on
%plot(T,Y,'-r');...

%hold off;...
%shg; 
%pause  % Press any key to continue.

%Mx1 = 'Euler`s solution to y` = f(t,y).';
%Mx2 = '     t(k)               y(k)';
'm=',m
%clc,echo off,
diary output,...
%disp(''),disp(Mx1),...
%disp(''),disp(Mx2),disp(points'),diary off,echo on


% muutetaan jakov{lien lukum{{r{ kaksinkertaiseksi

makro1='m=2*m;[T,Y]=meuler(''f'',a,b,ya,m);plot(T,Y,''-r'');[T'',Y''];';
makro2='if m<=30, plot(T,Y,''ow'');end;'
m=2*m;[T,Y]=meuler('f',a,b,ya,m);plot(T,Y,'-r');[T',Y'];
if m<=30, plot(T,Y,'ow');end;

disp(makro1)
disp(makro2)

pause % Toista kahta viimeista komentoa nuolinappaimella (voit muutella
      % m:n arvoja muutenkin kuin 2:lla kertomalla).

