Efficiently Solve Matrix of ODE's in MATLAB without Rewriting as Column Vectors

In summary, the conversation discusses the issue of solving a system X' = f(X) with MATLAB, where X is a square matrix. The solvers in MATLAB require X to be a column vector, which can be achieved by rewriting X' and f(X) as column vectors. However, this might lead to a loss of efficiency and be a tedious process. A simpler solution is suggested using the reshape command, which was not initially considered. The conversation ends with gratitude for the helpful suggestion.
  • #1
juef
27
0
Hey all,

Consider the system [tex]X' = f(X)[/tex], where [tex]X[/tex] is a square matrix. I would like to solve this system with MATLAB, but all of its solvers require [tex]X[/tex] to be a column vector.

Of course, it would be possible to rewrite [tex]X'[/tex] and [tex]f(X)[/tex] as column vectors, but I guess some efficiency would be lost. It would also be a lot of pain to do :grumpy:

So, does anyone know of a simpler way to do such a thing? Thank you!
 
Physics news on Phys.org
  • #2
It's not a pain to do with the reshape command.
 
  • #3
:shy: Why on Earth didn't I think of that? You can't possibly imagine how much that just helped me! Thank you very much!
 

1. How can I efficiently solve a matrix of ODE's in MATLAB?

There are a few different approaches you can take to efficiently solve a matrix of ODE's in MATLAB. One option is to use the built-in "ode45" function, which is a versatile solver that can handle both stiff and non-stiff systems. Another option is to use the "ode15s" function, which is specifically designed for stiff systems. It is important to also pay attention to the initial conditions and the time span over which you want to solve the ODE's, as these can greatly impact the efficiency of the solver.

2. Do I have to rewrite my ODE's as column vectors before solving in MATLAB?

No, it is not necessary to rewrite your ODE's as column vectors before solving them in MATLAB. The built-in solvers are designed to handle both row and column vector inputs. However, it is important to be consistent with your choice of input format throughout your code in order to avoid errors.

3. Can I use MATLAB to solve ODE's with multiple dependent variables?

Yes, MATLAB can handle systems of ODE's with multiple dependent variables. You can either use the "ode45" or "ode15s" function and specify multiple equations in the system, or you can use the "ode15s" function and specify a single vector-valued function that represents the system of equations.

4. How can I improve the efficiency of my ODE solver in MATLAB?

There are a few ways you can improve the efficiency of your ODE solver in MATLAB. First, you can try using a more appropriate solver for your system, such as "ode15s" for stiff systems or "ode23" for non-stiff systems. You can also try adjusting the tolerances for the solver to find a balance between accuracy and efficiency. Additionally, optimizing your code and reducing the size of your matrices can also help improve efficiency.

5. Can I plot the results of my ODE solver using MATLAB?

Yes, you can plot the results of your ODE solver using MATLAB. Once you have solved the ODE's, you can use the "plot" function to visualize the results. You can also customize the plot by adding labels, legends, and adjusting the axes. Additionally, you can use the "odeplot" function to create an interactive plot that allows you to pause, step through, and zoom in on specific parts of the solution.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
9K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
Replies
27
Views
1K
  • Precalculus Mathematics Homework Help
2
Replies
57
Views
3K
Back
Top