Using dsolve to solve a system of differential equations analytically
5 次查看(过去 30 天)
显示 更早的评论
When trying to solve a system analytically using dsolve, Matlab outputs that x is an empty function handle. Can someone explain why the following code does not work as expected?
m = 3.125*0.001; % Mass of the body in slug
Cd = 4.71*10^-7;
g = 32.2;
syms x(t) y(t)
Dx = diff(x,1);
D2x = diff(x,2);
Dy = diff(y,1);
D2y = diff(y,2);
[x,y] = dsolve([-Cd*Dx*sqrt(Dx^2+Dy^2)==m*D2x,-Cd*Dy*sqrt(Dx^2+Dy^2)-m*g==m*D2y],...
[x(0)==0 ,Dx(0)== 186*8.8/6*cosd(11.2), y(0) == 0, Dy(0)==186*8.8/6*sind(11.2)], 't');
x
x = matlabFunction(x)
0 个评论
采纳的回答
Star Strider
2020-12-21
The differential equation system is nonlinear, so it likely does not have an analytic solution.
Try this instead:
m = 3.125*0.001; % Mass of the body in slug
Cd = 4.71*10^-7;
g = 32.2;
syms x(t) y(t) T Y
Dx = diff(x,1);
D2x = diff(x,2);
Dy = diff(y,1);
D2y = diff(y,2);
[VF,Sbs] = odeToVectorField([-Cd*Dx*sqrt(Dx^2+Dy^2)==m*D2x,-Cd*Dy*sqrt(Dx^2+Dy^2)-m*g==m*D2y],...
[x(0)==0 ,Dx(0)== 186*8.8/6*cosd(11.2), y(0) == 0, Dy(0)==186*8.8/6*sind(11.2)]);
Fcn = matlabFunction(VF, 'Vars',{T,Y});
[T,Y] = ode45(Fcn, [0 10], [0 0 0 1]);
figure
plot(T, Y)
grid
legend(string(Sbs), 'Location','SW')
.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Oceanography and Hydrology 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!