Effacer les filtres
Effacer les filtres

Errors while trying to solve a simple differential equation

1 vue (au cours des 30 derniers jours)
naygarp
naygarp le 19 Oct 2017
Commenté : Walter Roberson le 19 Oct 2017
Why am I getting all these errors while solving this simple differential equation?
syms y t a b
eqn = diff(y,t,2) == a^2*y;
Dy = diff(y,t);
cond = [y(0)==b, Dy(0)==1];
ySol(t) = dsolve(eqn,cond)
??? Error using ==> sym.sym>checkindex at 2590
Index must be a positive integer or logical.
Error in ==> sym.sym>privformatscalar at 2540
checkindex(x);
Error in ==> sym.sym>privformat at 2524
s = privformatscalar(x);
Error in ==> sym.sym>sym.subsref at 1364
[inds{k},refs{k}] = privformat(inds{k});

Réponses (1)

Walter Roberson
Walter Roberson le 19 Oct 2017
You need
syms y(t)
You are currently just using y so MATLAB do not know that it is a function and thinks it is a constant. Constant differentiated gives 0
  2 commentaires
naygarp
naygarp le 19 Oct 2017
Modifié(e) : Walter Roberson le 19 Oct 2017
I previously tried going with 'syms y(t)' but it shows that the format is not recognized.
syms y(t) a b
eqn = diff(y,t,2) == a^2*y;
Dy = diff(y,t);
cond = [y(0)==b, Dy(0)==1];
ySol(t) = dsolve(eqn,cond)
??? Error using ==> syms at 61
Not a valid variable name.
Walter Roberson
Walter Roberson le 19 Oct 2017
You must be using a older version of MATLAB. Try
syms a b t
y = sym('y(t)');
y0 = subs(y,t,0);
Dy = diff(y,t);
Dy0 = subs(Dy, t, 0);
D2y = diff(Dy,t);
eqn = D2y == a^2*y;
cond = [y0 == b, Dy0 == 1];
ySol = dsolve(eqn, cond(1), cond(2))

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by