I don't know why my code makes odeToVectorField error

조회 수: 2 (최근 30일)
Student
Student 2023년 9월 19일
편집: Sam Chak 2023년 9월 19일
syms x(t)
m = 1;
k = 1;
F = 1;
fs = 1;
fk = 1;
[K,E] = ellipke((x / pi-floor(x/pi))*pi);
s = sqrt(2) * E + ( 2 * ellipke(1/2) * floor(x / pi));
r = abs(((cos(x))^2+1)^1.5/sin(x))
r(t) = 
Ds = diff(s, t)
Ds(t) = 
D2s = diff(s, t, 2)
D2s(t) = 
dnjstlafur = 0.5 * (((m * Ds^2) / r) + abs(((m * Ds^2) / r - fs) - fs));
ode = m * D2s == sqrt(F^2 - dnjstlafur^2)
ode(t) = 
[V] = odeToVectorField(ode)
Error using symengine
Invalid argument.

Error in mupadengine/evalin_internal

Error in mupadengine/fevalHelper

Error in mupadengine/feval_internal

Error in odeToVectorField>mupadOdeToVectorField (line 171)
T = feval_internal(symengine,'symobj::odeToVectorField',sys,x,stringInput);

Error in odeToVectorField (line 119)
sol = mupadOdeToVectorField(varargin);
M = matlabFunction(V, 'vars', {'t', 'Y'});
a = 0;
b = 0;
[t, Y]= ode45(M,[0, 10],[a, b / sqrt((2 * k * a)^2 + 1)]);
When running this code, odeToVectorField error occurs... Can anyone help me to solve this problem?
  댓글 수: 1
Steven Lord
Steven Lord 2023년 9월 19일
Please show the full and exact text of the error message(s) you received when you ran that code (all the text displayed in red in the Command Window).

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

채택된 답변

Torsten
Torsten 2023년 9월 19일
편집: Torsten 2023년 9월 19일
From the documentation:
odeToVectorField can convert only quasi-linear differential equations. That is, the highest-order derivatives must appear linearly. For example, odeToVectorField can convert y*y″(t) = –t^2 because it can be rewritten as y″(t) = –t^2/y. However, it cannot convert y″(t)^2 = –t^2 or sin(y″(t)) = –t^2.

추가 답변 (1개)

Sam Chak
Sam Chak 2023년 9월 19일
편집: Sam Chak 2023년 9월 19일
The highest-order derivative is embedded in or D2s. Notably, one of the terms in this context is nonlinear, as demonstrated by below.
To successfully utilize the 'odeToVectorField()' function, it's essential for the highest-order derivatives to appear linearly. To address this, I recommend attempting to solve this implicit differential equation using the 'ode15i()' command. See also decic().
syms x(t)
m = 1;
k = 1;
F = 1;
fs = 1;
fk = 1;
[K, E] = ellipke((x/pi - floor(x/pi))*pi);
% Test
% s = x; % this one should work!
s = sqrt(2)*E + 2*ellipke(1/2)*floor(x/pi)
s(t) = 
r = abs(((cos(x))^2 + 1)^1.5/sin(x)); % singularity occurs at x(t) = 0
Ds = diff(s, t); % time derivative of a unknown function s
D2s = diff(s, t, 2); % double-dot x is inside here
dnjstlafur = 0.5*((m*Ds^2)/r + abs((m*Ds^2)/r - 2*fs));
eqn = m*D2s == sqrt(F^2 - dnjstlafur^2)
eqn(t) = 

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by