MATLAB Troubleshooting ODE Systems in MATLAB: Common Errors and Solutions

AI Thread Summary
The discussion centers on troubleshooting issues with implementing an ordinary differential equation (ODE) system in MATLAB. The initial problem arises from an undefined input argument error when attempting to define the derivatives in the function. The user discovers that the ODE function needs to be properly structured and called within the correct context to avoid these errors. After resolving the initial issues, the user presents a new system of equations involving variables NO2, NH2O, and constants a, b, and g. The user seeks confirmation on the correctness of their MATLAB implementation of this system. The proposed function HTPEMMode is structured to calculate derivatives based on the defined equations, and the user plans to solve it using the ode23 function with specified initial conditions. The discussion highlights the importance of proper function syntax and context in MATLAB for successful ODE implementation.
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

Back
Top