Clear Filters
Clear Filters

Multiple parameters optimization having calculated and experimental values

2 views (last 30 days)
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.

Accepted Answer

Torsten
Torsten on 7 Sep 2018
Edited: Torsten on 7 Sep 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 Comments
Eduardo Chacin
Eduardo Chacin on 10 Sep 2018
@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. "
Torsten
Torsten on 11 Sep 2018
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!