Errors while trying to solve a simple differential equation
조회 수: 1 (최근 30일)
이전 댓글 표시
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});
댓글 수: 0
답변 (1개)
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
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 Center 및 File Exchange에서 Equation Solving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!