I am trying to find a solution for my equation with a command better than fminsearch.
11 views (last 30 days)
Show older comments
I have a code as below. I am trying to modelling the relationship between solar radiation and temperature extremes and humidity extremes. I was using fminsearch, but the mean percentage error of my model is resulted as %9. I want to decrease this error. What can I do? Which alternatively commands will be suitable for me? I am very new in Matlab.
%My matlab code
v = xlsread('I:\Yeni klasör\Tez 30 temmuz\Tez kilitlenme\Türkiye\Kahramanmaraş\matlab model.xlsx')
z=v(:,1)
y=v(:,2)
x=v(:,7)
u=v(:,5)
syms a, syms b, syms c
p(1) = a, p(2) = b, p(3) = c
z = @(p,v) v(:,2).*(p(1).*(1-exp(v(:,7).^p(2)))+p(3).*v(:,5))
P0 = [-0,3564; 0,0596; -0,4732]; % Choose Appropriate Initial Parameter Estimates
SSECF = @(p) sum((v(:,1) - z(p,v)).^2); % Sum-Squared-Error Cost Function
options = optimset('MaxFunEvals',100000000);
options = optimset('MaxIter',100000000);
[abc, SSE] = fminsearch(SSECF, P0, options); % Estimate Parameters
a = abc(1)
b = abc(2)
c = abc(3)
5 Comments
Walter Roberson
on 16 Sep 2016
Edited: Walter Roberson
on 16 Sep 2016
Could you confirm that your formula is
z - y*(a*(1-exp(x^b))+c*u)
Answers (3)
Star Strider
on 11 Sep 2016
If you have the Global Optimization Toolbox, use the patternsearch function to see if you can estimate a better set of parameters. If not, you can write your own genetic algorithm to do the same sort of search.
11 Comments
Star Strider
on 29 Oct 2016
We’ve already given you all the applicable MATLAB built-in functions and user-written File Exchange functions available. You know your data and the model you want to fit to it. You have to write the code to implement your model, then choose the solver best suited to estimate the parameters. The fminsearch function is a good place to begin, providing you don’t have too many parameters. The patternsearch function is much more robust in that it searches a greater parameter space.
You will likely have to settle for a less-than-perfect fit of your model function to your data. This is the usual outcome.
I would definitely not use a symbolic approach. The Symbolic Math Toolbox is not designed for iterative problems.
Walter Roberson
on 30 Oct 2016
My code, the one I used to find the coefficients I gave below, is not publishable quality. I have continued to make significant changes to it since I used it to examine your coefficients. For example I improved bounds checking a fair bit.
I am in the middle of improving its memory behavior for handling more variables by breaking the search into smaller pieces and patching the results together, which gets especially important for curve-fitting (non-linear least-squares fitting) situations like you have.
I am outlining practices for replicating variables for bulk fitting for least-squared, but I am not nearly ready to automate that; currently this requires hand-manipulating the input functions.
The user interface to call my program is not very friendly, having a large number of parameters whose meaning is sometimes difficult to describe. I started cleaning that up a bit -- the program now accepts an "options" style of structure... whose meaning is not especially obvious to anyone not intimately familiar with the code.
It is, in short, a piece of research code. I would not put it out to beta test; I would hesitate to put it out to alpha test. It is, at best, at the "collaborating programmer in the same office" stage (if not for the fact that I work alone.)
It progresses if I am not busy answering Questions, and I am inspired, and I am feeling healthy enough, and I can't sleep, and I am not working on my other long term project. [That one is a program that primarily validates .fig files but is growing from there.]
That is just how things happen sometimes. Research ~= Development.
Matt J
on 11 Sep 2016
Edited: Matt J
on 11 Sep 2016
Fminsearch is not guaranteed convergent for 3 variables, but I'm doubtful that the inaccuracy you see would be due to failure of the optimization. Still, you might try lsqcurvefit instead. Another good option might be fminspleas ( Download ), since your model function has a non-linear dependence on only one of your variables, b.
funlist={@(b,v) (1-exp(v(:,7).^b, @(b,v) v(:,5)};
[b,ac]=fminspleas(funlist,P0(2),v,v(:,1) );
a=ac(1);
c=ac(2);
2 Comments
Walter Roberson
on 11 Sep 2016
Matt J included a link to a location you can download fminspleas . Or you could use "Get Add-Ons" to install it.
Walter Roberson
on 16 Sep 2016
The best location I could find was
[-0.24036462711882056186851741585996933281421661376953125, 0.13543162823623988710863841333775781095027923583984375, -0.00345339601881113934800371367828120128251612186431884765625]
where the sum-of-squared residue was 17101.81404290700083947740495204925537109375
14 Comments
Walter Roberson
on 9 Oct 2016
Curvefit is not able to go beyond two independent variables and one dependent variable, but within that limitation it can be fast.
See Also
Categories
Find more on Applications in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!