Solving a ode with multiple conditions

10 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by