- #1
Theaumasch
- 25
- 0
Hi,
I'm having trouble with a programming problem for my numerical mathematics course. It's about the one-dimensional advection-diffusion equation
a*u'(x)-epsilon*u"(x) = 1, on the interval -1 < x < 1. The boundary values are: u(-1) = u_r, u(1) = u(l)
I have to approximate the solution in MATLAB using Chebyshev polynomials.
As is stated here , u and its first and second derivatives can be expanded in Chebyshev polynomials, I have implemented the calculation of the two D-matrices like this:
c = ones(1,N+1);
c(1) = 2;
DOne = zeros(N-1,N+1);
DTwo = zeros(N-1,N+1);
for n=0:1:N-2
for k=n+1:2:N
DOne(n+1,k+1) = 2*k/c(n+1);
end
end
for n=0:1:N-2
for k=n+2:2:N
DTwo(n+1,k+1) = (k)*((k)^2-(n)^2)/c(n+1);
end
end
Together with the two boundary conditions, I have N+1 equations in N+1 unknowns. The rest of the script was already written in advance by the lecturer, but my numerical result doesn't match the exact result at all (it seems to be random noise). The remaining part of the script does this:
- D = a*DOne-epsilon*DTwo;
- Generate a matrix A, which has the N-1 component equations and 2 boundary value equations as it's rows.
- Au = f => u = A\f. u is the numerical solution, the component of the vector f[n] is 1 for n = 0 and equal to 0 for n=1 up to and including n=N-2. f[N-1] = u_l and f[N] = u_r
- Both the exact and numerical solution are plotted.
I assume I did something wrong in the loops, but I just don't see it. Any help would be appreciated. Thanks in advance!
I'm having trouble with a programming problem for my numerical mathematics course. It's about the one-dimensional advection-diffusion equation
a*u'(x)-epsilon*u"(x) = 1, on the interval -1 < x < 1. The boundary values are: u(-1) = u_r, u(1) = u(l)
I have to approximate the solution in MATLAB using Chebyshev polynomials.
As is stated here , u and its first and second derivatives can be expanded in Chebyshev polynomials, I have implemented the calculation of the two D-matrices like this:
c = ones(1,N+1);
c(1) = 2;
DOne = zeros(N-1,N+1);
DTwo = zeros(N-1,N+1);
for n=0:1:N-2
for k=n+1:2:N
DOne(n+1,k+1) = 2*k/c(n+1);
end
end
for n=0:1:N-2
for k=n+2:2:N
DTwo(n+1,k+1) = (k)*((k)^2-(n)^2)/c(n+1);
end
end
Together with the two boundary conditions, I have N+1 equations in N+1 unknowns. The rest of the script was already written in advance by the lecturer, but my numerical result doesn't match the exact result at all (it seems to be random noise). The remaining part of the script does this:
- D = a*DOne-epsilon*DTwo;
- Generate a matrix A, which has the N-1 component equations and 2 boundary value equations as it's rows.
- Au = f => u = A\f. u is the numerical solution, the component of the vector f[n] is 1 for n = 0 and equal to 0 for n=1 up to and including n=N-2. f[N-1] = u_l and f[N] = u_r
- Both the exact and numerical solution are plotted.
I assume I did something wrong in the loops, but I just don't see it. Any help would be appreciated. Thanks in advance!