To solve ODE below with matlab
t = 0:.01:20;
x0 = [0 0]';
xdot = @(t,x) [0 1; 0 0] * x;
ode45(@(t,x) xdot(x(1), x(2)),t,x0)
I get this error:
Error using odearguments (line 91) @(T,X)XDOT(X(1),X(2)) must return a column vector.
Cloud anyone help me to solve solve 2nd order ODEs using only anonymous function definition?

 채택된 답변

Star Strider
Star Strider 2019년 5월 26일

1 개 추천

You are not calling ‘xdot’ correctly in your ode45 call.
Try this:
t = 0:.01:20;
x0 = [0 0]' + eps;
xdot = @(t,x) [0 1; 0 0] * x;
[T,X] = ode45(xdot,t,x0)
figure
plot(T, X)
grid
Also, the result is uniformly zero, so to prevent that, I added eps to ‘x0’.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2019년 5월 26일

답변:

2019년 5월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by