Filter löschen
Filter löschen

Solving a ode with multiple conditions

4 Ansichten (letzte 30 Tage)
Dhruba jyoti Bora
Dhruba jyoti Bora am 21 Jul. 2020
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 Kommentar
Bjorn Gustavsson
Bjorn Gustavsson am 21 Jul. 2020
Solve this one by hand (use separation of variables and integrate). Look at analytical solution, try to fit as best you can.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

John D'Errico
John D'Errico am 21 Jul. 2020
Bearbeitet: John D'Errico am 21 Jul. 2020
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 Kommentar
Dhruba jyoti Bora
Dhruba jyoti Bora am 23 Jul. 2020
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by