How to work with unknown parameters using Nelder Mead Algorithm?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
Dear All, I need to extract the original parameters of a PV Panel using Nelder-Mead Algorithm. How can I do that?
I also have the following equation: 
Thank you and looking forward.
Accepted Answer
Walter Roberson
on 3 Jan 2020
1 vote
Given a set of trial input parameters in a vector, use the known x values to project y values. Subtract the known y values in each case, and square those individually, and sum() the vector. The result will be a sum-of-squared-errors scalar for those input parameters. You want to minimize that: if there were a perfect fit, the residue would be 0. (The residue cannot be negative as you are adding values that are strictlly non-negative).
You can construct a function handle that given the trial parameters, calculates the residue scalar.
Now pass the function handle to your Nelder-Mead function for it to minimize.
12 Comments
Julkar_Mustakim
on 3 Jan 2020
Dear Walter,
Thanks for your answer. As I am very new in MatLab, it will be great if you please guide me little bit more on this issue. Which function should I use in this case? Thank you.
You can use fminsearch or, presumably, the alternative Nelder-Mead implementation that Walter provided a link for.
Walter Roberson
on 3 Jan 2020
First adapt the code in https://www.mathworks.com/matlabcentral/fileexchange/69636-nelder-and-mead-simplex-algorithm into the form of a function that takes a function handle that takes a vector of trial parameters, and has built-in alpha, beta, etc., coefficients, and alters the trial values to optimize, returning a vector of the best parameters found. This function will probably also want a vector of initial parameter guesses.
Then, in the below I function, use V as the vector of known voltages at which corresponding Current values were read off. Also have a vector of known Current values that is the same size and orientation as V is.
I = @(Iph, Io, Rs, Rsh, n) Iph - Io .* exp(ETC); %make sure to vectorize it on V
residue = @(poshn) sum((I(poshn(1), poshn(2), poshn(3), poshn(4), poshn(5)) - knownCurrents).^2);
Now pass the function handle residue to the NelderMeadSimplex function you constructed, along with a vector of initial parameter guesses. Take the return vector of values and break it out into individual Iph, Io, Rs, Rsh, n variables if you want.
Walter Roberson
on 3 Jan 2020
I just noticed that fminsearch uses Nelder-Mead simplex . It would be a good idea to use fminsearch() instead of altering the function I linked to earlier. I did not suggest fminsearch() earlier because I thought it was using a different but related algorithm.
Julkar_Mustakim
on 3 Jan 2020
Dear Walter, Thanks a lot for your detailed guideline. I will try and get back to you if there is any problem. In my case i can not use "fminserach()" directly. I have to use Nedler-Mead algorithm from very basic. Thanks again.
Walter Roberson
on 4 Jan 2020
If you are not permitted to use fminsearch then you probably are expected to code the simplex search yourself.
Julkar_Mustakim
on 14 Jan 2020
Dear @Walter Roberson, Will it be possible to give arrays of values of "X" to get the arrays of values of "Y"? If so, how can I pass it Nelder Mead to get the multiple optimized values? Thank you.
Walter Roberson
on 14 Jan 2020
Iproj = @(Iph, Io, q, Rs, n, K, T, Rsh) Iph - Io .* exp(q*(V + I.*Rs)./(n.*.K.*T) - 1) - (V+I.*Rs)./Rsh;
residue = @(p) sum((Iproj(p(1),p(2),p(3),p(4),p(5),p(6),p(7),p(8)) - I).^2);
p0 = randn(1,8);
bestp = NelderMead(residue, p0);
This assumes that your known values are V ("X") and I ("Y"). It processes the entire list of V and I values at the same time.
However if you examine your formula, you can see that it is not going to be possible mathematically to isolate q, n, K, and T: all that is going to be possibe to isolate is the product q/(n*K*T) . Double the n and halve the T and you are going to get exactly the same value calculated. Unless at least three of those quantities are fixed in advance, you cannot figure out what the un-fixed ones are using any kind of fitting algorithm.
Julkar_Mustakim
on 15 Jan 2020
Dear @Walter Roberson, Thanks again for the reply. We can use the following equation as well for the above purpose,

where I will be providing the initial values of Iph, Id, Rs, Rsh, n with some range of known values of "V" to calculate the unknown "I". For me the challenge is how to adapt the following link of nelder mead for multiple variables:
Once the adptation for multiple values in Nelder-Mead is done then I have to workout how can I put multiple values of known "V" to calcullate unknown "I".
As I am a beginner in MatLab you can suggest me any tutorial or learning materials to develop my skills. Thank you once again.
Walter Roberson
on 16 Jan 2020
That code already handles multiple dimensions. The dimension of the problem that is entered, n, would be the number of parameters that you are fitting. It will store each set of points as a column in the array named x
Iproj = @(Iph, Id, Rs, Rsh, n) Iph - Id .* exp((V + I.*Rs)./(0.9257 * n) - 1) - (V+I.*Rs)./Rsh;
residue = @(p) sum((Iproj(p(1),p(2),p(3),p(4),p(5)) - I).^2);
p0 = [Iph_initial, Id_initial, Rs_initial, Rsh_initial, n_initial];
bestp = NelderMead(residue, p0);
Walter Roberson
on 30 Jan 2020
[xMin] = NelderMead(myfunc,x0,alpha,beta,gamma,varargin)
varargin as a parameter would not typically occur outside of a function definition: in the majority of cases if you wanted to pass on parameters that you had received, you would use
[xMin] = NelderMead(myfunc,x0,alpha,beta,gamma,varargin{:})
Or is the
[xMin] = NelderMead(myfunc,x0,alpha,beta,gamma,varargin)
line intended to be a function definition that is missing the "function" keyword?
fval = feval(objfunc,smp,varargin{:});
what is objfunc and how does it differ from myfunc ?
Where is the end statement for your if fStd test? Where is the end statement for your while loop? Why are you setting up objF and x0 and so on inside the if inside the while ?
Julkar_Mustakim
on 30 Jan 2020
Edited: Julkar_Mustakim
on 30 Jan 2020
Dear Walter Roberson,
I have created seperate file for Nelder Mead and another file for my desired function like you guided me earlier. I have passed the Objective Function to the Nelder Mead Function. Here, "objfunc" means "myfunc". I have mistakenly written "objfunc". So here is the right one:
% objective function
myfunc = @(x)(1.5 - x(1,:)+ x(1,:).*x(2,:)).^2 ...
+ (2.25 - x(1,:) + x(1,:).*x(2,:).^2).^2 ...
+ (2.625 - x(1,:)+ x(1,:).*x(2,:).^3).^2;
and in the Nelder Mead File it will be like this:
fval = feval(myfunc,smp,varargin{:});
Initially, I will be deciding one of the stopping criteria if "fstd (standard deviation)" and "distv0 (which is the Absolute Relative Percentage Error considering the distance between the simplex and centroid)" is less than the tolerance.
if fStd < TOL && distv0 < TOL
break
end
But here, I was not able to calculate the "Absolute Relative Percentage Error (
) for Each of The Simplex (smp)". So please guide me on the calculation of Absolute Relative Percentage Error ( in my case it is becoming infinity).
distv0 = max(max(abs(repmat(v0,1,N)-smp(:,2:end))))./max(abs(repmat(v0,1,N));
More Answers (0)
Categories
Find more on NaNs in Help Center and File Exchange
See Also
on 3 Jan 2020
on 30 Jan 2020
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)