Coupled Differential Equation
조회 수: 8 (최근 30일)
이전 댓글 표시
Dear Friend,
I am solving a coupled differential equation in matlab to simulate the laser rate equation. The number of differential equation depends on the number of modes I will put through input, usually it is a very high number say 500-600.
I have two for loops inside another for loop.
I use the usual trick: dx/dt = Ax (say this is the differential equation)
so x2 = x1 + dt(Ax) (I solve it this way giving an initial condition on x1)
The problem is, this equation will be valid as long as abs(dx/x)<<1. And we need 'dt' for this purpose very small, which will eventually increases the iteration of my for loop. Now when I do that, I got an out of memory error.
Is there a way to get rid of it. I was thinking of extracting few outputs from the iteration (not all the output), but also it didn't work.
Thanks for your time.
-Graig
댓글 수: 2
Jarrod Rivituso
2011년 4월 21일
Forgive me if I misunderstand, but are you not using one of the ODE solvers?
채택된 답변
Andrew Newell
2011년 4월 26일
Here is an example where someone is using ode45 to solve an even bigger problem. To avoid out-of-memory errors, make A into a sparse matrix if you can.
EDIT: If I understand your notation, M is actually a vector with components M_q, and ditto for K and B. So you should create a new vector
X = [M; N];
and then define your function as follows:
f = @(x) [-gamma*x(1:end-1) + x(end)*B.*(x(1:end-1)+1) - c*K.*x(1:end-1); P - A*x(end) - x(end)*sum(B.*x(1:end-1))];
(or you could create an easier-to-read function in a separate file).
댓글 수: 0
추가 답변 (3개)
Jarrod Rivituso
2011년 4월 21일
I would recommend giving these a try:
I've never used them with the number of states you have. You may end up finding that your system is "stiff", depending on the system dynamics. In this case, you may prefer ode15s or other stiff solvers to the commonly used ode45.
댓글 수: 0
Graig
2011년 5월 2일
댓글 수: 7
Andrew Newell
2011년 5월 4일
This question is starting to sprawl and it is not clear what is going on. I recommend you accept an answer for this question and submit a new one in which you show us the code you used and describe the problem you are having.
참고 항목
카테고리
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!