2016-03-27 3 views
0

cette question concerne à la fois la programmation et les mathématiques. Donc, j'essaie d'écrire un code qui calcule la solution générale d'un système d'ODE linéaires décrit par system. La formule mathématique, il est indiqué ci-dessus: general solutionScript simple qui calcule une solution d'ODE linéaires donnant un résultat erroné

où le symbole grec \ PHI qui appers dans l'équation est la expm(A*t)

clear all 

A=[-2]; %system matrix 

t0=1; %initial time of simulation 

tf=2; %final time of simulation 

syms t x_0 

x0=x_0; 

hom=expm(A*t); %hom means "homogeneous solution" 

hom_initialcond=hom*x0;%this is the homogeneous solution multiplied by the initial conditon 

invhom=inv(hom); %this is the inverse of the greek letter at which, multiplied by the input of the system, composes the integrand of the integral 

g=5*cos(2*t); %system input 

integrand=invhom*g; %computation of the integrand 

integral=int(integrand,t0,t); %computation of the definite integral from t0 to t, as shown by the math formula 

partsol=hom*integral; %this is the particular solution 

gen_sol=partsol+hom_initialcond %this is the general solution 

x_0=1; %this is the initial condition 

t=linspace(t0,tf); %vector of time from t0 to tf 

y=double(subs(gen_sol)); %here I am evaluating my symbolic expression 

plot(t,y) 

Le problème est que ma parcelle de la solution de l'ODE, il ne cherche pas bien, comme vous peut voir: plot

la solution, il est faux parce que la courbe représentée sur le graphique ne commence pas à la valeur initiale est égale à 1. Mais la forme, il est très similaire de l'intrigue donné par le solveur ODE Matlab: enter image description here

Cependant, si je mets t0=0 alors le complot a donné mon code et par solveur Matlab il est exacly égal à l'autre. Donc, mon code c'est bien pour t0=0 mais avec toutes les autres valeurs mon code ne va pas.

Répondre

3

La solution générale en termes de matrices fondamentales est

Equation giving the solution of an ODE system with an arbitrary initial condition vector

ou plus souvent vu comme

Equation giving the solution of an ODE system with an initial condition vector for linear, constant coefficient problems

Mais depuis le temps initial est souvent considéré comme nul, l'inverse de la matrice fondamentale est souvent omise car c'est l'identité des problèmes de coefficients constants linéaires à zéro (c.-à-d. expm(zeros(n)) == eye(n)) et le vecteur c est équivalent à t Le vecteur de condition initiale.

Permutation quelques-unes des lignes autour de votre déclaration près symbolique à cette

syms t x_0 c_0 
hom    = expm(A*t)    ; 
invhom   = inv(hom)     ; 
invhom_0  = subs(invhom,t,sym(t0)) ; 
c_0    = invhom_0 * x_0   ; 
hom_initialcond = hom * c_0    ; 

devrait fournir la bonne solution pour le temps initial non nul.

+0

vous avez oublié d'évaluer invhom à t0 dans la ligne 'c_0 = invhom * x_0' – gustavoreche

+0

@gustavoreche Bonne prise! Réponse mise à jour – TroyHaskin