Info

This question is closed. Reopen it to edit or answer.

unable to link the files? showing error matrix dimension

1 view (last 30 days)
function dc = dialysis(t, c1, c2)
global k
v1=0.7*33.2; % intra cellular volume [liter]
v2=0.3*33.2; % extra cellular volume [liter]
% c1=0.63; % urea concentration in intracellular fluid [g/ltr]
% c2=0.63; % urea concentration in extra cellular fluid [g/ltr]
% c=[c1;c2];
g=0.18; %urea production rate[g/hr]
b=4.6; %dialysis blood flow [L/hr]
% t=0:1:99; % time interval [in hours]
% k=20:1:120; % mass transfer [ltr/hr]
dc1=(g-k*(c1-c2))./v1; % first differential equation
if ((t>=1) && (t<=3)) || ((t>=25) && (t<=27)) || ((t>=49) && (t<=51)) || ((t>=73) && (t<=75)) || ((t>=97) && (t<=99))
dc2=(k.*(c1-c2)-b*c2)./v2;% second differential equation
else
dc2=(k.*(c1-c2))./v2;
end
dc=[dc1,dc2]
end
% file 2
DIALTABL=xlsread('DIALTABL.xlsx')
clear all;
v1=0.7*33.2; % intra cellular volume [liter]
v2=0.3*33.2; % extra cellular volume [liter]
c1=0.63; % urea concentration in intracellular fluid [g/ltr]
c2=0.63; % urea concentration in extra cellular fluid [g/ltr]
c=[c1 c2];
g=0.18; %urea production rate[g/hr]
b=4.6; %dialysis blood flow [L/hr]
t=0:1:99; % time interval [in hours]
global k; % mass transfer [ltr/hr]
k=30
[tn,yn]=ode23('dialysis',[0,99],[c1,c2]);
plot(DIALTABL(:,n))
  3 Comments
rama tallapareddy
rama tallapareddy on 18 Jul 2015
Is this good for u? i need to call the function in the dialysis file and got an error for dc1 matrix dimension doesn't agree and problem with ode23.
Star Strider
Star Strider on 18 Jul 2015
This isn’t a complete Answer (I don’t understand your code and especially the if block), so I’m not listing it as one.
First, please read the documentation on the function format you have to use with the ODE integration functions. And don’t use globals.
See if changing the first three lines of your ODE function to:
function dc = dialysis(t, c, k)
c1 = c(1);
c2 = c(2);
...rest of code ...
then the function you use in your ode23 call is:
[tn,yn]=ode23(@(t,c) dialysis(t,c,k),[0,99],[c1,c2]);
The if block creates nonlinear discontinuities in your differential equation that ode23 will attempt to deal with. (Please be kind to ode23 and its friends. Don’t give them discontinuous functions to integrate.) The best way is instead to create two separate differential equation function files, integrate each of them across the appropriate time vectors, saving the last values of the previous integration to be the initial conditions of the subsequent integration.
This should get you started.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!