Code covered by the BSD License  

Highlights from
Chebpack

image thumbnail

Chebpack

by

 

15 Jul 2011 (Updated )

The MATLAB package Chebpack solves specific problems for differential or integral equations.

[t,err]=quad_ex1
function [t,err]=quad_ex1
% Calculates int_0^1(x*sin(1/x))dx for n = 10,10^2,..,10^6
Iex=.37853001712416130988;
err=[];dom=[0 1];kind=1;t=[];
for n = logspace(1,6,6);
tic;[x,w] = pd(n,dom,kind);
f=x.*sin(1./x);
I = w*f;t=[t,toc];
err = [err abs(I-Iex)];
end
xx=logspace(1,6,6);
[haxes,hline1,hline2] = plotyy(xx,err,xx,t,'loglog','loglog');
axes(haxes(1));ylabel('error');
axes(haxes(2));ylabel('elapsed time (sec)');
set(hline1,'LineStyle','-','Marker','.');
set(hline2,'LineStyle','--','Marker','.');
title('\int_0^1 x*sin(1/x) dx');legend('elapsed time','error');xlabel('N');
display([t' err']);

Contact us