Error using eval with a differential equation

조회 수: 6 (최근 30일)
jose luis guillan suarez
jose luis guillan suarez 2018년 5월 19일
댓글: Walter Roberson 2018년 5월 21일
when i do this i get this error:
>> t=0:0.01:10;
>> dsolve('D3x + 6*D2x + 11*Dx + 6*x=6*square(2*pi*t),D2x(0)=0,Dx(0)=0,x(0)=0')
ans =
exp(-t)*int(3*exp(x)*square(2*pi*x), x, 0, t, 'IgnoreSpecialCases', true, 'IgnoreAnalyticConstraints', true) + exp(-3*t)*int(3*exp(3*x)*square(2*pi*x), x, 0, t, 'IgnoreSpecialCases', true, 'IgnoreAnalyticConstraints', true) + exp(-2*t)*int(-6*exp(2*x)*square(2*pi*x), x, 0, t, 'IgnoreSpecialCases', true, 'IgnoreAnalyticConstraints', true)
>> y=eval(vectorize(ans))
Error using eval
Undefined function or variable 'x'.
what's happening? (i suppose is the square function because if i substitute it for sin(t) it works right.
  댓글 수: 1
Stephen23
Stephen23 2018년 5월 19일
편집: Stephen23 2018년 5월 20일
What do you hope to obtain by evaluating the output of dsolve? eval is not the right tool to use:
Is there a reason why you are using the very outdated char input to dsolve ?

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

답변 (2개)

Walter Roberson
Walter Roberson 2018년 5월 20일
Never eval() a symbolic expression. Symbolic expressions are not in the MATLAB language, just in something that is close to the MATLAB language.
But more immediately you need to
syms x
  댓글 수: 5
jose luis guillan suarez
jose luis guillan suarez 2018년 5월 20일
and how i plot the equation?
Walter Roberson
Walter Roberson 2018년 5월 21일
This is difficult to solve analytically, probably because the differentiation is not all that well defined right at the boundary conditions.
But you can get "good enough" this way:
syms t
Square(t) = piecewise(t - floor(t) < 1/2, 1, -1)
sol_plus = dsolve('D3x + 6*D2x + 11*Dx + 6*x=6*1,D2x(0)=0,Dx(0)=0,x(0)=0');
sol = Square(t) * sol_plus;
This works because solving for =6*-1 gives the negative of sol_plus.
Once you have the above you can plot with
T = 0:0.01:10;
solt = double( subs(sol, t, T) );
plot(T, solt);

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


jose luis guillan suarez
jose luis guillan suarez 2018년 5월 20일
i'm using R2017a

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by