MATLAB solution to system of ODEs with forward and backward propagation

  • MATLAB
  • Thread starter phy127
  • Start date
  • #1
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. :)
 

Answers and Replies

  • #2
kai_sikorski
Gold Member
162
0
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
kai_sikorski
Gold Member
162
0
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
13
0
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
kai_sikorski
Gold Member
162
0
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
13
0
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
kai_sikorski
Gold Member
162
0
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
kai_sikorski
Gold Member
162
0
If you have Mathematica you might also be able to be lazy and just use NDSolve.
 
  • #9
13
0
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
kai_sikorski
Gold Member
162
0
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 Threads on MATLAB solution to system of ODEs with forward and backward propagation

Replies
1
Views
2K
  • Last Post
Replies
5
Views
3K
Replies
0
Views
1K
Replies
17
Views
4K
Replies
7
Views
2K
  • Last Post
Replies
3
Views
864
Replies
5
Views
682
Replies
3
Views
3K
  • Last Post
Replies
2
Views
2K
Top