Solving a differential equation
조회 수: 5 (최근 30일)
이전 댓글 표시
Hello,
I am working at a mathematical problem and I wanted to solve it numerically through MATLAB. The equation has the form:
y'(t) = g(t,y(t)) - a y(t)
and
g(t,y(t)) = b sinh[(g(t-dt, y(t-dt))] y(t) + c
with a,b,c in R.
I already tried using the ode and dde function in MATLAB without luck. Therefore I hope you can help me with the implementation in the code.
댓글 수: 4
Andrew Newell
2011년 5월 11일
I think Matt has a point. As formulated, it looks like an infinite recursion.
채택된 답변
Andrew Newell
2011년 5월 12일
If your equations contain only linear combinations of the derivatives, you could formulate it as a mass matrix problem M(t,y)y' = f(t,y) . For the two equations you have provided in the comment,
dF = - R*dI/u_a;
dI = const2*cosh(insinh*F)*insinh*dF+vor*sinh(insinh*F)*dn*exp(-beta*dEC2);
you could set up the problem as follows:
y = [F; I];
M = [1 - R/u_a; const2*cosh(insinh*F)*insinh 1];
and f(t,y) would output
[0; vor*sinh(insinh*y(1))*dn*exp(-beta*dEC2)]
See the ode45 documentation for how to include a mass matrix.
(edited to include the relevant part of betlor5's comment)
댓글 수: 0
추가 답변 (5개)
Andrew Newell
2011년 5월 11일
I have been floundering a bit with this problem, but now I see what you need: a variable
z = [y; g]
with
y'(t) = (g-a)*y(t)
g'(t) = df(t)/dt * y(t)
g(0) = c
The function f is something like what you currently would call b sinh[(g(t,y)].
Note that this new system is a set of ordinary differential equations, so you could use the odexx functions.
EDIT: In terms of z,
z_1'(t) = (z_2-a)*z_1
z_2'(t) = df(z_1)/dt * z_1
z_2(0) = c
댓글 수: 0
Andrew Newell
2011년 5월 11일
If I understand your question, you have a delay differential equation with one variable y(t), and your equation has the form y'(t) = f( y(t), y(t-t1) ), so it should input a scalar for y(t) and another for y(t-1) (the variables y and Z). Instead, you input vectors of length 2 and return a 2-vector for y'(t).
EDIT: For clarity, it might help to rewrite your function as follows:
function d = ddeg(~,y,ylag)
The tilde is used in recent versions of MATLAB to indicate that the variable is not used. If your version of MATLAB objects, put the t back in.
EDIT 2: I'm not sure that your definition of the function g makes sense. If
g(t,y(t)) = b sinh[(g(t-dt, y(t-dt))] y(t) + c
then
g(t-dt,y(t-dt)) = b sinh[(g(t-2*dt, y(t-2*dt))] y(t-dt) + c
and so on forever. How could you evaluate g?
댓글 수: 3
Andrew Newell
2011년 5월 11일
You don't need to pass on g. The purpose of ddeg is to calculate y'(t) and get the next y(t). The solver takes care of the details.
betlor5
2011년 5월 12일
댓글 수: 2
Andrew Newell
2011년 5월 12일
It could be g'(t) = f'(t) * y'(t). My answer above is just a sketch; I can't tell exactly what the right form is without the original equations. Yes, I think that if you can calculate g'(t), you should make g a component of the y vector.
I don't see the problem with solving 8 differential equations. People solve systems of thousands using MATLAB. And I really don't see how passing g as a variable makes it any simpler.
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!