Code covered by the BSD License

# Chebpack

### Damian Trif (view profile)

15 Jul 2011 (Updated )

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

eig42CHEBFUN.m
```% eig42CHEBFUN.m - An executable M-file file for solving an eigenvalue problem.
% Automatically created from chebfun/chebgui by user Dami
% at 12:39:37 on 29-May-2013.

% Solving
%   u""=lambda*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),dom);
B = chebop(@(x,u) diff(u,2),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);toc;

% Plot the eigenvalues.
D = diag(D);
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');
```