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;
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.