Multiple parameters optimization having calculated and experimental values

Hello everyone, I have a function that have to predict Hc and I have the Hcexperimental values. What I need to do, is optimize the 6 parameters that are in the function; so that the relative deviation between the calculated and experimental values becomes the smallest possible. I don't know if I need fmin, lsqnonlin, lsqcurvefit... I also don't know if I need multiple function files (.M files) to accomplish this. So far I've writen this:
function Hc = myfunction( P_k, T_k, c, z, w, v, IFexp )
y=T_k;
q=length(P_k);
%Initial values for parameters
par1=0.1442;
par2=2.6388;
par3=2.2083;
par4=0.2168;
par5=0.2;
par6=0.4;
%Ecuations
a=1.28+55.*(1./P_k+0.04).*exp(50.22./(T_k+230));
g=0.4+2084.69.*(1./P_k-0.002).*exp((-986.95)./(T_k+230));
x=(g./a).*c;
Hc=par1.*(x.^par2).*(y.^par3).*(z.^par4).*exp(par5.*w).*exp
(par6.*v);
disp(Hc)
RD=(IFexp-IFc)./IFexp.*100;
disp(RD)
ARD=100*(sum(RD))/q;
disp(ARD)
end
If someone could explain it to me detailed or show me an example with a script or even modify the script if needed; I'd be really grateful.

 Respuesta aceptada

Torsten
Torsten el 7 de Sept. de 2018
Editada: Torsten el 7 de Sept. de 2018
function main
P_k = ...;
Hcexp = ...;
T_k = ...;
z = ...;
w = ...;
v = ...;
c = ...;
a = 1.28+55.*(1./P_k+0.04).*exp(50.22./(T_k+230));
g = 0.4+2084.69.*(1./P_k-0.002).*exp((-986.95)./(T_k+230));
x = (g./a).*c;
p0 = [0.1442;2.6388;2.2083;0.2168;0.2;0.4];
p = lsqnonlin(@(p)fun(p,x,T_k,z,w,v,Hcexp),p0)
end
function res = fun(p,x,y,z,w,v,Hcexp)
Hc = p(1).*x.^p(2).*y.^p(3).*z.^p(4).*exp(p(5).*w).*exp(p(6).*v);
res = (Hc-Hcexp)./Hcexp;
end
Best wishes
Torsten.

6 comentarios

Thank you very much! Sorry to bother you @Torsten, but how can I display the last optimized value for each parameter?
If you use the above code, the final parameters will be displayed automatically.
Last question if possible @Torsten. I need all the parameters to be positive, I added:
function main
P_k = ...;
Hcexp = ...;
T_k = ...;
z = ...;
w = ...;
v = ...;
c = ...;
a = 1.28+55.*(1./P_k+0.04).*exp(50.22./(T_k+230));
g = 0.4+2084.69.*(1./P_k-0.002).*exp((-986.95)./(T_k+230));
x = (g./a).*c;
lb=[0,0,0,0,0,0];
ub=[inf,inf,inf,inf,inf,inf]
p0 = [0.1442;2.6388;2.2083;0.2168;0.2;0.4];
p = lsqnonlin(@(p)fun(p,x,T_k,z,w,v,Hcexp),p0,lb,up)
end
function res = fun(p,x,y,z,w,v,Hcexp)
Hc = p(1).*x.^p(2).*y.^p(3).*z.^p(4).*exp(p(5).*w).*exp(p(6).*v);
res = (Hc-Hcexp)./Hcexp;
end
But it says that there are more variables than ecuations so the solver is going to ignore the bounds. Is there anything I can do to have only positive parameters?
Use "ub" instead of "up" in the call to lsqnonlin.
@Torsten sorry, I did write "ub" instead of "up", but it has the same warning "Cannot solve problems with fewer equations than variables and with bounds. An error will be issued for this case in a future release. Ignoring bounds, using Levenberg-Marquardt method. "
Then the warning says that it does not make sense to fit six parameters if you have less than six data points Hcexp.
And this warning is justified.
Best wishes
Torsten.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 7 de Sept. de 2018

Comentada:

el 11 de Sept. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by