Matlalb problem with two first order ODEs

In summary, the conversation discusses two questions regarding plotting first and second order ODEs in MATLAB. The first question involves plotting one first order ODE versus another, while the second question involves solving two second order ODEs by making substitutions and creating first order ODEs. The conversation also mentions an attempt at a solution using the plot function, but encountering an error due to an undefined variable.
  • #1
sara_87
763
0

Homework Statement



I have two questions:
1) If i have two first order ODE y(1) and y(2) (in terms of time), i know how to plot y(1) versus time and y(2) versus time but i don't know how to plot y(2) versus y(1)

2)I have two second order ODES X''=... and Z''=... to solve this, we make the substitutions y(1)=X, y(2)=X', y(3)=Z, and y(4)=Z'
then we have two first order ODEs: y(2)'=... and y(4)'=...
I typed this into Matlab (dydt=[(the equation for y(2)'; the equation for y(4)']) but an error came up since i didnt define y(4). how do i do this?
2. Homework Equations



3. The Attempt at a Solution
1) i tried putting:
plot(y(1),y(:,2)), and i also tried plot(y(1),y(2)) but these didnt work.


Any help would be very much appreciated.
Than you.
 
Physics news on Phys.org
  • #2
1) plot(y(:,1),y(:,2)) ought to work, assuming you just left out the iterate through all rows part in the first column.

2) Can you post your exact system of equations function?
 
  • #3


I would first suggest reviewing the basics of plotting in Matlab and understanding how to plot multiple variables on the same graph. This can be achieved using the "hold on" and "plot" commands, as well as specifying the x and y variables in the plot function. Additionally, it may be helpful to review the concepts of dependent and independent variables in plotting.

For the second question, it seems that the error may be due to not defining the initial conditions for the y(4) variable. In order to solve the first order ODEs, initial conditions must be specified for all variables. I would suggest double checking the equations and initial conditions, and possibly consulting with a professor or TA for further assistance.

Overall, it is important to have a strong understanding of the mathematical concepts behind the ODEs and how they relate to each other in order to effectively solve and plot the solutions. It may also be helpful to consult with a math or physics tutor for additional guidance and practice.
 

1. What is Matlab?

Matlab is a high-level programming language and interactive environment commonly used by scientists and engineers for data analysis, visualization, and mathematical computations.

2. What is an ODE?

An ODE, or ordinary differential equation, is a mathematical equation that describes the relationship between a variable and its derivatives. In other words, it shows how a quantity changes over time.

3. What is a first order ODE?

A first order ODE is an ODE where the highest derivative of the variable is of first order. This means that the rate of change of the variable is directly dependent on the current value of the variable itself, rather than on higher order derivatives.

4. What are the common problems encountered when solving two first order ODEs in Matlab?

Some common problems include incorrect syntax, incorrect initial conditions or boundary conditions, and issues with the chosen numerical method for solving the ODEs.

5. How can I troubleshoot and solve a Matlab problem with two first order ODEs?

To troubleshoot and solve a Matlab problem with two first order ODEs, you can check for errors in your code, ensure that your initial and boundary conditions are correct, and try using a different numerical method for solving the equations. It can also be helpful to consult online resources or seek assistance from a Matlab expert.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
985
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
536
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top