Solving a ode with multiple conditions

14 ビュー (過去 30 日間)
Dhruba jyoti Bora
Dhruba jyoti Bora 2020 年 7 月 21 日
コメント済み: Dhruba jyoti Bora 2020 年 7 月 23 日
I am unable to solve dy/dx=k/x with three conditions y(x1)=y1, y(x2)=y2, y(x3)=y3. Where both k and a constant need to be evaluated. Please help
  1 件のコメント
Bjorn Gustavsson
Bjorn Gustavsson 2020 年 7 月 21 日
Solve this one by hand (use separation of variables and integrate). Look at analytical solution, try to fit as best you can.

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

採用された回答

John D'Errico
John D'Errico 2020 年 7 月 21 日
編集済み: John D'Errico 2020 年 7 月 21 日
This is a first order ODE. You can have only ONE condition. However, if k is an unknown, then you could have TWO conditions. A third condition makes it impossible, unless you get lucky and the three values happen to be consistent.
The ode itself is trivial to solve. We could use separation of variables simply enough, to do it on paper. Or use dsolve in MATLAB. The separation of variables solution is easy enough theough. If dydx = k/x, then we have
dy = k*dx/x
integrating, we obtain
y = k*log(x) + C
If you don't trust me, then since this is a MATLAB forum, we would have
syms y(x) k
ysol = dsolve(diff(y,x) == k/x,x)
ysol =
C1 + k*log(x)
Which is, not surprsingly, the same as what I found. Remember that in MATLAB, log(x) is the natural log.
Now, you have THREE data points, so three pieces of information. But you have two unknown variables, k and C. You can recognize that an exact solution is impossible unless those 3 points fall on a straight line, when plotting y as a function of log(x). At best then we could consider a least squares fit. polyfit will suffice.
(By the way, it is a really bad idea to use numbered variables like that.)
X = [x1,x2,x3];
Y = [y1,y2,y3];
KC = polyfit(log(X),Y,1);
k = KC(1);
C = KC(2);
Again though, I would first plot log(X) versus Y. Is it a straight line, or at least close to one?
  1 件のコメント
Dhruba jyoti Bora
Dhruba jyoti Bora 2020 年 7 月 23 日
thanks a lot sir. I have solved in pen and paper the differential equation twice with two conditions at a time each. After plotting in matlab, there was a mismatch at the boundary in the plot. This was corrected using polyfit and i successfuly obtained my desired result and graph.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by