How to solve differential equation with dx and dy in matlab

130 Views Asked by At

I am trying to solve the equation: (3xy^2)dx + (2x^2y)dy = 0 in matlab but I can't get it to work. Can you please help me? This is my code so far.

The dx and dy do not show up in matlab, as ML thinks they are 1. Then dsolve returns an error.

This is my code:

syms dy dx y x

dy = diff(y)
dx = diff(x)

eqn = 3*x*y^2*dx + 2*x^2*y*dy == 0

dsolve(eqn)

I tried to use dsolve.

Edit: the answer is C = (x^3y^2)^(1/5)

2

There are 2 best solutions below

0
duffymo On

Rearrange it to look like this:

y' = 3xy^2/2x^2y

This is a separable, non-linear, first-order ordinary differential equation.

Here is the solution from Wolfram Alpha.

4
horchler On

Assuming dx and dy actually represent the derivatives of x and y with respect to an independent variable such as time, you need to define your derivatives with respect to this independent variable upon which out depends. This can be dune using an abstract symbolic function:

syms x(t) y(t);

Then sym/diff will implicitly understand what to differentiate with respect to:

dx = diff(x); % equivalent to diff(x(t), t)
dy = diff(y); % equivalent to diff(y(t), t)

Finally, you can use your original differential equation with dsolve as before:

eqn = 3*x*y^2*dx + 2*x^2*y*dy == 0;
dsolve(eqn)

This returns two solutions, 0 and C1/x(t)^(3/2) (the constant C1 is because you have not defined any initial conditions).

On the other hand, if y is actually a function of the independent variable x instead of time you'll need to do something akin to what @duffymo suggested:

syms y(x);
dydx = diff(y);
eqn = 3*x*y^2 + 2*x^2*y*dydx == 0;
dsolve(eqn)