explicit answer error with dsolve
显示 更早的评论
Hello, we made a code to model the motion of a ball in a rota meter. MatLab gives a error 'unable to find an explicit answer'. We can not figure out what we are doing wrong. Code:
% Constants
g = 9.81; % Gravitation (m/s^2)
C_D = 0.47; % Drag coefficient [-]
rho = 1.293; % Density of air [kg/m^3]
rho_steel = 8050; % Density of steel [kg/m^3]
%%system dimesions and properties
r_ball=0.005; % Radius of the ball in [m] (ESTIMATED VALUE)
m_ball= rho_steel*(4/3 * pi * r_ball^3); % Mass of the ball [kg] (ESTIMATED VALUE)
a = 0.005; % a variable of the tube [m]
b = 0.008; % b variable of the tube [m]
L = 0.112; % length of the tube [m]
h = 0.07 % equilibrium height
phi = 1.81*10^-5; % Viscosity of air [pa * s]
A_float = 0.0001327 % Area of the float [m^2]
%%Variables
Q=0.1; % Volume flow generated by compressor [m^3/s](ESTIMATED VALUE)
% Create differential equation
syms x(t);
dx = diff(x,t);
dxdx = diff(x,t,2);
ode = m_ball * diff(x,t,2) - 1/2 * rho * A_float * C_D * ((Q/((((((((b-a)*(h*x))/L)+a)^2)*pi)-A_float)))^2)
+ g * m_ball == 0;
% Conditions
cond1 = x(0) == 0;
cond2 = dx(0) == 3;
cond = [cond1 cond2];
%%Solve differential equation
ySol(t) = dsolve(ode, cond);
t = 0:1:100;
%Plot the solution
plot(t, ySol(t))
回答(1 个)
Star Strider
2018-9-30
0 个投票
You are not doing anything wrong. Not all differential equations have analytic solutions.
Instead, create your differential equation as a system of first-order differential equations, and code it as an anonymous function to use in ode15s (which would be my choice for your problem). Two functions, odeToVectorField and matlabFunction can do this for you:
g = 9.81; % Gravitation (m/s^2) C_D = 0.47; % Drag coefficient [-] rho = 1.293; % Density of air [kg/m^3] rho_steel = 8050; % Density of steel [kg/m^3] % %% system dimesions and properties r_ball=0.005; % Radius of the ball in [m] (ESTIMATED VALUE) m_ball= rho_steel*(4/3 * pi * r_ball^3); % Mass of the ball [kg] (ESTIMATED VALUE) a = 0.005; % a variable of the tube [m] b = 0.008; % b variable of the tube [m] L = 0.112; % length of the tube [m] h = 0.07 % equilibrium height phi = 1.81*10^-5; % Viscosity of air [pa * s] A_float = 0.0001327 % Area of the float [m^2] % %% Variables Q=0.1; % Volume flow generated by compressor [m^3/s](ESTIMATED VALUE)
% Create differential equation syms x(t) Y T dx = diff(x,t); dxdx = diff(x,t,2); ode = m_ball * diff(x,t,2) - 1/2 * rho * A_float * C_D * ((Q/((((((((b-a)*(h*x))/L)+a)^2)*pi)-A_float)))^2) + g * m_ball == 0;
[VF,Subs] = odeToVectorField(ode)
odefcn = matlabFunction(VF, 'Vars',{T,Y})
producing:
VF =
Y[2] 46487591893913/(485952971979340400*(pi*((3*Y[1])/1600 + 1/200)^2 - 4895765877162515/36893488147419103232)^2)
Subs =
x Dx
odefcn =
function_handle with value:
@(T,Y)[Y(2);1.0./(pi.*(Y(1).*1.875e-3+1.0./2.0e2).^2-1.327e-4).^2.*9.566273811345134e-5]
I always get the second output from odeToVectorField, because I then use it with legend in the plot of the ode15s result to know what the solutions represent.
类别
在 帮助中心 和 File Exchange 中查找有关 Equation Solving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!