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 . La formule mathématique, il est indiqué ci-dessus: Script 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:
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:
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.
vous avez oublié d'évaluer invhom à t0 dans la ligne 'c_0 = invhom * x_0' – gustavoreche
@gustavoreche Bonne prise! Réponse mise à jour – TroyHaskin