I don't know why this error happens...
2 ビュー (過去 30 日間)
古いコメントを表示
y = [0 0 0 0];
yp = [0 0 0 0];
tspan = [0,1];
y0_new = [5;0;0;0];
yp0_new = [0;0;5;0];
% y(1) = x , y(2) = y
% y(3) = yp(1) = vx
% y(4) = yp(2) = vy
% yp(3) = ax
% yp(4) = ay
[T,Y2] = ode15i(@f,tspan,y0_new,yp0_new);
plot(y(1), y(2));
function res = f(t2,y,yp)
m2 = 60;
F2 = 300;
fs2 = 150;
fk2 = 0;
syms x1(t);
m1 = 60;
k1 = 1;
F1 = 300;
fs1 = 150;
fk1 = 0;
s = ((log(sqrt(1 + (2 * k1 * x1)^2) + 2 * k1 * x1)) / (4 * k1)) + (sqrt(1 + (2 * k1 * x1)^2) * x1) / 2;
Ds1 = diff(s, t);
D2s1 = diff(s, t, 2);
dnjstlafur1 = 0.5 * (((m1 * Ds1^2) / (((2*k1*x1)^2 + 1)^1.5 / (2 * k1))) + abs(((m1 * Ds1^2) / (((2*k1*x1)^2 + 1)^1.5 / (2 * k1))) - fs1) - fs1);
ode1 = m1 * D2s1 == sqrt(F1^2 - dnjstlafur1^2);
[V1] = odeToVectorField(ode1);
M1 = matlabFunction(V1, 'vars', {'t', 'Y'});
a = 0;
b = 0;
[t, Y1]= ode45(M1,[0, t2],[a, b / sqrt((2 * k1 * a)^2 + 1)]);
xx = Y1(:,1);
xx1 = xx(end);
yy1 = xx1^2;
% y(1) = x , y(2) = y
% y(3) = yp(1) = vx
% y(4) = yp(2) = vy
% yp(3) = ax
% yp(4) = ay
res = zeros(4,1);
res(1) = yp(1) - y(3);
res(2) = yp(2) - y(4);
r2 = (y(3)^2 + y(4)^2)^1.5 / (y(3)*yp(4) - yp(3)*y(4));
v2 = sqrt(y(3)^2 + y(4)^2);
dnjstlafur2 = 0.5 * (((m2 * v2^2) / r2) + abs(((m2 * v2^2) / r2) - fs2) - fs2);
a2 = sqrt(yp(3)^2 + yp(4)^2);
res(3) = m2 * a2 - sqrt(F2^2 - dnjstlafur2^2);
res(4) = (y(1) - xx1) * yp(2) - (y(2) - yy1) * yp(1);
end
3 件のコメント
採用された回答
Walter Roberson
2023 年 11 月 22 日
移動済み: Walter Roberson
2023 年 11 月 22 日
[T,Y2] = ode15i(@f,tspan,y0_new,yp0_new);
You have an outer ode15i call. That is executing function f each time.
function res = f(t2,y,yp)
Function f is receiving the "current" time as the variable t2
[t, Y1]= ode45(M1,[0, t2],[a, b / sqrt((2 * k1 * a)^2 + 1)]);
t2 is used as the upper bound of the tspan for an ode45() call.
ode15i is finding f to be very unstable right from the beginning, so ode15i is decreasing the time step again and again trying to find a scale that the function is predictable "enough" over.
ode15i is finding f to be very unstable. It reduces the time right down to eps(0), 4.94065645841247e-324 -- the smallest representable positive time.
ode15s is calling f with that t2 value of 4.94065645841247e-324 . f is calling ode45() passing in a time span of [0 4.94065645841247e-324] .
In the argument processing for ode45, ode45 tries to figure out how large of a step to start with. There are a few calculations involved, but as a simplification they involve taking the final time of 4.94065645841247e-324 and multiplying by 0.1 . But 4.94065645841247e-324 is the smallest representable number, so 0.1 times it underflows to 0.
ode45 then cross-checks and sees that the step size it has calculated is 0, and generates the MATLAB:odearguments:MaxStepLEzero message.
To avoid getting the error message about the step size, use options on the ode15i call to set a minimum step size greater than 10*eps(0) . I would suggest to you that it is not useful to have a minimum step size smaller than realmin, about
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1546232/image.png)
Doing this would avoid the obscure error about minimum step size, and would instead get you a more understandable message from ode15i that it detected a likely singularity at time 0.
その他の回答 (1 件)
Student
2023 年 11 月 21 日
3 件のコメント
Torsten
2023 年 11 月 22 日
編集済み: Torsten
2023 年 11 月 24 日
Hint to make your code simpler:
Y = integral_{t'=t0}^{t'=t} y(t') dt'
is equivalent to
dY/dt = y(t), Y(t0) = 0
Thus the call to ode45 is superfluous - the integral functions for which you solve using ode45 can be included as unknowns in the call to ode15i.
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!