How to solve a row of differential equations?

3 views (last 30 days)
Hey,
I have the Problem that I want to solve a row of differential equations like:
dP_0(t)=-v_0*P_0(t)
dP_i(t)=-v_i*P_i(t) + v_i-1*P_i-1(t)
and so on. So P_i-1(t) is the vector I get from the last equation.
I wrote a script and the funkctions for solving it with ode45. Now I have the problem that P_i-1 is a vector with length 1001 and the initial condition vector for P_i has the length 1. That's the error: "DGL_P_I returns a vector of length 1001, but the length of initial conditions vector is 1. The vector returned by DGL_P_I and the initial conditions vector must have the same number of elements."
DGL_P_I is the function.
I hope there's someone who can help me with the problem.
Thank you ;)
  2 Comments
Torsten
Torsten on 30 Jun 2015
You must supply initial conditions for P_0,P_1,P_2,...,P_N. Thus your vector of initial condition must have length (N+1).
Or what exactly is your problem ?
Best wishes
Torsten.
Lukas Bathelt
Lukas Bathelt on 30 Jun 2015
Thank you for the answer.
The initial conditions are 1 for P_0 and 0 for all other "Ps". But my result for a P_i-1 is a vector of the length 1001. So when I have the next step:
dP_i(t)=-v_i*P_i(t) + v_i-1*P_i-1(t)
P_i has as initial condition just the 0 and the P_i-1 is a vector with length 1001. But for Matlab it has to be the same dimensions.
I solved the problem now with an approximation where P_i-1 is a function handle and it is made with polyfit. It's not nice, but it works. Especially for more iterations the approximation is very inaccurate.

Sign in to comment.

Answers (2)

Star Strider
Star Strider on 30 Jun 2015
I may not understand the function you want to integrate, so consider that with respect to my Answer.
Integrating a system of 1000 or so differential equations with ode45 or any other ODE solver is going to be difficult.
Fortunately, your equation appears to be linear, with your constants being the ‘v_’ values, and the variables the P_ values. You can probably create it as a square matrix, and then use the matrix exponential function expm to evaluate it.
The matrix exponential, expm, is the integrated solution to the system:
dx/dt = A*x
where dx/dt and x are both column vectors and A is your matrix of coefficients, that is in your instance, a lower-triangular matrix.
See any text on modern control for a detailed discussion. You will quickly see how that applies to your problem (at least if I understand it correctly).

John D'Errico
John D'Errico on 30 Jun 2015
You have 1001 COUPLED differential equations.
You are willing to provide only ONE initial condition. That is insufficient information to solve for all of those unknowns. Think of it like this:
While you could solve for P_0(t) from the first equation (assuming that v_0 is known) this is a problem of integration.
dP_0(t)=-v_0*P_0(t)
So there is effectively a constant of integration that is unknown. We use that one initial condition to solve for the unknown constant. But then one must use P_0 to solve for P_1. As soon as you try to do so, you will have ANOTHER constant of integration to resolve. But you are now out of initial conditions! You used it up before. You have no new information to provide to resolve the constant term in P_1(t). Of course all of the remainder of the equations also fail due to this problem, leaving you with a problem of insufficient information.
This is why the ODE solver cannot solve your problem. You needed to provide 1001 initial conditions for 1001 equations. Just wanting a solution is not enough. You need to provide sufficient information for the solution to be resolved.

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!