Azzera filtri
Azzera filtri

Solving a ode with multiple conditions

4 visualizzazioni (ultimi 30 giorni)
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 Commento
Bjorn Gustavsson
Bjorn Gustavsson il 21 Lug 2020
Solve this one by hand (use separation of variables and integrate). Look at analytical solution, try to fit as best you can.

Accedi per commentare.

Risposta accettata

John D'Errico
John D'Errico il 21 Lug 2020
Modificato: John D'Errico il 21 Lug 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 Commento
Dhruba jyoti Bora
Dhruba jyoti Bora il 23 Lug 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.

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by