Help in solving a system of ODEs using MATLAB

In summary, make sure to fix the typo in your m-file function name, specify initial conditions for the system of ODEs, and use the "plot" function to plot the desired graphs.
  • #1
jcsolis
38
1
Hello, I have been trying to solve this problem and the only thing I got is errors and errors. Also I need to plot y versus t, y' versus t and y' versus y??

Homework Statement



The system of ODEs

y1'= y2
y2'= -2y1-0.03y13

The time span is [0:0.1:5]
and there are no initial conditions!

Need to be solved using ODE45 solver



Homework Equations



None


The Attempt at a Solution



I created this m-file

function yprime = syst1(t, y)
yprime = [y(2); -2*y(1)-0.03*(y(1))^3];

then in the command window

tspan=[0:01:5]
[t y]=oder45 ('syst1', tspan)


and then nothing comes out. I have found many examples of solving systems of ODEs but all of them with initial conditions which is not my case. Can someone explain me waht I am doing wrong?

Than You
 
Physics news on Phys.org
  • #2


Hello,

Thank you for reaching out for help with your problem. It sounds like you are on the right track, but there are a few things that may be causing errors in your code.

First, in your m-file, you have a typo in the function name. It should be "ode45" instead of "oder45". This could be causing the code to not run properly.

Second, you mentioned that there are no initial conditions given for the system of ODEs. However, the ode45 solver requires initial conditions to solve the system. You will need to specify some initial conditions for y1 and y2 in order for the code to run successfully. These initial conditions can be specified as the third input to the ode45 function, in the form of a vector [y1(0); y2(0)].

Finally, to plot y versus t, y' versus t, and y' versus y, you can use the "plot" function after solving the system. For example, to plot y versus t, you can use the command "plot(t,y(:,1))", where y(:,1) is the first column of the y matrix returned by the ode45 solver.

I hope this helps and good luck with your problem! Let me know if you have any further questions.
 

1. How do I define the differential equations in MATLAB?

To define a system of ordinary differential equations (ODEs) in MATLAB, you can use the function odefun. This function takes in the dependent variable, independent variable, and any additional parameters as inputs, and returns the derivative of the dependent variable with respect to the independent variable. You can then use this function in the ode45 solver to integrate the ODEs over a specified time interval.

2. What is the difference between the ode45 and ode23 solvers in MATLAB?

The ode45 solver in MATLAB is a variable-step, fifth-order Runge-Kutta method, while the ode23 solver is a variable-step, third-order Runge-Kutta method. This means that ode45 is more accurate but may take longer to compute, while ode23 is less accurate but faster. The choice between the two solvers depends on the specific problem and the desired trade-off between accuracy and speed.

3. How can I plot the solution of a system of ODEs in MATLAB?

To plot the solution of a system of ODEs in MATLAB, you can use the ode45 solver to compute the solution over a specified time interval. Then, you can use the plot function to plot the dependent variables against the independent variable. It is also possible to plot the solution in 3D using the plot3 function if the system of ODEs has three dependent variables.

4. Can I solve a system of ODEs with initial conditions in MATLAB?

Yes, you can solve a system of ODEs with initial conditions in MATLAB using the ode45 solver. The initial conditions should be specified as a vector in the input to the solver. You can also use the ode23 solver to solve the system of ODEs with initial conditions, but it may not be as accurate as ode45.

5. How can I use MATLAB to solve a system of ODEs with parameters?

To solve a system of ODEs with parameters in MATLAB, you can define the parameters as variables in your odefun function. Then, you can pass these parameters as inputs to the ode45 solver. This allows you to solve the system of ODEs for different values of the parameters without having to rewrite the odefun function each time.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • Calculus and Beyond Homework Help
Replies
3
Views
330
  • Calculus and Beyond Homework Help
Replies
11
Views
960
  • Math POTW for University Students
Replies
10
Views
1K
  • Calculus and Beyond Homework Help
Replies
12
Views
1K
  • Calculus and Beyond Homework Help
Replies
7
Views
2K
  • Differential Equations
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
996
  • Calculus and Beyond Homework Help
Replies
2
Views
1K
  • Calculus and Beyond Homework Help
Replies
2
Views
2K
Back
Top