Forum de mathématiques - Bibm@th.net
Vous n'êtes pas identifié(e).
- Contributions : Récentes | Sans réponse
Pages : 1
#1 04-02-2010 23:33:09
- stormin
- Membre
- Inscription : 03-12-2009
- Messages : 124
programme en matlab
Salut tous le monde;
je cherche des programme en MATLAB de :
1__La résolution de cette équations différentielles,d²y/dx² +2 dy/dx +y=0.
2__Résolution d'un système d'équations linéaires ax=b avec une méthode itérative.
3__ le programme de la corde animée
merci d'avance
Hors ligne
#5 07-02-2010 18:58:04
- stormin
- Membre
- Inscription : 03-12-2009
- Messages : 124
Re : programme en matlab
voila les deux codes l'un pour la méthode itérative et l'autre pour la corde ,est ce que c'est juste
function [x, error, total_iters, it_hist] = ...
pcgsol(x0, b, atv, params, pcv)
% Preconditioned Conjugate-Gradient solver
%
% C. T. Kelley, December 12, 1993
%
% This code comes with no guarantee or warranty of any kind.
%
% function [x, error, total_iters, it_hist]
% = pcgsol(x0, b, atv, params, pcv)
%
%
% Input: x0=initial iterate
% b=right hand side
% atv, a matrix-vector product routine
% atv must return Ax when x is input
% the format for atv is
% function ax = atv(x)
% params = two dimensional vector to control iteration
% params(1) = relative residual reduction factor
% params(2) = max number of iterations
% pcv, a routine to apply the preconditioner
% if omitted, the identity is used.
% The format for pcv is
% function px = pcv(x).
%
% Output: x=solution
% error = vector of iteration residual norms
% total_iters = number of iterations
% it_hist (optional) = matrix of all iterations
% useful for movies
%
%
%
%
% initialization
%
if nargout == 4 it_hist=[]; end
n=length(b); errtol = params(1); maxiters = params(2); error=[]; x=x0;
if nargout == 4; it_hist=[it_hist, x]; end
r=b - feval(atv, x);
if nargin == 4
z=r;
else
z = feval(pcv, r);
end
rho=z'*r;
tst=norm(r);
terminate=errtol*norm(b);
error=[error,tst];
it=1;
while((tst > terminate) & (it <= maxiters))
%
%
%
if(it==1)
p = z;
else
beta=rho/rhoold;
p = z + beta*p;
%
% end if
%
end
w = feval(atv, p);
alpha=p'*w;
%
% Test here to make sure the linear transformation is positive definite.
% A non-positive value of alpha is a very bad sign.
%
if(alpha <= 0)
[alpha, rho, it]
error(' negative curvature ')
end
alpha=rho/alpha;
x=x+alpha*p;
if nargout == 4; it_hist=[it_hist, x]; end
r = r - alpha*w;
tst=norm(r);
rhoold=rho;
if nargin == 4
z=r;
else
z = feval(pcv, r);
end
rho=z'*r;
it=it+1;
error=[error,tst];
%
% end while
%
total_iters=it-1;
end
clc
t=0:0.01:2;
theta1=0.1*cos(sqrt(9.82/1)*t);
y=1-1*cos(theta1);
x=1*sin(theta1);
for i=1:length(t)
cla
hold on
plot([0 0],[-0.2 1],'b--')
fill([-0.1 -0.1 0.1 0.1],[1 1.1 1.1 1],[.8 .8 .8])
fill([0 x(i)],[1 y(i)],[0.8 0.8 0.8])
plot(x(i),y(i),'r.','MarkerSize',45)
axis([-0.5 0.5 -0.2 1.2]);
pause(0.01)
end
Hors ligne
#6 09-02-2010 08:21:57
- yoshi
- Modo Ferox
- Inscription : 20-11-2005
- Messages : 17 385
Re : programme en matlab
Re,
Je ne suis pas compétent, mais là tu trouveras de l'aide sur matlab :
http://www.developpez.net/forums/f148/e … nt/matlab/
La prochaine fois, poste dans la section programmation. Merci.
@+
Hors ligne
Pages : 1







