Using dsolve to solve a system of differential equations analytically
5 views (last 30 days)
Show older comments
Aleem Andrew
on 20 Dec 2020
Commented: Star Strider
on 21 Dec 2020
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 Comments
Accepted Answer
Star Strider
on 21 Dec 2020
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')
.
2 Comments
More Answers (0)
See Also
Categories
Find more on Oceanography and Hydrology in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!