Trying to understand the implementation of boundary conditions in this MATLAB code
댓글 수: 9
Hi Janee,
Try to modify the differentiation matrix calculation within the Cheb function, (Reason: The Cheb function you are using is setting the values of u(x, y) to zero instead). I just made the modification in your Cheb function, here is revised version,
function [D, x] = cheb(N)
if (N == 0) D = 0.0; x = 1.0; return end
x = cos(pi * (0:N) / N)'; c = [2.0; ones(N-1, 1); 2.0] .* (-1.0).^(0:N)'; X = repmat(x, 1, N + 1); dX = X - X';
% Set the off-diagonal entries. D = (c * (1.0 ./ c)') ./ (dX + eye(N + 1));
% Modify diagonal entries for enforcing boundary conditions on first derivative.
D(1, :) = zeros(1, N + 1); D(N + 1, :) = zeros(1, N + 1);
% Update diagonal entries.
D = D - diag(sum(D'));
return end
By incorporating modification of diagonal entries for enforcing boundary conditions on first derivative into your Cheb function, you can make sure that the values of the first derivative at +/-1 are correctly set to zero as intended. This modification will help you enforce the appropriate boundary conditions for the first derivative in your numerical solution code.Hope, now all your issues have been resolved. Please let me know if you have any further questions.
답변 (0개)
참고 항목
카테고리
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!