Error Function value and YDATA sizes are not equal using lsqcurvefit

2 visualizzazioni (ultimi 30 giorni)
I'm new in mathlab and i'm trying to solve a system of 13 differential equations. This system is a Pharmacokinetic in 13 different organs; I want to fit experimental time vs plasmatic concentration data with the output values and estimating some parameteres (two elimination constants K(1) and K(2)). I've tryed two codes, the fist one with a calling program, and the second one with all in the same program; both attempts return the same error. This is the code for one of the attempts
calling program:
K0 = [1;14];
t=[5;15;30;60];
c=[11.46;21.24;3.35;4.53];
[K,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(@ajuste_coc_cor_2,K0,t,c);
fprintf(1,'\tConstants:\n')
for k1 = 1:length(K)
fprintf(1, '\t\tK(%d) = %8.5f\n', k1, K(k1))
end
tv = linspace(min(t), max(t));
Cfit = ajuste(K, tv);
figure(1)
plot(t, c, 'p')
hold on
hlp = plot(tv, Cfit);
hold off
grid
xlabel('Time')
ylabel('Concentration')
legend(hlp, 'C_1(t)', 'C_2(t)', 'C_3(t)', 'C_4(t)','C_5(t)','C_6(t)','C_7(t)','C_8(t)','C_9(t)','C_10(t)','C_11(t)','C_12(t)','C_13(t)','Location','N')
The other file:
% K(1)= constante de eliminación en hígado
% K(2)= constante de eliminación plasmática
% le quité los valores de 120 y 240 min para que corra más rápido
function C=ajuste_coc_cor_2(K,t)
CLr=0.0441;
Pb=4.47176966;
Pcer=1.3191;
Pcor=3.3789;
Pf=7.2458;
Ph=6.1711;
Phu=1.2509;
Pint=3.7487;
Plu=5.4719;
Pm=2.4497;
Pp=2.53282;
Pr=6.7441;
Qb=0.0017;
Qc=0.0831;
Qcer=0.0017;
Qcor=0.0041;
Qf=0.0058;
Qh=0.0145;
Qha=0.0019;
Qhu=0.0101;
Qint=0.0109;
Qlu=0.0831;
Qm=0.0231;
Qp=0.0048;
Qr=0.0117;
Va=0.0065;
Vb=5.0000e-04;
Vcer=0.0014;
Vcor=8.0000e-04;
Vf=0.0207;
Vh=0.0092;
Vhu=0.0052;
Vint=0.0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(Qcor*(c(6)/Pcor))+(Qr*(c(10)/Pr))+(Qcer*(c(11)/Pcer))+(Qh*(c(9)/Ph))-(Qc*c(12))-((K(2)*c(12))/Vv))/Vv;
dcdt(13)=(Qlu*(c(12)-(c(13)/Plu)))/Vlu;
dC=dcdt;
end
C=Cv(:,12);
end
This is the message I get:
Error using lsqcurvefit (line 251)
Function value and YDATA sizes are not equal.
Error in cocaine_corto_script (line 4)
[K,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(@ajuste_coc_cor_2,K0,t,c);
I can not find the mistake! please help!

Risposte (0)

Prodotti


Release

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by