Errors while trying to solve a simple differential equation

1 visualizzazione (ultimi 30 giorni)
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});

Risposte (1)

Walter Roberson
Walter Roberson il 19 Ott 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 Commenti
naygarp
naygarp il 19 Ott 2017
Modificato: Walter Roberson il 19 Ott 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 il 19 Ott 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))

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by