Code for boundary value problem
1 次查看(过去 30 天)
显示 更早的评论
I'm trying to answer this question:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150131/image.jpeg)
This is the code I have produced:
function [x,y] = bvp(coeff, bcs, xspan, h)
N = (xspan(2)-xspan(1))/(h);
x = xspan(1):h:xspan(2);
main = [ones(N-1,1).*(coeff(3)*h^2-2*coeff(1))];
sub = ones(N-2,1).*(coeff(1)-coeff(2)*h/2);
super = ones(N-2,1).*(coeff(1)+coeff(2)*h/2);
A = (diag(main) + diag(sub,-1) + diag(super,1));
B = [(-(coeff(1)-coeff(2)*h/2)*bcs(1));zeros(N-3,1);-(coeff(1)+coeff(2)*h/2)*bcs(2)];
y = A\B;
y = [bcs(1); y; bcs(2)];
end
I'm not sure why this is not working. Any help would be appreciated.
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Boundary Conditions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!