Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
How to use fminsearch for my code
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello everyone, I am new in MATLAB. Please help me find out my problem.
I prepared a code that aimed at finding parameters to fit the data. (data is recorded temperature vs. time)
it is work by changing that three parameters manually but I would like to use fminsearch but always faild!
Thanks in advance.
here is my code (the objective is RMSE):
close all, clear all, clc
load GHE1_6kW_P12_V1.txt
[min,n]=size(GHE1_6kW_P12_V1);
tau = GHE1_6kW_P12_V1(240:end,1);
Tfm_mis = GHE1_6kW_P12_V1(240:end,2);
rho_s = 2533; %[kg/mc]
c_s = 840; %[J/kg.K]
eps = 0.4;
T_0 = 15.96;
rho_w = 1020; %water density [kg/mc]
c_w = 4186;
r_bh= 0.076; %borehole ID/OD=151/165
q = 110.22; %[W/m]
a_s = 0.25;
par=[10,1.7E-6,0.09];
C_0 = rho_s*c_s*(1-eps)+rho_w*c_w*eps;
est = r_bh^2*C_0/4*tau*par(1);
f=(1./est).*exp((-1./est)-((par(2)^2)*c_w^2*r_bh^2*rho_w^2)/16*par(1));
T=cumtrapz(est,f);
dteta= 45*pi/180;
teta =(dteta : dteta : 2*pi);
for j=1:numel(teta)
z(1,j)= q/(4*pi*par(1))*exp((par(2)*rho_w*c_w*r_bh*cos(teta(j)))/2*par(1));
end
g=T*z;
A=mean(g');
B = T_0+A;
Tfm_MLS= B + (q * par(3));
plot(Tfm_MLS,'r')
hold on
plot (Tfm_mis,'g')
RMSE = (sum((Tfm_MLS-Tfm_mis).^2)/length(tau)).^0.5;
1 comentario
Walter Roberson
el 11 de Nov. de 2019
Which variables need to be optimized over? Is it the par vector?
Is RMSE the equation whose value is to be minimized? \
Is there a reason you are using a loop for
for j=1:numel(teta)
z(1,j)= q/(4*pi*par(1))*exp((par(2)*rho_w*c_w*r_bh*cos(teta(j)))/2*par(1));
end
instead of
z = q./(4*pi*par(1)).*exp((par(2).*rho_w.*c_w.*r_bh.*cos(teta))./2.*par(1));
which is vectorized?
Respuestas (1)
Saeid Bina
el 11 de Nov. de 2019
2 comentarios
Walter Roberson
el 11 de Nov. de 2019
Vectorizing that loop that calculates z would be more efficient.
Make sure, though, that you use ./ and .* instead of / and * like I show in my code.
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!