Optimization with trapz and data

3 views (last 30 days)
plasmageek
plasmageek on 8 Aug 2019
Edited: plasmageek on 13 Aug 2019
The basic bit. I have an experimental data point. I can estimate what the value should be from physics; the value is dependent on temperature(a constant) and energy(covers a range). I want to find the value of temperature that (chi) minimizes the experimental value to my estimated value to find the temperature.
The complex bit: I have to integrate over energy to get my estimated signal. The integral is non-trivial. It involves a predined function (chosen based on physics). Pretty much this is an exponential with energy and temperature outfront and in the exponent.
This is multipled by two emperical functions that take into account filters and diagnostic response functions that depend on energy. The emperical functions aren't really functions; I have emperical data, did multiple fits to sections of the data to get the best fit possible and compiled it all into an array using the relevant energy values. A single fit is not possible.
Currently I'm solving this with for loops, generating large amounts of data. There are actually 9 data points, which should be solved consistently with each other. It takes 10-20 minutes with a parallel loops to run the current iteration. The issue is, we think there's a second temperature. Running it with loops was already inefficient but I've never used the optimziation toolbox and kept getting stuck trying to use it. A second temperature makes doing this with loops....pretty much impossible.
I'm wondering if there's a way to use the optimization toolbox (or something else in Matlab?) to improve solving this problem.
  6 Comments
plasmageek
plasmageek on 13 Aug 2019
Edited: plasmageek on 13 Aug 2019
So here's my current issue. I need to solve all my channels consistently. I was able to combine my emperical data sets and find a fit for them. The issue is this fit changes for each channel, but it has to be included in the function. I'm trying to use lsqcurvefit. Below is my current code (which doesn't run). My xdata represents my different channels.
The variable E is an array from 1 to 300. Omega is a single value for each channel.
Area = a*1e-3*b*1e-3; %%m^2
for ii = 1:7
idx = ii+1;
const = T(idx,:).*IP_response';
[E,const] = prepareCurveData(E,const);
Ft{ii} = fit(E,const,'smoothingspline');
end
%%
xdata = 2:8; %%calling out channels of interest
ydata = double(SigFin(xdata))/IP_Fade;
fun = @(x,xdata)Omega(xdata)/Area*trapz((2*sqrt(x(1))/(x(2)^(3/2)))*exp(-E/x(2)).*Ft{xdata}(E));
x0 = [1, .020];
X = lsqcurvefit(fun,x0,xdata,ydata);
plasmageek
plasmageek on 13 Aug 2019
And my other thought was to make a function and have it called. I put together the following, but it's obviously not right either...
function fun = HerieAnalysis(x,Area,Omega,xdata,E,Ft)
for ii = 1:length(xdata)
switch xdata(ii)
case 1
const = Ft{1};
Ang = Omega(1);
case 2
const = Ft{2};
Ang = Omega(2);
case 3
const = Ft{3};
Ang = Omega(3);
case 4
const = Ft{4};
Ang = Omega(4);
case 5
const = Ft{5};
Ang = Omega(5);
case 6
const = Ft{6};
Ang = Omega(6);
case 7
const = Ft{7};
Ang = Omega(7);
case 8
const = Ft{8};
Ang = Omega(8);
case 9
const = Ft{9};
Ang = Omega(9);
end
fun = Ang/Area*trapz((2*sqrt(x(1))/(x(2)^(3/2)))*exp(-E/x(2)).*const(E));
end

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!