How do I create a function that will work when optimized using fminsearch when modelling heat transfer?
Show older comments
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.
Answers (1)
Alan Weiss
on 2 Apr 2018
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 Comment
Categories
Find more on Nonlinear Control in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!