MATLAB solution to system of ODEs with forward and backward propagation

In summary: I just found an example that does almost exactly what you're trying to do (solve a non linear odes system to match b.c.s). I'll post the link in a little bit.
  • #1
phy127
13
0
I have a system of coupled ODEs which tells the propagation of power Pi in an optic fiber.

[tex]
\frac{\partial P_i }{\partial z} = \left (N\sigma - 1 \right ) P_i
[/tex]
where
[tex] N = \frac{\sum_i \alpha_i P_i}{\sum_i \beta_i P_i + 1}
[/tex]

If the signals are copropagating, there is no problem since it is easily solvable with ode45 in MATLAB. However, since there are signals which are propagating in the opposite direction, solutions must be relaxed (according to the Book) so that the forward and backward propagation powers would agree.

I'm solving the system from z = [0,L]. For those forward propagating signals, P_i(0)=finite. For those backward propagating signals, P_i(L) = some value. Can I solve this using initial value problem techniques in MATLAB? or do i need to move to boundary-value problem techniques. The thing is, I only know one side of the boundary, the value on the other side is my objective.

Please help. :)
 
Physics news on Phys.org
  • #2
The following simple problem has the essential features you're asking about, so let me show you how I would do it in this easier context.

[tex] \left(
\begin{array}{c}
x \\
y \\
\end{array}
\right)'=\left(
\begin{array}{cc}
-2 & 1 \\
1 & -2 \\
\end{array}
\right)\left(
\begin{array}{c}
x \\
y \\
\end{array}
\right)[/tex]
[tex] x(0) = 1 [/tex]
[tex] y(1) = 1 [/tex]

Here is the MATLAB code to solve it by setting up a simultaneous system for all the variables

Code:
function [ x y z] = example( N )
%Discretize the z interval with N points
z = linspace(0,1,N);
dz = 1/(N-1);
%Create the matrix system we need to solve. In the matrix the first 1 to N
%positions correspond to xs and the N+1 to 2N postions correspond to ys

A = zeros(2*N,2*N);
b = zeros(2*N,1);

%now the equations at each data point using a forward and backward
%difference for the y and x derivatives respectively
for i=1:N-1,
    %equations corresponding to x points
    A(i+1,i) = -1/dz;
    A(i+1,i+1) = 1/dz;
    A(i+1,i+1) = A(i+1,i+1)+2;
    A(i+1,i+1+N) = -1;
    %equations corresponding to y points
    A(i+N,i+N+1) = 1/dz;
    A(i+N,i+N) = -1/dz;
    A(i+N,i+N+1) = A(i+N,i+N+1) +2;
    A(i+N,i) = -1;
end
%handle end points as special cases
A(1,1) = 1; b(1) = 1;
A(2*N,2*N) = 1; b(2*N) = 1;
vars=A\b;
x = vars(1:N);
y = vars(N+1:2*N);
end

The exact solutions are
[tex] x(z) = \frac{e^{-3 z} \left(e^2-e^3+e^{2 z}+e^{3+2 z}\right)}{1+e^2}[/tex]
[tex] y(z) = \frac{e^{-3 z} \left(-e^2+e^3+e^{2 z}+e^{3+2 z}\right)}{1+e^2}[/tex]

If you run it you'll see it works.

Now your problem will be harder because it is non-linear which means the matrix A will actually be some Jacobian, and you'll have to do Newtons method or something like that to find the solution.
 
  • #3
The alternative, which might be easier to code but is less elegant is to just guess the initial conditions for the variables for which you don't have them, integrate the system and then iterate until you find a set of ICs such that the right BCs are satisfied.
 
  • #4
Thanks kai_sikorski

Your first reply is elegant! But unfortunately, my system is nonlinear. I have been searching around too and found that your second reply is the commonly used method.

On the other hand, I'm interested in the MATLAB function you presented. As for my problem, the number of simultaneous equations could be more than 50 if needed and about a quarter of that is backward propagating. I don't know yet if MATLAB can handle it in a faster rate using your second reply.
 
  • #5
phy,

