How to Use MATLAB ode23 or ode45 to Solve a Vector Problem?

  • MATLAB
  • Thread starter louie
  • Start date
  • Tags
    Matlab
In summary, to use ode23 or ode45 in MATLAB, you need to have two files: one for the differential function and one for the main function. The differential function should return a vector of derivatives and take in the time steps and original state vector. The main function should set up the state vector and call the differential function using either ode23 or ode45. It is important to make sure the input variables are properly defined and that the differential function returns the correct derivatives.
  • #1
louie
10
0
I want to use MATLAB ode23 or ode45 to solve the following problem,
(ignore the periods '.' as they are there to line up the vector spaces)

... Ids ...0.5Ids-0.3Iqs-0.4Idr-0.1IdrIqr ... 0.2Vd
d ..Iqs = -0.3Ids+0.5Iqs+0.8Idr-0.2Iqr^2 . . + . 0.2Vds
dt .Idr ...-0.5Ids+0.1Iqs+0.7Idr+0.6IdrIqr ... 0
.. . Iqr ... 0.9Iqs-0.5Iqs-0.4Idr+0.3Iqr^2 ... 0
... Wm .. 0.27(IdrIqs-IqrIds)-0.1Wm-0.85 ... 0

Any help explaining the correct input syntax would be greatly appreciated (as I'm not that familiar with MatLab).

Thanks
 
Physics news on Phys.org
  • #2
correction

correction original post...should say -0.1Iqr not -0.1IdrIqr,
-0.2Iqr not -0.2Iqr^2, 0.6Iqr not 0.6IdrIqr, 0.3Iqr not 0.3 Iqr^2
 
  • #3
Hi louie,

I'm not sure I understand what you're trying to do.

For ode45, you need two files. One which is your differential updater, and one which is the main function which calls it.

the differential function should return a vector which is the derivatives and read in time steps you want to look at and the original state vector.

The main file should set up the state vector and pass it.

for example, the differential function:

Code:
function dW=differential(t,W)

dW(1)=W(2);
dW(2)=W(1);

for the calling function:
Code:
function [t,W]=odesolver("input variables")

W_0= [X_0;Y_0];

t=[0:.1:20];

[T,W]=ode45('differential',t,W_0);

This will return the values for W at the points designated by t
 

1. What is the difference between ode23 and ode45 in MatLab?

Both ode23 and ode45 are numerical solvers in MatLab used for solving ordinary differential equations (ODEs). The main difference between the two is the order of accuracy, with ode45 being a higher order method than ode23. This means that ode45 is more accurate but may also take longer to compute. It is recommended to try both solvers and compare the results to determine which one is better suited for a particular problem.

2. How do I input my ODE into ode23/ode45 in MatLab?

The input for ode23 and ode45 in MatLab is a function handle, which is a way to pass a function as an argument to another function. You can define your ODE function separately and then use a function handle to pass it as an argument to ode23/ode45. Alternatively, you can use an anonymous function directly as the input for ode23/ode45. Make sure to read the documentation for the correct syntax and input requirements for your specific ODE.

3. Can ode23/ode45 handle systems of ODEs in MatLab?

Yes, both ode23 and ode45 can handle systems of ODEs in MatLab. For ode23, the system of ODEs must be in the form of a first-order vector differential equation, while for ode45, it can also handle higher-order equations. Make sure to properly define the system of ODEs and use the correct input syntax for the solver.

4. How do I specify initial conditions for my ODE in ode23/ode45 in MatLab?

The initial conditions for your ODE can be specified as a vector in the form [y0, y1, y2, ...], where y0 is the initial value for the dependent variable and y1, y2, ... are the initial values for the derivatives. If you have a system of ODEs, the initial conditions should be a vector with the same length as the number of equations in the system. Make sure to specify the initial conditions in the correct order according to your ODE function.

5. How do I change the settings and options for ode23/ode45 in MatLab?

There are several settings and options that can be changed for ode23/ode45 in MatLab, such as the solver tolerances, maximum step size, and output options. These can be specified using the odeset function, which allows you to create an options structure to pass as an argument to ode23/ode45. You can also use the odeset function to access and modify the default settings for the solvers. Refer to the documentation for more details on the available settings and options.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • Introductory Physics Homework Help
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
10K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
23K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
Back
Top