Troubleshooting ODE Systems in MATLAB: Common Errors and Solutions

  • Context: MATLAB 
  • Thread starter Thread starter Ultimato
  • Start date Start date
  • Tags Tags
    Ode Ode system System
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting issues encountered while implementing ordinary differential equation (ODE) systems in MATLAB. Participants share their experiences with error messages, syntax problems, and the structure of their code related to ODE functions.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant describes an error message indicating that the input argument "C" is undefined in their ODE function, suggesting a potential issue with how the function is defined or called.
  • Another participant asks for clarification on the original differential equation being implemented, indicating a need for context to better understand the problem.
  • A participant claims to have resolved their issue by moving the ODE function to a different "worksheet," implying that the location of the function may affect its accessibility.
  • Another participant presents a new system of equations and questions the correctness of their MATLAB syntax for defining the ODE function, including the use of global variables.
  • One participant asks if they need to provide additional explanations, indicating a willingness to clarify their previous statements or code.
  • A later post requests help with the syntax or implementation, suggesting ongoing confusion or difficulty with the MATLAB code.

Areas of Agreement / Disagreement

The discussion reflects a lack of consensus on the correct implementation of ODE systems in MATLAB, with multiple participants expressing different issues and solutions without a clear resolution.

Contextual Notes

Some participants' code snippets may contain unresolved syntax issues or logical errors, and there is uncertainty regarding the correct structure and calling of ODE functions in MATLAB.

Ultimato
Messages
5
Reaction score
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
I think that I've solved it, the ode function must be in another "worksheet" to run; now works :)
 
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
 
Should I explain something else?
 
Can you help me with this please?
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K