I don't know why my code makes odeToVectorField error

3 vues (au cours des 30 derniers jours)
Student
Student le 19 Sep 2023
Modifié(e) : Sam Chak le 19 Sep 2023
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 commentaire
Steven Lord
Steven Lord le 19 Sep 2023
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).

Connectez-vous pour commenter.

Réponse acceptée

Torsten
Torsten le 19 Sep 2023
Modifié(e) : Torsten le 19 Sep 2023
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.

Plus de réponses (1)

Sam Chak
Sam Chak le 19 Sep 2023
Modifié(e) : Sam Chak le 19 Sep 2023
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) = 

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by