# Graphing and finding the closed form solution to a system of differential equations

10 views (last 30 days)
Aleem Andrew on 19 Mar 2020
Edited: Aleem Andrew on 2 Apr 2020
I am trying to graph the solution to the following system of differential equations and finding the closed form solution using for example.the symbolic toolbox would help me understand what function is being plotted. When using the symbolic toolbox to find the analytical solution Matlab states that it is unable to find an explicit solution. On the other hand when I tried to write a function and graph the solution the graph was not visible. Can someone explain how I can either find the analytical solution or graph the solution? Any help would be appreciated.
t''= t'^2(tan(t)) - x''(4sec(t))
t'^2 (sec(t)-tan(t)) = x''*sec(t)*(1/0.625-4)
Initial conditions: t(0) = pi/3; t'(0) = 0; x'(0) = x(0) = 0
Mohammad Sami on 19 Mar 2020
You can use the function fplot to plot a function. You will need to write out the functions you need to plot as anoynmous functions. An example for documentation.
See doc fplot for more details
xt = @(t) cos(3*t);
yt = @(t) sin(2*t);
fplot(xt,yt)

Ameer Hamza on 2 Apr 2020
The following shows how to use the symbolic toolbox to create the handle for the ODEs and then use ode45 to find a numerical solution.
syms t(y) x(y)
dt = diff(t);
ddt = diff(dt);
dx = diff(x);
ddx = diff(dx);
eq1 = ddt == dt^2*(tan(t)) - ddx*4*sec(t);
eq2 = dt^2*(sec(t)-tan(t)) == ddx*sec(t)*(1/0.625-4);
[eqn, vars] = reduceDifferentialOrder([eq1 eq2], [t x]);
[M,F] = massMatrixForm(eqn,vars);
f = M\F;
odeFun = odeFunction(f, vars);
ic = [pi/6; 0; 0; 0];
ode45(odeFun, [0 10], ic)
Alternatively, you can also write your own odeFunction but It require a bit of algebric manipulation
ode = @myodeFun;
t = [0 10];
ic = [pi/6; 0; 0; 0];
[t,y] = ode45(ode, t, ic);
plot(t,y, 'o-');
function dydx = myodeFun(t,x)
% Rearranged Equations:
% t'' = -(dt^2*(2*cos(t)*tan(t) - 5))/(3*cos(t))
% x'' = (5*dt^2*(cos(t)*tan(t) - 1))/12
% x(1) -> t, x(2) -> t', x(3) -> x, x(4) -> x'
dydx = zeros(4,1);
dydx(1) = x(2);
dydx(2) = -(x(2)^2*(2*cos(x(1))*tan(x(1)) - 5))/(3*cos(x(1)));
dydx(3) = x(4);
dydx(4) = (5*x(2)^2*(cos(x(1))*tan(x(1)) - 1))/12;
end
##### 2 CommentsShow 1 older commentHide 1 older comment
Ameer Hamza on 2 Apr 2020