Code covered by the BSD License  

Highlights from
First-order stiff ordinary differential equation solver

from First-order stiff ordinary differential equation solver by Ali Dinler
Runs 20 implicit and semi-implicit methods for first-order initial value stiff ODEs.

example.m
%---------------------------------------------------------%                   
% Example
%---------------------------------------------------------%
clear; close; clc;

x0=0;
y0=0;
xn=1;
h=0.01; %step-size

[RKa,RKb,RKc,RKns,RKord,RKtype,RKname]=implicit_setmethod('SDIRK3');
[Y]=implicit_solver('f1',x0,y0,xn,h,RKa,RKb,RKc,RKns);

M=(xn-x0)/h;
xx = x0:h:xn;
Ye(1)=y0;
Yerr(1)=0;
for i=1:M
%exact solution    
Ye(i+1)=-exp(-50*xx(i+1))+cos(xx(i+1))+0.02*sin(xx(i+1));
Yerr(i+1)=abs(Ye(i+1)-Y(i+1));
end

%plot solution
figure(1)
p = plot(xx,Y,xx,Ye);
legend(p,'SDIRK3','exact sol');
xlabel('x');
ylabel('y(x)');
title('SDIRK3 vs. exact solution')
grid on;

%L_inf error
err=norm(Yerr,inf)

%plot Error
figure(2)
plot(xx,Yerr);
title('SDIRK3 method error graphic');
xlabel('x');
ylabel('Error');
grid on;

Contact us at files@mathworks.com