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
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?
 
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
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · 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