フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to use fminsearch for my code

1 回表示 (過去 30 日間)
Saeid Bina
Saeid Bina 2019 年 11 月 11 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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 件のコメント
Walter Roberson
Walter Roberson 2019 年 11 月 11 日
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?

回答 (1 件)

Saeid Bina
Saeid Bina 2019 年 11 月 11 日
Yes Par need to be optimaized and while RMSE is minimized. RMSE is the diffrence between calculated and measured data.
I have used loop beacuase that fuction need to be calculated for 8 teta. It is kind a 3D matrix. The data are calculating for timly basis and at each min for 8 teta (degree) and then using Mean for finding average temperature for each min.
by the way if you think is not needed, your idea is respected.
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 11 月 11 日
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.
Saeid Bina
Saeid Bina 2019 年 11 月 11 日
Yes, I have used that one, it results in same. Please help me to optimaize par.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by