Created
January 9, 2018 03:53
-
-
Save pureexe/7fea7fcd3395df1bb0de14b99abff808 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function [result,t] = fdm(a,b,h,alpha,beta,p,q,r) | |
| t = a+h:h:b-h; | |
| n = length(t); | |
| forward = @(t) 1 + (p(t).*(h./2)); | |
| center = @(t) q(t).*(h.^2) - 2; | |
| backward = @(t) 1 - (p(t).*(h./2)); | |
| right = @(t) r(t).*(h.^2); | |
| A = spdiags([forward(t).',center(t).',backward(t).'],[-1,0,1],n,n); | |
| F = right(t).'; | |
| F(1) = F(1) - alpha; | |
| F(n) = F(n) - beta; | |
| result = A \ F; | |
| result = [alpha;result;beta]; | |
| t = [a,t,b]; | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment