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.

OrrSomCHEBFUN.m
% OrrSomCHEBFUN.m - An executable M-file file for solving an eigenvalue problem.
% Automatically created from chebfun/chebgui by user Dami
% at 17:52:24 on 24-May-2013.

% Solving
%   (u""-2*u"+u)/5772-2i*u-1i*(1-x^2)*(u"-u)=lambda*(u"-u),
% for x in [-1 1], subject to
%   u(-1) = 0,
%   u'(-1) = 0,
%   u(1) = 0,
%   u'(1) = 0.
% Define the domain we're working on.
dom = [-1 1];tic;

% Assign the equation to two chebops N and B such that N(u) = lambda*B(u).
N = chebop(@(x,u) (diff(u,4)-2.*diff(u,2)+u)./5772-2i.*u-1i.*(1-x.^2).*(diff(u,2)-u),dom);
B = chebop(@(x,u) diff(u,2)-u,dom);

% Assign boundary conditions to the chebop.
N.bc = @(x,u) [u(-1),feval(diff(u),-1),u(1),feval(diff(u),1)];

% Number of eigenvalue and eigenmodes to compute.
k = 60;

% Solve the eigenvalue problem.
[V D] = eigs(N,B,k);

% Plot the eigenvalues.
D = diag(D);toc;
figure
plot(real(D),imag(D),'.','markersize',25)
title('Eigenvalues'); xlabel('real'); ylabel('imag');

% Plot the eigenmodes.
figure
plot(real(V),'linewidth',2);
title('Eigenmodes'); xlabel('x'); ylabel('u');

Contact us