# how to solve this differential equation system symbolically?

4 views (last 30 days)
Feysal Gholampour on 1 May 2022
Commented: Walter Roberson on 3 May 2022

John D'Errico on 1 May 2022
Edited: John D'Errico on 1 May 2022
This seems like a homework problem. But Walter has already given an answer, that I think is not helpful, since dsolve will fail when applied directly. And since the problem is insufficiently defined to be a good homework problem, I might conjecture it is not in fact homework.
syms y(t) x(t) f(t)
dy = diff(y);
E1 = x + dy == f;
E2 = diff(x) + y == diff(f);
First, differentiate E1, subtracting E2 from that.
E3 = simplify(diff(E1) - E2)
E3(t) =
As you can see, x(t) and f(t) have been completely eliminated from the result. However, now we can solve for y(t).
y(t) = dsolve(E3,y(0) == 0, dy(0) == 1)
y(t) =
In fact, if you think about it, note that this is a well known function : the hyperbolic sine function.
y = rewrite(y,'sinh')
y(t) =
E1 = subs(E1)
E1(t) =
From this we see that x(t) and f(t) are simply related, differening only by that cosh(t) term.
E2 = subs(E2)
E2(t) =
The problem is, at this point you are now stuck. Lacking f(t) or y(t), you cannot find the other. What is worse, We see that now E1 and E2 are actually the same pieces of information, since we can derive E2 from E1. That is, just differentiate both sides of E1, and look to see what you get.
diff(E1)
ans(t) =
SURPRISE! Differentiating E1 yields E2.
The point is, you lack sufficient information to solve the problem, even though you can solve for y(t). So perhaps that is the point of this assignment, IF it is one. Anyway, since the problem already had an answer, I might as well have written this.
Walter Roberson on 1 May 2022
The approach I used worked fine. I tested with MATLAB Online before I posted. I didn't post the code because it is obvious that it is an assignment.

Walter Roberson on 1 May 2022
Create the symbols and the two equations. dsolve() the pair of equations without boundary conditions, getting out a struct with a definition for x and y. Take the y and substitute t = 0 to get y(0) and equate that to the known value. Take the y and differentiate and substitute t = 0 to get y'(0) and equate that to the known value. You now have a pair of simultaneous equations relating the constants of the differential equations.
Walter Roberson on 3 May 2022
Good question. I wonder if it used symvar or equivalent and choose the first two. I seem to recall that solve() chooses variables starting from x y z (or X Y Z) first