Output of ode45 for System of Differential Equations

  • MATLAB
  • Thread starter marellasunny
  • Start date
  • Tags
    Matlab
In summary, the conversation discusses the output of ode45 for a system of differential equations and how to plot the results using MATLAB. It is explained that the command x(:,1) means all rows, first column and that this can be used to plot the results of the first state variable over time. The function "f" is also mentioned and how it returns a time vector and a matrix containing the values of the state variables at each time point.
  • #1
marellasunny
255
3
My book explains the command x(:,1) as "x,all rows,first column".
Q.How does the output of ode45 for a system of differential equations look like?
But,when I solve a system of 2 first order differential equations(w.r.t time),I take x as a "column vector".
[x1
x2]
So,if I wanted to plot x(1) which is the first row of the column vector,I should write plot(t,x(1)) right? MATLAB gives an error.

MATLAB however accepts this ''plot(t,x(:,1))'',which literally means plotting all rows,1st column x versus t.

I don't get it.x has only 1 column and 2 rows.Where is the question of 1st and 2nd column in x?
 
Last edited:
Physics news on Phys.org
  • #2
marellasunny said:
My book explains the command x(:,1) as "x,all rows,first column".
Q.How does the output of ode45 for a system of differential equations look like?
But,when I solve a system of 2 first order differential equations(w.r.t time),I take x as a "column vector".
[x1
x2]
So,if I wanted to plot x(1) which is the first row of the column vector,I should write plot(t,x(1)) right? MATLAB gives an error.

MATLAB however accepts this ''plot(t,x(:,1))'',which literally means plotting all rows,1st column x versus t.

I don't get it.x has only 1 column and 2 rows.Where is the question of 1st and 2nd column in x?

If the function "f" that you're integrating has "n" state variables, then [t,x]=ode45(@f,[ti,tf],x0) should return a time vector "t" length "m", and an m by n matrix "x". Here "m" is the number of time sample points used, and the i-th column of "x" is a vector length "m" containing the values of the i-th state variable at each time point.

So yes, "plot(t,x(:,i))" should plot the results for the i-th state variable versus time.

BTW. That's how it works in gnu-Octave anyway. I think MATLAB is the same.
 
Last edited:

1. What is the output of ode45 for a system of differential equations?

The output of ode45 for a system of differential equations is a vector of solution values at specific time points. This vector contains the values of all the variables in the system at each time point, allowing for a complete understanding of the behavior of the system over time.

2. How does ode45 handle the solution of a system of differential equations?

Ode45 uses a combination of fourth and fifth order Runge-Kutta methods to solve a system of differential equations. This means that it calculates an estimate for the solution at multiple time points, and then uses this information to refine the estimate and improve accuracy.

3. Can ode45 handle stiff systems of differential equations?

Yes, ode45 is designed to handle both non-stiff and stiff systems of differential equations. It automatically adjusts its step size based on the stiffness of the system, ensuring accurate solutions for both types of systems.

4. How do I specify the initial conditions for a system of differential equations in ode45?

The initial conditions for a system of differential equations can be specified by passing a vector of initial values to the ode45 function. This vector should contain the initial values for all the variables in the system, in the same order as they appear in the system of equations.

5. Can I plot the output of ode45 for a system of differential equations?

Yes, you can plot the output of ode45 for a system of differential equations by using the time points as the x-axis and the solution values as the y-axis. This will give you a visual representation of how the variables in the system change over time.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
993
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • Linear and Abstract Algebra
Replies
4
Views
869
Back
Top