필터 지우기
필터 지우기

problem with fminsearch and parameters estimation

조회 수: 1 (최근 30일)
Ewa Kozub
Ewa Kozub 2013년 7월 16일
function [to,yo]=magda_ewa
clc
clear all
close all
global Vg Vi Rinf Cinf Gg gamma lambda alfa C1 a1 Rm Ki Kg Tinf UFR m Gd time meang meani
UFR=3/240; %0.004166667; %[L/min]
Gd=5.615292712;
Rinf=60/1000; %[L/min]
Vinf=0.5*m*100/(33*1000); %[L]
Cinf=33/180.16*1000*1000/100; %[mmol/L]
Tinf=Vinf/Rinf; %[min]
Go=5.62;
Io=4.3;
Gg=0.1751; %[mmol/min]
lambda=0.00993; %[L/min]
alfa=0.01855; %[L/min]
C1=23.9395; %[mmol/L]
a1=0.228339456; %[mmol/L]
Rm=968.8786; %[mU/min]
m=78; %[kg]
Vg=11.4587; %[L]
Vi=3.1201; %[L]
time=[0 10 20 30 40 60];
meang=[5.62 19.12 14.76 12.07 10.57 7.95];
meani=[4.3 33.98 24.64 19.03 15.38 14.84];
[to yo]=ode45('model_magda',0:60,[Go Io]);
[to yo(:,1) yo(:,2)];
--------------------------------------
function F=model_magda(t,y)
F=zeros(2,1);
global Vg Vi Rinf Cinf Gg gamma lambda alfa C1 a1 Rm Ki Kg Tinf UFR Gd Vglucose Vinsulin
if t<Tinf
Ginf=Rinf*Cinf;
else
Ginf=0;
end;
for t=1:61
Vglucose(t)=Vg-UFR*(t-1);
Vinsulin(t)=Vi-UFR*(t-1);
F(1)=(Gg-gamma*y(1)*y(2)-lambda*y(1)+Ginf-Kg*(y(1)-Gd)+y(1)*UFR)/Vglucose(t);
F(2)=(Rm/(1+exp((C1-y(1))/a1))-alfa*y(2)-Ki*y(2))/Vinsulin(t);
end
----------------------------
function f=minimum(par)
global gamma %lambda alfa C1 a1 Rm Vg Vi Gg time meang meani
gamma=par(1);
[to,yo]=magda_ewa;
f=0;
for i=1:6
c(i)=(abs(meani(i) - yo((time(i)+1),2))/meani(i))+(abs(meang(i) -
yo((time(i))+1,1))/meang(i));
f=f+c(i);
i=i+1;
end
end
---------------------
clear all
close all
[wynik,c]=fminsearch(@minimum,0.003);
gamma=wynik(1)
This is my program and when i try to run it i get this comment :
??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
Error in ==> model_magda at 24
F(1)=(Gg-gamma*y(1)*y(2)-lambda*y(1)+Ginf-Kg*(y(1)-Gd)+y(1)*UFR)/Vglucose(t);
Error in ==> odearguments at 98
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ==> ode45 at 172
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in ==> magda_ewa at 211
[to yo]=ode45('model_magda',0:60,[Go Io]);
Error in ==> minimum at 15
[to,yo]=magda_ewa;
Error in ==> fminsearch at 191
fv(:,1) = funfcn(x,varargin{:});
Error in ==> optymalizacja at 3
[wynik,c]=fminsearch(@minimum,0.003);
before used fminsearch everything was ok I didn't have problems with number of elements in matrix....Please help me because i don't known wher the mistake is
  댓글 수: 1
Matt J
Matt J 2013년 7월 16일
편집: Matt J 2013년 7월 16일
Please use the "{} Code" formatting tool, so that we can distinguish your code/errors from text with less strain.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2013년 7월 16일
편집: Matt J 2013년 7월 16일
Error in model_magda at 24
Some of your variables are empty/undefined in model_magda:
K>> whos Kg Ki Tinf gamma
Name Size Bytes Class Attributes
Kg 0x0 0 double global
Ki 0x0 0 double global
Tinf 0x0 0 double global
gamma 0x0 0 double global
Using global variables is probably a bad idea. See here for better options
Using "clear all" while using globals is probably making things worse.
  댓글 수: 2
Ewa Kozub
Ewa Kozub 2013년 7월 17일
thanks for your answer :) i'm quite new in Matlab and could you tell me how you check those parameters (Kg, Ki Tinf, gamma)?. And when i want to use function in this way F = model_magda(Vg Vi Rinf Cinf Gg gamma lambda alfa C1 a1 Rm Ki Kg Tinf UFR Gd Vglucose Vinsulin ) I get information :too many input arguments
Matt J
Matt J 2013년 7월 17일
편집: Matt J 2013년 7월 17일
could you tell me how you check those parameters (Kg, Ki Tinf, gamma)?
By using the dbstop command. In particular
>> dbstop if error
will halt program execution right at the point in the code where an error occurs, so you can inspect the state of the workspace variables at that moment.
I get information :too many input arguments
You have to rewrite
function F=model_magda(t,y)
so that it knows to expect more than just t and y as inputs.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by