estimating parameters by lsqcurvfit
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Good afternoon sir
sir please tell me how to draw graph for infected data vs predicted for this lscurvefit code.
i wrote code like this
plot(time,infected ,time,Cv) but it shows error sir.
code is
data = [ 1 25
2 75
3 227
4 296
5 258
6 236
7 192
8 126
9 71
10 28
11 11
12 7];
time = data(1:12,1);
infected= data(1:12,2);
beta0 = 1;
lamdaa0= 0.019;
lamdas0= 0.0715;
etas0 = 0.03;
etaq0 = 0.04;
gammaa0 = 0.2;
gammaq0 = 0.13;
gammah0 = 0.07;
mua0 = 0.0001;
muh0 = 0.0002;
lb =[0,0,0,0,0,0,0,0,0,0]; ub = [1,1,1,1,1,1,1,1,1,1];
B0 = [beta0; lamdaa0; lamdas0; etas0; etaq0; gammaa0; gammaq0; gammah0; mua0; muh0 ];
options=optimset('MaxFunEvals', 10000, 'MaxIter', 10000, 'TolFun', 0.0001, 'TolX',0.0001,'Display','on');
[B,resnorm,RESIDUAL,exitflag,OUTPUT,LAMBDA,Jacobian] = lsqcurvefit(@diff1,B0,time,infected,lb,ub,options);
disp(B)
%plot(time,infected,time,C)
function C = diff1(B,time)
x0 = [1217378052,120,3,2,1,1,0,0];
[t,Cv] = ode45(@DifEq, time, x0);
function dC = DifEq(t, x)
N = 1390000000;
pi = 700 ;
zetaa = 0.1;
zetas = 0.2;
zetaq = 0.3;
zetah = 0.3;
omega = 0.2;
theta = 0.5;
mu = 0.0000425;
beta = B(1);
lamdaa= B(2);
lamdas = B(3);
etas = B(4);
etaq = B(5);
gammaa = B(6);
gammaq = B(7);
gammah = B(8);
mua = B(9);
muh = B(10);
xdot = zeros(7,1);
xdot(1) = pi -beta*(zetaa*x(3) +zetas*x(4) +zetaq*x(5)+zetah*x(6))*(x(1)/N) -mu*x(1);
xdot(2) = beta*(zetaa*x(3) +zetas*x(4) +zetaq*x(5)+zetah*x(6))*(x(1)/N) -(omega+mu)*x(2);
xdot(3) = theta*omega*x(2)-(lamdaa+gammaa+mua+mu)*x(3);
xdot(4) = (1-theta)*omega*E-(lamdas+etas+mu)*x(4);
xdot(5) = lamdaa*Ia+lamdas*Is-(etaq+gammaq+mu)*x(5);
xdot(6) = etas*Is+etaq*Q- (gammah+muh+mu)*x(6);
xdot(7) = gammaa*x(4) + gammaq*x(5) + gammah*x(6)
end
C = Cv(:,2);
plot(time,infected ,time,Cv)
end
Error is
Unrecognized function or variable 'infected'.
Error in lscurvfit6>diff1 (line 72)
plot(time,infected ,time,Cv)
Error in lsqcurvefit (line 225)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in lscurvfit6 (line 19)
[B,resnorm,RESIDUAL,exitflag,OUTPUT,LAMBDA,Jacobian] = lsqcurvefit(@diff1,B0,time,infected,lb,ub,options);
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.
0 Kommentare
Antworten (2)
Torsten
am 29 Apr. 2022
Bearbeitet: Torsten
am 29 Apr. 2022
Although this has been answered several times already, here we go again:
data = [ 1 25
2 75
3 227
4 296
5 258
6 236
7 192
8 126
9 71
10 28
11 11
12 7];
time = data(1:12,1);
infected= data(1:12,2);
beta0 = 1;
lamdaa0= 0.019;
lamdas0= 0.0715;
etas0 = 0.03;
etaq0 = 0.04;
gammaa0 = 0.2;
gammaq0 = 0.13;
gammah0 = 0.07;
mua0 = 0.0001;
muh0 = 0.0002;
lb =[0,0,0,0,0,0,0,0,0,0]; ub = [1,1,1,1,1,1,1,1,1,1];
B0 = [beta0; lamdaa0; lamdas0; etas0; etaq0; gammaa0; gammaq0; gammah0; mua0; muh0 ];
options=optimset('MaxFunEvals', 10000, 'MaxIter', 10000, 'TolFun', 0.0001, 'TolX',0.0001,'Display','on');
[B,resnorm,RESIDUAL,exitflag,OUTPUT,LAMBDA,Jacobian] = lsqcurvefit(@diff1,B0,time,infected,lb,ub,options);
C = diff1(B,time);
plot(time,[infected,C])
function C = diff1(B,time)
x0 = [1217378052,120,3,2,1,1,0,0];
[t,Cv] = ode45(@DifEq, time, x0);
function dC = DifEq(t, x)
N = 1390000000;
pi = 700 ;
zetaa = 0.1;
zetas = 0.2;
zetaq = 0.3;
zetah = 0.3;
omega = 0.2;
theta = 0.5;
mu = 0.0000425;
beta = B(1);
lamdaa= B(2);
lamdas = B(3);
etas = B(4);
etaq = B(5);
gammaa = B(6);
gammaq = B(7);
gammah = B(8);
mua = B(9);
muh = B(10);
xdot = zeros(7,1);
xdot(1) = pi -beta*(zetaa*x(3) +zetas*x(4) +zetaq*x(5)+zetah*x(6))*(x(1)/N) -mu*x(1);
xdot(2) = beta*(zetaa*x(3) +zetas*x(4) +zetaq*x(5)+zetah*x(6))*(x(1)/N) -(omega+mu)*x(2);
xdot(3) = theta*omega*x(2)-(lamdaa+gammaa+mua+mu)*x(3);
xdot(4) = (1-theta)*omega*E-(lamdas+etas+mu)*x(4);
xdot(5) = lamdaa*Ia+lamdas*Is-(etaq+gammaq+mu)*x(5);
xdot(6) = etas*Is+etaq*Q- (gammah+muh+mu)*x(6);
xdot(7) = gammaa*x(4) + gammaq*x(5) + gammah*x(6)
end
C = Cv(:,2);
end
Walter Roberson
am 29 Apr. 2022
infected= data(1:12,2);
You do that assignment once, before any function calls.
You do call
[B,resnorm,RESIDUAL,exitflag,OUTPUT,LAMBDA,Jacobian] = lsqcurvefit(@diff1,B0,time,infected,lb,ub,options);
but there, infected is going to become the ydata for curve fitting purposes; that copy of infected is not going to be passed to any lower level under the name infected
plot(time,infected ,time,Cv)
You are inside function diff1 . infected is not a defined variable there.
Perhaps you were thinking of somehow passing it in to function diff1() so that they could be used for plotting purposes -- that could be done by parameterizing the @diff1 call.
You do some funny things with time vs t in the plot(), but that should be okay... unless, that is, the ode*() call stopped early. It would be better to plot t,Cv than time,Cv in case the full time span does not get covered.
Siehe auch
Kategorien
Mehr zu Biological and Health Sciences finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!