如何在Matlab中解决包含dx和dy的微分方程。

huangapple go评论64阅读模式
英文:

How to solve differential equation with dx and dy in matlab

问题

我正在尝试解决方程:(3xy^2)dx + (2x^2y)dy = 0 在Matlab中,但我无法使其工作。您能帮助我吗?这是我迄今为止的代码。

dx和dy在Matlab中没有显示,因为ML认为它们等于1。然后dsolve返回错误。

这是我的代码:

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)

我尝试使用dsolve。

编辑:答案是C = (x^3y^2)^(1/5)

英文:

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)

答案1

得分: 1

假设 dxdy 实际上表示相对于一个独立变量(比如时间)的 xy 的导数,您需要使用关于此独立变量的导数来定义您的导数。这可以使用 抽象符号函数 来实现:

syms x(t) y(t);

然后,sym/diff 将隐式地理解要相对于哪个变量进行微分:

dx = diff(x); % 等同于 diff(x(t), t)
dy = diff(y); % 等同于 diff(y(t), t)

最后,您可以像以前一样使用您的原始微分方程来使用 dsolve

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

这将返回两个解,分别是 0C1/x(t)^(3/2)(常数 C1 是因为您尚未定义任何初始条件)。

另一方面,如果 y 实际上是相对于独立变量 x 而不是时间的函数,那么您需要执行类似于 @duffymo 建议的操作:

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

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)

答案2

得分: 0

重新排列成如下形式:

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

这是一个可分离的、非线性的、一阶常微分方程。

这里是来自Wolfram Alpha的解答。

英文:

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.

huangapple
  • 本文由 发表于 2023年7月10日 14:13:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76651069.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定