Differential equations by separable equations (Symbolically)

14 views (last 30 days)
Hi guys, I'm new to Matlab, so i have this problem:
My professor said I need to write a code to solve a differential equation by the Separable Equations Method. The script needs these steps:
  1. Enter the equation
  2. Identify the equation as one solvable by the Separable Equations Method
  3. Call a class, method, subroutine (I'm yet to know how it's called in matlab) that contains the Separable Equations algorithm
  4. Have one variable in one side of the equations (by some command or method by matlab) and the other one on the other side.
  5. Extract both sides with f=lhs() and g=rhs()
  6. Integrate both so F=int(f) and G=int(g)
  7. Combine both in one equation by F-G==0
  8. If not explicit, solve (or isolate) for the dependant variable.
Right now, I solved (scripted) pretty much of steps 5 to 8. Step 1 I believe I'll need to ask the user to enter the differential equation in the Matlab way, so the software can work with it. Step 3 I'm yet to investigate but I'm sure it's not difficult. The probelms are steps 2 and 4.
Math says that a diff eqn solvable by separable equations is one of the form f(x,y)=p(x)h(y) or p(x)+h(y)=0. So, I don't know if there's a command to have matlab check this option or if I need to study more of those equations to see if there's some mathematical way to identify them so I can turn that into an algorithm.
Step 4 it's another challenge. I investigated documentation on matlab and I don't find a command to ask the program to do that. Isolate works if there's only y' (or dy in some other notation), but if I have, for example, y'+2xy=0 or dx/dy+2xy=0, isolate can only work with dy or y at the time, not both. The question in this step is, there's a way to do this with matlab? if so, how? For the example above I would need matlab to: y'/y = 2x or dy/y = 2x dx (or in the notation used by matlab: diff(y,x)/y==2x so i can f=lhs() and g=rhs().
I forgot to mention, I already know of dsolve() and I love it. It's a general way (and a much better way) to solve any differential equation. I can't use it though, I think my professor wants us to code the way we solve it on paper, but I'm having it difficult because the reasons I mentioned. Thanks in advance and sorry for the long question.
I'm also new to this forum, so if I broke any rules or you have any feedback so I can improve in my future questions, let me know.
  1 Comment
Gary Gorman
Gary Gorman on 6 Feb 2023
Luis, I see this question is two years old. No one has answered. I know that Maple has a command separateVariables which would probably do the trick for steps 2 and 4. At this moment, Feb 2023, i think Matlab has no such command.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 6 Feb 2023
Math says that a diff eqn solvable by separable equations is one of the form f(x,y)=p(x)h(y) or p(x)+h(y)=0
For the first form, if you coeffs(f, x, 'all') then each entry in the coefficients must involve y, including there being no non-zero constant term.
For the second form, if you coeffs(f,x,'all') then each coefficient for x must not involve y, except for the coefficient corresponding to x^0, the "constant" as far as x is concerned.
[I was going to say that in turn each element of the remainder must involve y, but I realized that was incorrect: p(x) = 2*x+5 h(y) = 7*y + 9, p(x)+h(y) = 2*x + 7*y + 14 and you cannot tell with just this information how to partition the 14 between p(x) and h(y) ]
To isolate variables, you can first use symvars() to verify that both variables are present; if not then you cannot isolate the two variables to different sides. Next, expand() the equation. Then use isSymType() with 'plus' to determine whether you are working with a sum on at least one of the sides of the expanded equation; if not then one of the variables only appears multiplied by the other.
Now that you have a summation,
ch = children(TheSummation);
cellfun(@(E) findSymType(E, "symfunDependingOn", x), ch, 'uniform', 0)
any entry that is non-empty involves an unresolved function of x such as p(x) or diff(p,x), and those corresponding children can be moved to one side . Any entry of the findSymType that is empty should be further examined with symvar() to see whether it contains the variable not in the form of a function call . For example q = diff(p) + p^2 + 5 + x then the diff(p) and p^2 entries would be non-empty for symfunDependingOn but the 5 and the x results for the findSymType would be empty, so you need to check them with symvar() to determine whether the variable appears. Any expression in which the variable appear should be moved to one side.
Hmmm, actually instead of the above approach you could
ch = children(TheSummation);
cellfun(@(E) intersect(symvar(E),x), children(q), 'uniform', 0)
the empty entries have no references to x
This approach will not work for p(x)*h(y): it is not clear to me that you can isolate x and y to different sides with that form.
  1 Comment
Gary Gorman
Gary Gorman on 6 Feb 2023
Thanks much, Walter. i am working through this. Appears that coeffs can only handle polynomials. If p(X)=1/(1+x) (practically a standard form for differential equations) then coeffs will not do the trick, i think.

Sign in to comment.

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!