How to solve 2nd order BVP using Chebyshev Spectral Method?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I am tring to solve the following BVP using Chebshev Spectral Method:
with boundary conditions:
The code is given by for Linear BVP
% p33.m - solve linear BVP u_xx = exp(4x), u'(-1)=u(1)=0
N = 16;
[D,x] = cheb(N); D2 = D^2;
D2(N+1,:) = D(N+1,:); % Neumann condition at x = -1
D2 = D2(2:N+1,2:N+1);
f = exp(4*x(2:N));
u = D2\[f;0];
u = [0;u];
clf, subplot('position',[.1 .4 .8 .5])
plot(x,u,'.','markersize',16)
axis([-1 1 -4 0])
xx = -1:.01:1;
uu = polyval(polyfit(x,u,N),xx);
line(xx,uu)
grid on
exact = (exp(4*xx) - 4*exp(-4)*(xx-1) - exp(4))/16;
title(['max err = ' num2str(norm(uu-exact,inf))],'fontsize',12)
where cheb was defined as:
% CHEB compute D = differentiation matrix, x = Chebyshev grid
function [D,x] = cheb(N)
if N==0, D=0; x=1; return, end
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))); % off-diagonal entries
D = D - diag(sum(D')); % diagonal entries
I want to modify the the code according to the BVP defined earlier. Please help me to sort out this problem.
Thanks
2 commentaires
Torsten
le 27 Mar 2023
You are forced to use this special solution method ? Or are you also free to use bvp4c or bvp5c ?
Réponses (1)
Torsten
le 27 Mar 2023
alpha = 0.1;
xmesh = linspace(0,1,50);
solinit = bvpinit(xmesh, [0 0]);
bvpfcn = @(x,y)[y(2);0.75/(1+6*alpha*y(2)^2)];
bcfcn = @(ya,yb)[ya(2);yb(1)];
sol = bvp4c(bvpfcn, bcfcn, solinit);
plot(sol.x, sol.y, '-o')
grid on
2 commentaires
Voir également
Catégories
En savoir plus sur Boundary Value Problems dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!