Troubleshooting ODE Systems in MATLAB: Common Errors and Solutions

In summary, the conversation discusses a problem with implementing an ODE system in MATLAB. Two examples are given and the user is struggling with the syntax and input arguments for the ODE function. The user is trying to solve a system of equations involving NO2, NH2O, a, b, and g. They have attempted to create a function and call the ODE function, but are unsure if their approach is correct. They are looking for assistance with the syntax and input arguments.
  • #1
Ultimato
5
0
Hi to everyone, I have some problem in implementing a ODE system in matlab.

function dC = Model(x,C)
dC = zeros(2,1);
dC(1) = -2/C(1) -3*dC(2);
dC(2) = -3/C(2) -4*dC(1);
[x,C] = ode23(@Model(x,C),[0 300],[56.9 0]);
plot(x,C)

The debugger says

"? Input argument "C" is undefined.

Error in ==> HTPEMModel at 3
dC(1) = -2/C(1) -3*dC(2);"

I have tried also one of the examples in the help of MATLAB and gives me the same error:

function dy = rigid(t,y)
dy = zeros(3,1); % a column vector
dy(1) = y(2) * y(3);
dy(2) = -y(1) * y(3);
dy(3) = -0.51 * y(1) * y(2);
[T,Y] = ode45(@rigid,[0 12],[0 1 1]);
plot(T,Y(:,1),'-',T,Y(:,2),'-.',T,Y(:,3),'.')

gives me:

"? Input argument "y" is undefined.

Error in ==> rigid at 3
dy(1) = y(2) * y(3);"

What's my mistake?
 
Physics news on Phys.org
  • #3
I think that I've solved it, the ode function must be in another "worksheet" to run; now works :)
 
  • #4
Sorry for the disturb but I have some problem with the syntax

With this system of equation:

NO2 = a*Co2' - g*Co2*(-Co2' - Ch2o')
NH2O = b*Ch2o' - g*Ch2o*(-Co2' - Ch2o')

where NO2, NH2O, a, b, g are known

Is correct to write in Matlab:

Code:
function dC = HTPEMMode(x,C)
global A B G NO2 NH2O
dC = zeros(2,1);
dC(1) = (NO2/A-B/A*C(1)*dC(2))*((1+B/A*C(1))^-1);
dC(2) = (NH2O/G-B/G*C(2)*dC(1))*((1+B/G*C(2))^-1);
end

and for solving that system call in this way:

Code:
[x,C] = ode23(@HTPEMMode,[0 0.0003],[CO2in 0]);

x growing from 0 to 0.0003 and initial Condition are for Co2 CO2in and for Ch2o 0
 
  • #5
Should I explain something else?
 
  • #6
Can you help me with this please?
 

Related to Troubleshooting ODE Systems in MATLAB: Common Errors and Solutions

1. What is an ODE system in MATLAB?

An ODE system in MATLAB refers to a set of ordinary differential equations that can be solved using the built-in ODE solvers in MATLAB. These equations typically describe the rate of change of one or more variables over time.

2. How do I define an ODE system in MATLAB?

To define an ODE system in MATLAB, you need to create a function file that represents the equations in your system. This function file should take in the variables and their initial values as inputs and return the values of the derivatives of those variables at a given time point.

3. What are some common errors when working with ODE systems in MATLAB?

Some common errors when working with ODE systems in MATLAB include using incorrect syntax or variable names, not defining the initial values of the variables, and not specifying the time span over which to solve the equations.

4. How do I solve an ODE system in MATLAB?

To solve an ODE system in MATLAB, you can use the built-in ODE solvers such as ode45, ode23, or ode15s. These solvers use different algorithms to approximate the solutions to the equations in your system. You can also specify the desired accuracy and time span for the solution.

5. Can I plot the solution to an ODE system in MATLAB?

Yes, you can plot the solution to an ODE system in MATLAB using the plot function. You can specify which variables to plot and which time points to use for the x-axis. You can also add labels, titles, and legends to your plot to make it more informative and visually appealing.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
231
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
221
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top