Wrong answer for ODE

7 ビュー (過去 30 日間)
Umer
Umer 2023 年 4 月 29 日
コメント済み: Umer 2023 年 4 月 29 日
MATLAB is giving the wrong answer to my ordinary differential equation.
m*diff(v) + p*v(t) == -g*m
The solution I am getting by solving it by hand is
C*exp(-(p*t)/m) - (g*m)/p
This is part of my code:
syms v(t) p m g
sol = dsolve (m*diff(v) + p*v(t) == -g*m)
sol = 
MATLAB says:
sol =
(C4*exp(-(p*t)/m) - g*m)/p
What am I doing wrong?
  3 件のコメント
Image Analyst
Image Analyst 2023 年 4 月 29 日
編集済み: Image Analyst 2023 年 4 月 29 日
How did you get the one you got by hand? Why is your exp() not divided by p? Is p a constant? If so then it could be bundled into the constant.
Umer
Umer 2023 年 4 月 29 日
Oh yes!!! p IS a constant, that makes sense. sorry my bad. just learning this stuff for the first time. Thank youu so muchh.

サインインしてコメントする。

採用された回答

John D'Errico
John D'Errico 2023 年 4 月 29 日
As is so often the case, a DIFFERENT answer is not always a WRONG answer. It may just look different. But different is not always a bad thing. (Why do I think these are words we all should take more seriously? Skipping the editorial comments...)
We can look at the ODE. You give no initial condition, but that should not be relevant. As well, you do not say which release of MATLAB you did that with.
syms m p g v(t)
ODE = m*diff(v) + p*v(t) == -g*m
ODE(t) = 
vsol = dsolve(ODE)
vsol = 
And that is the same as what you got from dsolve. But is it different? Remember that C1 in this solution is a COMPLETELY unknown parameter. As well, p is a CONSTANT, but it could be any constant.
So the only difference is that IF we decided to write
C = C1/p
then do you agree that the two solutions would now look the same?
  1 件のコメント
Umer
Umer 2023 年 4 月 29 日
Thank you so much!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by