Spaces:
Sleeping
Sleeping
File size: 2,365 Bytes
3d893c2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | // Scicos
//
// Copyright (C) INRIA - Author : EADS-CCR
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// See the file ../license.txt
//
function M=Disc_diff_oper45(N,h,DF_type)
// Cette fonction construit l'ecriture de la discretisation de l'operateur d2u/dtdx //
// ou de l'operateur du/dx sous forme matricielle. //
// sortie : //
// - M (Double) : est la matrice elementaire de discretisation de l'operateur //
// entrees : //
// - N (Entier) : est le nombre de noeuds //
// - h (Double) : est le pas de discretisation h= (b-a)/N (i.e x(i)= i* h) //
// - DF_type (Entier) : 0 pour les differences finies centrees, 1 pour les //
// decentrees a gauche et 2 pour les decentrees � droite //
//----------------------------------------------------------------------------------//
if ( DF_type == 0) then
// cas centr�e :
Mij=[[(1:N-1) (2:N)]',[(2:N) (1:N-1)]'];
Mmn=[N, N];
Mval=[(1/(2*h))*ones(N-1,1); (-1/(2*h))*ones(N-1,1)];
M=sparse(Mij, Mval, Mmn);
elseif ( DF_type == 1 | DF_type == 2) then
// les cas d�centr�e
Mij=[[(1:N) (2:N)]',[(1:N) (1:N-1)]'];
Mmn=[N, N];
Mval=[(1/h)*ones(N,1); (-1/h)*ones(N-1,1)];
M=sparse(Mij, Mval, Mmn);
if ( DF_type == 2) then
M=-M';
end
end
endfunction
|