ode45 solver argument error
Mostrar comentarios más antiguos
clear all
clc;
syms y(x)
K = 0.1;
A=10;
N=100;
v=diff(y);
Y0 = [y(0)==K, v(0)==0];
tspan = [0 20];
eqn = diff(y,2) == N*(1+v^2)^1.5 + A*(K - y)*(1+v^2)^1.5 - (1+v^2)*v*x^(-1);
V=odeToVectorField(eqn,Y0);
M = matlabFunction(V,'vars',{'x','Y'});
ySol = ode45(M,tspan,Y0);
xValues = linspace(0,20,100);
yValues = deval(ySol,xValues,1);
plot(xValues,yValues)
I had a problem with ySol line in its arguments but I put in everything as i read from matlab informational page but then arithmetical error appeared(probably during tinkering with code i changed something) but I really dont have an idea what causes the main error, its really hard to understand error meaning, I am using odetovectorField for second order differential equation solution, if anyone knows how to successfully solve this diff eq please share. anyway here are errors
Error using ./
Arithmetical expression expected.
Error in symengine>@(x,Y)[Y(2);-(Y(1).*1.0e+1-1.0).*(Y(2).^2+1.0).^(3.0./2.0)+(Y(2).^2+1.0).^(3.0./2.0).*1.0e+2-((Y(2).^2+1.0).*Y(2))./x]
Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0. this is error i dont understand, is it connected to line 14?
Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
Error in (line 14)
ySol = ode45(M,tspan,Y0);
2 comentarios
The input y0 in ode45 i.e. the initial conditions are supposed to be numeric, but you have defined them to be symbolic, which is why you get the error.
syms y(x)
K = 0.1;
A = 10;
N = 100;
v = diff(y);
Y0 = [y(0)==K, v(0)==0];
tspan = [0 20];
eqn = diff(y,2) == N*(1+v^2)^1.5 + A*(K - y)*(1+v^2)^1.5 - (1+v^2)*v*x^(-1);
V = odeToVectorField(eqn);
M = matlabFunction(V,'vars',{'x','Y'});
%Supplying numeric values for initial conditions
ySol = ode45(M,tspan,[K; 0]);
xValues = linspace(0,20,100)
yValues = deval(ySol,xValues,1)
%plot(xValues,yValues)
Andria
el 12 de Sept. de 2023
Respuestas (1)
Hi @Andria
If you start the simulation from
, then a singularity will occur due to the division-by-zero term '...*v/x'. However, the system is inherently unstable, as you can see the state v exponentially explodes to a very large value in a very short interval of x.
xspan = [0.001 0.02]; % <-- start from non-zero x that is relatively close to 0
Y0 = [0.1; 0];
[x, Y] = ode45(@M, xspan, Y0);
plot(x, Y, 'linewidth', 1.5), grid on,
legend({'$y$', '$v$'}, 'interpreter', 'latex', 'fontsize', 12), legend('boxoff')
xlabel('x'), ylabel('Amplitude')
% the system
function Ydot = M(x, Y)
% definitions
Ydot = zeros(2, 1);
y = Y(1);
v = Y(2);
% parameters
K = 0.1;
A = 10;
N = 100;
% system
Ydot(1) = v;
Ydot(2) = N*(1 + v^2)^1.5 + A*(K - y)*(1 + v^2)^1.5 - (1 + v^2)*v/x;
% diff(y,2) == N*(1 + v^2)^1.5 + A*(K - y)*(1 + v^2)^1.5 - (1 + v^2)*v*x^(-1);
end
Categorías
Más información sobre Mathematics en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
