Errors while trying to solve a simple differential equation

조회 수: 1 (최근 30일)
naygarp
naygarp 2017년 10월 19일
댓글: Walter Roberson 2017년 10월 19일
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});

답변 (1개)

Walter Roberson
Walter Roberson 2017년 10월 19일
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
naygarp
naygarp 2017년 10월 19일
편집: Walter Roberson 2017년 10월 19일
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 2017년 10월 19일
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))

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Equation Solving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by