As I said in my first post you can handle non linear problems. If you're trying to solve y'=f(y) you'll need to find the Jacobian of f and do Newton's method. If there are 50 equations, and say you want to discretize using 100 z steps, that would be 5000x5000 system you'll have to solve at each iteration. It might not be fast but I think that's doable.

EDIT Sorry it won't be a jacobian of f strictly speaking but rather a function related to f. You can see the pdf file I post below.
 
Last edited:
  • #6
Sorry if I misunderstood you kai. I'm not really good with linear algebra and I don't know exactly how can I do the method you are presenting. I will give it a try if you will help me lay it all. Of course that will consume your time. :))
 
  • #7
This file seems to go over what you need to do

http://www.cs.rpi.edu/~flaherje/pdf/ode6.pdf

Section 6.3 first goes over a linear problem similarly to what I did, then on page 22 they talk about a non-linear problem using Newtons method.

They use centered differences instead of forward and backward like I did. You should change their expressions to use forward and backward (depending on whether you're looking at a variable that has a left or right b.c.).

Maybe there's also a way to use centered difference in your problem. I couldn't figure out how to get as many equations as unknowns that way because you run into problems when for example trying to write an equation for x_N in my post. But maybe I'm missing something and maybe someone else can chime in.
 
  • #8
If you have Mathematica you might also be able to be lazy and just use NDSolve.
 
  • #9
I'm reading the pdf file you directed. It's too hard for me. I don't have very good mathematical foundations. Maybe this needs a lot of time. After some time, I will post a reply if things are getting better, or worse.

About Mathematica, I'll stick with Matlab as I need to do this in Matlab or Python.
 
  • #10
Yeah the Newton method stuff can be a little confusing.

It might be easier to try to implement a shooting method. The file I linked to has a section on that as well, or if that's too hard I'm sure you can find some other resources for the shooting method. Do a little reading and try to implement it. Once you give it a try if you have any problems go ahead and post and I think it will be easier to address specific issues than to try to give you general guidance.

Hang in there!
 

Related to MATLAB solution to system of ODEs with forward and backward propagation

1. What is a MATLAB solution to a system of ODEs?

A MATLAB solution to a system of ODEs refers to using the software program MATLAB to numerically solve a set of ordinary differential equations (ODEs). This involves using numerical methods to approximate the solutions of the ODEs, which can then be plotted or further analyzed.

2. What is forward and backward propagation in the context of ODEs?

In the context of ODEs, forward and backward propagation refer to the direction in which the equations are being solved. Forward propagation starts at an initial point and moves forward in time to calculate the solution at future points. Backward propagation, on the other hand, starts at a final point and moves backward in time to calculate the solution at previous points.

3. How does MATLAB handle solving a system of ODEs with forward and backward propagation?

MATLAB uses built-in functions and algorithms to solve a system of ODEs with both forward and backward propagation. These functions take in the ODEs, initial conditions, and other parameters, and use numerical methods such as Runge-Kutta or Adams-Bashforth to calculate the solutions at desired points in time.

4. What are the advantages of using MATLAB for solving ODEs with forward and backward propagation?

There are several advantages of using MATLAB for solving ODEs with forward and backward propagation. Firstly, MATLAB has a user-friendly interface, making it easy to input and modify equations and parameters. Additionally, MATLAB has a wide range of built-in functions and algorithms for solving ODEs, making it a powerful tool for numerical analysis. Finally, MATLAB allows for easy visualization of the solutions through plotting and graphing capabilities.

5. Are there any limitations to using a MATLAB solution for ODEs with forward and backward propagation?

While MATLAB is a powerful tool for solving ODEs, there are some limitations to using it for forward and backward propagation. One limitation is that it can only handle systems of ODEs that can be solved numerically. Additionally, the accuracy of the solutions depends on the chosen numerical method and step size, so it is important to choose appropriate settings for the problem at hand. Finally, MATLAB can be computationally intensive for large systems of ODEs, so it may not be the best option for solving very complex problems.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • Other Physics Topics
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
3K
  • Programming and Computer Science
Replies
2
Views
947
  • Special and General Relativity
2
Replies
40
Views
2K
Replies
1
Views
2K
Back
Top