フィルターのクリア

How do I create a function that will work when optimized using fminsearch when modelling heat transfer?

2 ビュー (過去 30 日間)
JD
JD 2018 年 3 月 31 日
編集済み: JD 2018 年 4 月 2 日
I'm trying to carry out an optimization of my heat transfer model (using implicit finite difference equations) for a steel cube being cooled in air. The task is to find the correct heat transfer coefficient (h) for each time step using inverse analysis. I'm trying to create a function that generates the sum square error (r) of the predicted T (dependent on h) and the experimentally determined T that I've been given. I'll then pass this function to fminsearch that will find the value of h for that time step so that the error between the predicted T and experimental T is minimized (hopefully 0). The process will then repeat for the next time step, using the value of h determined for the previous time step.
However, I'm having trouble creating a function itself. The function itself looks like this:
function [r] = functest(h)
[all of my implicit calculations and constants etc used to generate the predicted T, + read in of experimental data
from separate m. file]
r=sqrt(sum(((Predicted_T(2,2)-Experimental_T(2,2))/2)));
and when I then try to run the fminsearch in the 'main' matlab code (although there's hardly anything there now, as its all been moved into the function) like this:
h0 = 20; % initial guess
h = fminsearch(@functest,h0);
It just returns h = 20 and h0 = 20 (or whatever the initial guess is). So my question is, is putting all of the implicit finite difference equations and constants etc into the function the right way to go about this? Obviously, as it would have to repeat this for every time step it will take a very long time to complete, however my supervisor said his takes upwards of an hour, so I'm not too fussed about that.
Any help is greatly appreciated.
  1 件のコメント
JD
JD 2018 年 4 月 2 日
So I've progressed a little further with this and I've hit another stumbling block which someone might be able to help with.
I've got a function working ( function r = functest(h) ) and when I pass this to fminsearch it produces a value of h that minimizes the error between predicted and experimental T for a single time step - good so far! However, I'm now having trouble making the code use this calculated value of h in the next iteration (the next time step).
Is there a command or something similar that enables me to use the fminsearch derived h for the previous time step as the initial guess for the next time step, whereby the process repeats itself until a predetermined temperature is reached?

サインインしてコメントする。

回答 (1 件)

Alan Weiss
Alan Weiss 2018 年 4 月 2 日
I don't knw what Predicted_T(2,2) or Experimental_T(2,2) are, but they look like scalars to me. If you want to sum over some indices, I would expect that the formula would be something like
sum(((Predicted_T(:,2)-Experimental_T(:,2))/2)));
or
sum(sum(((Predicted_T(:,:)-Experimental_T(:,:))/2))));
Alan Weiss
MATLAB mathematical toolbox documentation
  1 件のコメント
JD
JD 2018 年 4 月 2 日
編集済み: JD 2018 年 4 月 2 日
Predicted_T and Experimental_T are are my two matrices containing my model predicted temperatures and experimentally derived temperatures, with time in column one (0, 1, 2, 3 etc) and the corresponding temperature adjacent to each time step in column two.
So at the moment, I can enter for example in my function:
r=sqrt(sum(((Predicted_T(50,2)-Experimental_T(50,2))/2)));
and this will compute the error between the model predicted T and the experimentally derived T at 49 seconds; the function can then be passed to the optimizer to find the value of h that minimizes the error between predicted T and experimental T at 49 seconds (for example).
I'm basically trying to find a way to do this:
1 - Calculate predicted T using model for first time step (already done). 2 - Read in experimental data for that time step (already done). 3 - Calculate error (r) using SSE between predicted T and experimental T (already done). 4 - Pass to optimizer (fminsearch currently) to find value of h (already done). 5 - Starts back at step 1 for the next time step, using the value of h calculated in step 4 for the previous time step. And so on...
At the moment I've got the model to predict the temperature at each time step with a constant value of h, it's just a case of incorporating the changing of h (as determined using fminsearch in conjunction with the experimental data) with each loop until that I'm having trouble with.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by