ode45 function error: function must return a coloumn vector. how can i run this?
Show older comments
plz help me.my editor is same as this:
function xdot = vanvusse(t,x) % % (c) b.w. bequette % 25 july 94 % revised 20 july 96 % % dynamic model for the van de vusse reaction % % to use this function file with ode45: % % [t,x] = ode45('vanvusse',t0,tf,x0) % % where t0 is the initial time (usually 0) % tf is the final time % x0 is the initial condition for the states % % x = states % x(1) = concentration of A % x(2) = concentration of B % t = time % % fov = dilution rate % ca = concentration of a % cb = concentration of b % caf = feed concentration of a % % the reaction scheme is % % A --> B --> C % (k1) (k2) % 2A --> D % (k3) % k1 = 5/6; % rate constant for A --> B (min^-1) k2 = 5/3; % rate constant for B --> C (min^-1) k3 = 1/6; % rate constant for A + A --> D (mol/(liter min)) caf = 10; % feed concentration of A, mol/liter % % for step changes in fov, use the following % fov = 4/7 + delf; % % use familiar notation for the states % ca = 2; cb = 1.117; fov = 4/7; % % modeling equations % dcadt = fov*(caf - ca) -k1*ca - k3*ca*ca; dcbdt = -fov*cb + k1*ca - k2*cb;
% % derivatives placed in vector notation % xdot(1) = dcadt; xdot(2) = dcbdt; % end of file
then i wrote at command window this:
[t,x]=ode45('vanvusse',[0,5],[0 0]);
and I see that warning on matlab.
??? Error using ==> odearguments at 113 VANVUSSE must return a column vector.
Error in ==> ode45 at 173 [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
I wanna plot(t,x) but ode is not working. how do i run this ?
Answers (2)
Mischa Kim
on 14 Mar 2014
Edited: Mischa Kim
on 14 Mar 2014
Tugce, either add
xdot = zeros(2,1);
right before you start assigning values to the two xdot components, or, rewrite the two scalar equations for xdot(1) and xdot(2) as a vector equation:
xdot = [dcadt;...
dcbdt];
1 Comment
Mischa Kim
on 17 Mar 2014
Edited: Mischa Kim
on 17 Mar 2014
If I run the code I do get non-constant output. In fact you get linearly increasing function values, which is to be expected because the derivatives ( dcadt, dcbdt ) are constants.
function test()
[t,X] = ode45(@vanvusse,[0,5],[0 0]);
plot(t,X(:,1),t,X(:,2))
end
function xdot = vanvusse(t,x)
k1 = 5/6; k2 = 5/3;
k3 = 1/6; caf = 10;
fov = 4/7 + 0; % delf not defined, set to zero
ca = 2; cb = 1.117;
fov = 4/7;
dcadt = fov*(caf - ca) - k1*ca - k3*ca*ca;
dcbdt = -fov*cb + k1*ca - k2*cb;
xdot = [dcadt; ...
dcbdt];
end
Copy-paste the above code into one m-file, name it test.m and run it.
Also, please post follow-up questions and comments as comments , not answers.
tugce
on 14 Mar 2014
0 votes
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!