# Using Chebyshev Differentiation Matrix to solve ODE

Trying to solve

dy/dx = 2xy, y(1) = 1,


using Chebyshev differentiation matrix

The exact solution is y = exp(x.^2 -1);

Heres what I have:

% compute the chebyshev differentiation matrix and x-grid

[D1,x] = cheb(N);


% boundary condition (I don't know if this is correct?)

D1 = D1(1:end-1,1:end-1); x = x(1:end-1);


% compute the derivatives at x (i.e. at the chebyshev grid points)

f = 2*x.*ones(size(x));


% solve

u = D1\f;


% set the boundary condition

u = [u;1];


Where cheb.m is from Trefethen (spectral methods in matlab)

function [D,x] = cheb(N)

% check the base case
if N == 0; D = 0; x = 1; return; end

% create the Chebyshev grid
x = cos(pi*(0:N)/N)';

c = [2; ones(N-1,1);2].*(-1).^(0:N)';
X = repmat(x,1,N+1);
dX = X-X';
D = (c*(1./c)')./(dX+(eye(N+1)));
D = D - diag(sum(D'));


This solution (u = D1\f) does not match the exact solution at all.

I think what I have is close to a solution. I'm not quite sure what's wrong with this solution

-
Are you asking for math help or for programming help? – Pragabhava Oct 17 '12 at 21:31
math help ... hence the post on math.stackexchange rather than stackoverflow ... – brown.2179 Oct 18 '12 at 13:26
Why all the code then? – Pragabhava Oct 18 '12 at 14:55
b/c that the solution to the problem. If you don't have anything helpful please refrain from further comments. Thanks. – brown.2179 Oct 18 '12 at 15:48
Here's something helpful (because you can't read between lines). People here know about mathematics, not matlab. If you phrase your question in matlab code, not only you are excluding people who can't (or won't) read it, you're implicitly asking us to debug it. There are two reasons this question hasn't been voted down: not enough atention (poorly written) and a good hearted community. – Pragabhava Oct 18 '12 at 19:56