@Spancymath
2016-06-23T08:14:15.000000Z
字数 988
阅读 747
数值解
求解一维抛物方程的初边值问题:
clcclearxb = [0, pi]; %boundary of xm = input('input the grid number of x:');n = input('input the grid number of t:');h = (xb(2)-xb(1))/m; %step value of xk = 1/n; %step value of timer = k/h^2; %ratio of gridu = zeros(n+1, m+1); % the value of every gridx = h*((1:m+1)-1);u(1, :) = sin(x); %initialu(:, 1) = 0; %boundary conditionu(:, end) = 0;%A = zeros(m-2, 3); %the coefficient matrix of equationd = zeros(1, m-1);g = zeros(1, m-1);w = zeros(1, m-1);alpha = r/2;beta = 1+r;gamma = r/2;for N = 2:n+1for M = 2:mite = M-1;d(ite) = r/2*(u(N-1, M-1)+u(N-1, M+1))+(1-r)*u(N-1, M);if ite==1 %zhuig(1) = d(1)/beta;w(1) = gamma/beta;elseg(ite) = (d(ite)+alpha*g(ite-1))/(beta-alpha*w(ite-1));w(ite) = gamma/(beta-alpha*w(ite-1));endendfor M = m:-1:2 %ganite = M-1;if M==mu(N, M) = g(ite);elseu(N, M) = g(ite)+w(ite)*u(N, M+1);endendendX = xb(1):h:xb(2);T = 0:k:n*k;[X, T] = meshgrid(X, T);surf(X, T, u);