Programming error with a model function
Afficher commentaires plus anciens
I don't understand why but I'm getting an error message regarding my Matlab script:
I'm trying to code for the example equation
y′1=y′2
y2=A/Bty1.
tspan = [0 5];
y0 = [0 0.1];
A = 1;
B = 2;
[t,yAB] = ode15s(@fun40,tspan,y0);
figure
semilog(t,y)
grid
function dyAB = fun40(t,yAB)
dyAB = zeros(2,1);
dyA(1) = dyB(2);
dyB(2) = (A/B)*t.*dyA(1);
end
Réponse acceptée
Plus de réponses (1)
tspan = [0 5];
y0 = [0 0.1];
A = 1;
B = 2;
[t,yAB] = ode15s(@(t,y)fun40(t,y,A,B),tspan,y0);
figure
plot(t,yAB)
grid
ylim([-0.01 0.11])
function dyAB = fun40(t,yAB,A,B)
dyAB = zeros(2,1);
dyA(1) = yAB(2);
dyB(2) = (A/B)*t.*yAB(1);
end
1 commentaire
syms A B positive
syms y1(t) y2(t)
dy1 = diff(y1);
dy2 = diff(y2);
eqn1 = dy1 == dy2
eqn2 = y2 == A/B * t * y1
sol = dsolve([eqn1, eqn2])
However, if the derivatives of the two functions are equal then the two functions differ only by a constant, and so you can substitute into
syms C
y1 = y2 + C
eqn3 = y2 == A/B * t * y1
sol = isolate(eqn3, y2)
y2 = rhs(sol)
y1 = simplify(y2 + C)
simplify(diff(y1) - diff(y2))
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


