Is it possible to use runge-kutta 4th order method to solve a equation with three different variables? For instance I have a equation : dy/dt= (R-0.135y)/P

조회 수: 13 (최근 30일)
Is it possible to use runge-kutta 4th order method to solve a equation with three different variables? For instance I have a equation : dy/dt= (R-0.135y)/P

답변 (1개)

John D'Errico
John D'Errico 2020년 2월 20일
It looks like you do not have THREE different variables.
You have P, which I presume is a constant? Do you know the value of P? If so, it is a constant, just like the number 0.135. The same applies to R. Is it a known constant? Or, are P and R some constants, but where you do not know the value?
In the first case, where R and P have some fixed and known value, then yes, you can use a tool like ODE45 to predict y over some range for t. You WILL need an initial condition however. That is true for any ODE solver.
In the alternative cae, where R and P are assumed to be constant, but with an unknown value, then NO, you CANNOT use a tool like ODE45 (or ANY numerical ODE solver, thus Runge Kutta, Euler, etc.) to solve the ODE. In that case, you can use a solver like DSOLVE, thus a symbolic solver.
And, of course, if R and P are unknown functions of t, then no, you CANNOT use a tool like ODE45 or even DSOLVE to solve the problem, since you have only one ODE and three unknown functions.
  댓글 수: 3
John D'Errico
John D'Errico 2020년 2월 20일
As long as in the end, you have fully numerical values for R (and P and A, etc.) and you have an initial value for y at a point, then yes, you can use ODE45.
Of course, this is such a simple ODE that it has a simple solution too. dsolve can handle it easily enough to give an anlytical solution.
syms t y(t) P R
dsolve(diff(y(t)) == (R - 0.135*y(t))/P)
ans =
(200*R)/27 - (C1*exp(-(27*t)/(200*P)))/27
As you should see, there is an undetermined constant, C1 in there, since I did not provide an initial condition. If I have that also, for example, y(0) = 2,
dsolve(diff(y(t)) == (R - 0.135*y(t))/P,y(0) == 2)
ans =
(200*R)/27 - (exp(-(27*t)/(200*P))*(200*R - 54))/27
Of course, you mention that you have a set of equations, so it appears that in reality you have a system of ODEs. Again, dsolve MIGHT be able to handle it, although the odds are good that if you have more than a couple of equations, dsolve might fail. In that case, ODE45 might indeed be the proper solution tool. It is rather difficult to know, since you have not been that clear. Do you indeed have a system of ordinary differential equations? Is it an initial value problem? A boundary value problem? You indicate that only SOME of the equations are in differential form. Does that mean you really have a DAE problem?
I'd suggest you start by reading through the docs for ODE45. There will be examples in there. Its hard to know what you really have.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by