Using fminsearch : converting mex file to a function
2 views (last 30 days)
Show older comments
iono_layer_parms = [a, b, -1, -1, -1, -1];
[iono, iono_extra] = iri2012(lat, lon, R12, UT, ht_start, ht_step,num_hts,iono_layer_parms);
ionofreq = 0.008978663597663*sqrt((10.^(-6))*(iono(1,18:end)));
ban = ionofreq(76:126) - D6xc;
[x,fval] = fminsearch(@(x)ban,[10.52, 490]);
This is the code I have written to use fminsearch for my purpose. I have all the variables defined for iri2012 except 'a' and 'b'. I want to change variables 'a' and 'b' only and want to mimize 'ban'. iri2012 is a Matlab wrapper to the IRI-2012 fortan based empirical model ionosphere. The actual programme is a mex wrapper (iri2012_matlab_wrapper.for) to the Fortran code (irisub.for). And when I run this code, I get the following errors :
Subscripted assignment dimension mismatch.
Error in fminsearch (line 191)
fv(:,1) = funfcn(x,varargin{:});
Error in Naldermead (line 25)
[x,fval] = fminsearch(@(x)ban,[10.52, 490]);
I want to take one of the outputs of iri2012 which is iono(1,18:end) .
The code is named Naldermead.m
I think there is more than these errors. The real pronblem may be converting the mex wrapper into a function. Please let me know if I can work on this problem with this approach.
6 Comments
John D'Errico
on 23 Feb 2015
So if ban is a vector, it is a CONSTANT. You may think of it as a function of a and b, but it is just a constant as you have it here.
You need to write a function that returns the sum of squares of the vector ban, where the function will take a and b as an argument vector of length 2. The function must compute ban internally, then return sum(ban.^2) to minimize.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!