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

  • Context: MATLAB 
  • Thread starter Thread starter louie
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
SUMMARY

The discussion focuses on using MATLAB's ode23 and ode45 functions to solve a vector problem involving differential equations. The user seeks clarification on the correct input syntax for these functions, particularly how to structure the differential updater and the main function. Key points include the need for two separate files: one for the differential function that returns derivatives and another for the main function that sets up the state vector and calls the differential function. The corrected equations and syntax are crucial for accurate implementation.

PREREQUISITES
  • Understanding of MATLAB syntax and functions
  • Familiarity with differential equations
  • Knowledge of vector mathematics
  • Basic experience with MATLAB file structures
NEXT STEPS
  • Learn how to implement MATLAB ode23 for solving differential equations
  • Explore MATLAB function file creation and management
  • Study the differences between ode23 and ode45 in MATLAB
  • Investigate vector and matrix operations in MATLAB for complex systems
USEFUL FOR

Students, engineers, and researchers working with MATLAB who need to solve vector-based differential equations, particularly those new to MATLAB's ode functions.

louie
Messages
10
Reaction score
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
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
 
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
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 5 ·
Replies
5
Views
11K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
23K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 12 ·
Replies
12
Views
33K