필터 지우기
필터 지우기

Solving a ode with multiple conditions

조회 수: 4 (최근 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 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