Solving two ODE's Simultaneously using MATLAB

  • MATLAB
  • Thread starter mkadouh
  • Start date
  • Tags
    Matlab
Time (s)');ylabel('Value');legend('ia','w');In summary, the conversation discusses writing code for solving the two Dynamic Equilibrium Equations for an electric motor and plotting the values of ia and w versus time. The code uses the constants and initial conditions provided and uses the ode45 function to solve the equations and plot the results. It also mentions the ability to change initial conditions and TL to see how the plots change.
  • #1
mkadouh
1
0
Hi,

I am having trouble writing the code for the following:

The two Dynamic Equilibium Equations for an electric motor are:

dia/dt=(1/La)*(Va-ia*Ra-ea);
dw/dt=(1/J)*(Tem-TL-B*w);

Where:
Ra=0.6;
La=2e-3;
K*Phi=0.076;
TL=0.041893;
B=1e-4;
J=0.0024624;
Va=42;
Tem=K*Phi*ia;
ea=K*Phi*w;
Time span= 5 sec;

How do I write a code that solves these two equations simultaneously? I am required to plot ia and w versus time. I am also required to change the initial conditions and change TL to see how the plots change.

Thanks.
 
Physics news on Phys.org
  • #2
The following is a basic example of how to solve the two equations simultaneously and plot the results:% Define constants Ra = 0.6;La = 2e-3;KPhi = 0.076;TL = 0.041893;B = 1e-4;J = 0.0024624;Va = 42;% Set initial conditions ia_0 = 0;w_0 = 0;% Set time span tspan = [0 5];% Define function handlesf1 = @(t,ia,w) (1/La)*(Va - ia*Ra - KPhi*w);f2 = @(t,ia,w) (1/J)*(KPhi*ia - TL - B*w);% Solve system of equations with ode45 [t,y] = ode45(@(t,y) [f1(t,y(1),y(2)); f2(t,y(1),y(2))], tspan,[ia_0, w_0]);% Plot results figure;hold on;plot(t,y(:,1)); %ia vs. timeplot(t,y(:,2)); %w vs. timehold off;
 

1. How do I solve two ODEs simultaneously using MATLAB?

To solve two ODEs simultaneously using MATLAB, you can use the ode45 function, which is a built-in solver for systems of ODEs. You will need to define your ODEs as a system of first-order equations and provide initial conditions for each equation. Then, you can use the ode45 function to numerically solve the equations and obtain a solution.

2. Can I solve more than two ODEs simultaneously using MATLAB?

Yes, you can solve any number of ODEs simultaneously using MATLAB. The ode45 function can handle systems of any size as long as you define your equations and initial conditions correctly. You can also use other built-in solvers, such as ode23 or ode15s, depending on the specific needs of your system.

3. How do I plot the solution to my system of ODEs using MATLAB?

To plot the solution to your system of ODEs using MATLAB, you can use the plot function. You will need to specify the independent variable (usually time) and the dependent variables (the solutions to your equations). You can also use the ode45 output to directly plot the solution without having to manually extract the data points.

4. Can I use MATLAB to solve systems of nonlinear ODEs?

Yes, MATLAB can be used to solve systems of nonlinear ODEs. The ode45 function is a robust solver that can handle both linear and nonlinear systems. However, depending on the complexity of your equations, you may need to use a different solver or adjust the tolerances to ensure accurate results.

5. How can I check the accuracy of my solution when solving two ODEs simultaneously using MATLAB?

You can check the accuracy of your solution by comparing it to a known analytical solution, if one exists. You can also adjust the error tolerances in the ode45 function to see how it affects the accuracy of your solution. Additionally, you can plot the solution with different step sizes to see if the results are consistent.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
896
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
742
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
999
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
991
  • Advanced Physics Homework Help
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • Introductory Physics Homework Help
Replies
5
Views
3K
Back
Top