필터 지우기
필터 지우기

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