IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MATLAB Discussion :

Résolution d'équations linéaires et oscillateur stationnaire


Sujet :

MATLAB

  1. #1
    Nouveau membre du Club
    Inscrit en
    Décembre 2009
    Messages
    117
    Détails du profil
    Informations forums :
    Inscription : Décembre 2009
    Messages : 117
    Points : 30
    Points
    30
    Par défaut Résolution d'équations linéaires et oscillateur stationnaire
    Bonjour,

    voila les deux codes l'un pour la méthode itérative et l'autre pour la corde(j'ai arrivé à faire un programme pour un pendule animée mais je sais plus comment faire pour un corde animée tel que un oscillateur stationnaire ) ,est ce que c'est juste ..

    pour l'equation différentielle,j'ai pas une idée

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
     
    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
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    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
    Merci

  2. #2
    Expert confirmé
    Avatar de duf42
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Novembre 2007
    Messages
    3 111
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2007
    Messages : 3 111
    Points : 4 661
    Points
    4 661
    Par défaut
    Bonjour,

    Quelle est ta question exactement? C'est plutôt à toi de nous dire si ton code fonctionne et sinon quels sont les problèmes pour que l'on puisse t'aider à les résoudre...

    Bonne journée,
    Duf

Discussions similaires

  1. problème de résolution des équations linéaires
    Par HI9IMOMO dans le forum Débuter
    Réponses: 2
    Dernier message: 22/11/2012, 15h35
  2. Résolution d'équation non linéaire
    Par Squallo dans le forum MATLAB
    Réponses: 15
    Dernier message: 15/01/2009, 13h16
  3. Résolution de systèmes d'équations linéaires
    Par Eric06 dans le forum MATLAB
    Réponses: 3
    Dernier message: 14/06/2008, 17h19
  4. Résolution d'équation non-linéaire
    Par progmatho dans le forum Simulink
    Réponses: 1
    Dernier message: 20/02/2008, 11h26

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo