optimization value not able to acheive

2 views (last 30 days)
I am not able to get the optimize value of n. Every time it shows Failure in initial objective function evaluation. FSOLVE cannot continue
Below matlab code is given. Thank you
Function
clear all
clc
function F = roo2d(n)
F=[(sin(pi*((n(1)/700)-1))/(pi*((n(1)/700)-1)))^2-0.31;
(sin(pi*((n(1)/1100)-1))/(pi*((n(1)/700)-1)))^2-0.42;
(sin(pi*((n(1)/1500)-1))/(pi*((n(1)/700)-1)))^2-0.50;
(sin(pi*((n(1)/2000)-1))/(pi*((n(1)/700)-1)))^2-0.59;
(sin(pi*((n(1)/2500)-1))/(pi*((n(1)/700)-1)))^2-0.64;
(sin(pi*((n(1)/3000)-1))/(pi*((n(1)/700)-1)))^2-0.655;
(sin(pi*((n(1)/3500)-1))/(pi*((n(1)/700)-1)))^2-0.64;
(sin(pi*((n(1)/4000)-1))/(pi*((n(1)/700)-1)))^2-0.59;
(sin(pi*((n(1)/4500)-1))/(pi*((n(1)/700)-1)))^2-0.50;
(sin(pi*((n(1)/5000)-1))/(pi*((n(1)/700)-1)))^2-0.39];
end
calling a function
fun= @roo2d
n0=[2000];
options = optimoptions('fsolve','Algorithm','levenberg-marquardt');
x= fsolve(fun,n0,options);

Accepted Answer

Walter Roberson
Walter Roberson on 9 Dec 2021
All of your equations are effectively calculations -- just with an offset for where the effective zero point is.
sinc() has a central spike that hits 1, but outside of that central spike, it never gets above for the original function -- the square of that for . So when you subtract values like 0.59, unless you are subtracting values down near 0.025 or less, then each of the functions individually has exactly two solutions, one before its central peak and one after its central peak.
With you using different divisors, you are guaranting that those central peaks do not line up -- and thus that only one function at a time has a solution. You can be certain that there is no possible solution for all of the functions simultaneously.
  8 Comments
Kundan Prasad
Kundan Prasad on 17 Dec 2021
Thank you sir,
Now I am able achieve the optimization for more than two number of blaze wavelength

Sign in to comment.

More Answers (1)

Alan Weiss
Alan Weiss on 8 Dec 2021
That is not what I get when I run your code:
No solution found.
fsolve stopped because the last step was ineffective. However, the vector of function
values is not near zero, as measured by the value of the function tolerance.
Sometiimes it is worthwhile plotting your function to see whether it might have some roots.
t = linspace(800,1e3);
z = zeros(10,length(t));
for i = 1:length(t)
z(:,i) = roo2d(t(i));
end
plot(t,z)
figure
t = linspace(1e3,3e3);
z = zeros(10,length(t));
for i = 1:length(t)
z(:,i) = roo2d(t(i));
end
plot(t,z)
function F = roo2d(n)
F=[(sin(pi*((n(1)/700)-1))/(pi*((n(1)/700)-1)))^2-0.31;
(sin(pi*((n(1)/1100)-1))/(pi*((n(1)/700)-1)))^2-0.42;
(sin(pi*((n(1)/1500)-1))/(pi*((n(1)/700)-1)))^2-0.50;
(sin(pi*((n(1)/2000)-1))/(pi*((n(1)/700)-1)))^2-0.59;
(sin(pi*((n(1)/2500)-1))/(pi*((n(1)/700)-1)))^2-0.64;
(sin(pi*((n(1)/3000)-1))/(pi*((n(1)/700)-1)))^2-0.655;
(sin(pi*((n(1)/3500)-1))/(pi*((n(1)/700)-1)))^2-0.64;
(sin(pi*((n(1)/4000)-1))/(pi*((n(1)/700)-1)))^2-0.59;
(sin(pi*((n(1)/4500)-1))/(pi*((n(1)/700)-1)))^2-0.50;
(sin(pi*((n(1)/5000)-1))/(pi*((n(1)/700)-1)))^2-0.39];
end
There is clearly no time t where all of the curves simultaneously cross 0.
Alan Weiss
MATLAB mathematical toolbox documentation
  3 Comments
Walter Roberson
Walter Roberson on 9 Dec 2021
N = linspace(2000,2500,500);
y = cell2mat(arrayfun(@roo2d, N, 'uniform', 0));
plot(N, y.');
yline(0, 'k')
function F = roo2d(n)
F=[(sin(pi*((n(1)/700)-1))/(pi*((n(1)/700)-1)))^2-0.31;
(sin(pi*((n(1)/1100)-1))/(pi*((n(1)/1100)-1)))^2-0.42;
(sin(pi*((n(1)/1500)-1))/(pi*((n(1)/1500)-1)))^2-0.50;
(sin(pi*((n(1)/2000)-1))/(pi*((n(1)/2000)-1)))^2-0.59;
(sin(pi*((n(1)/2500)-1))/(pi*((n(1)/2500)-1)))^2-0.64;
(sin(pi*((n(1)/3000)-1))/(pi*((n(1)/3000)-1)))^2-0.655;
(sin(pi*((n(1)/3500)-1))/(pi*((n(1)/3500)-1)))^2-0.64;
(sin(pi*((n(1)/4000)-1))/(pi*((n(1)/4000)-1)))^2-0.59;
(sin(pi*((n(1)/4500)-1))/(pi*((n(1)/4500)-1)))^2-0.50;
(sin(pi*((n(1)/5000)-1))/(pi*((n(1)/5000)-1)))^2-0.39];
end
Look at the graph. Near 2250-ish, it crosses 0 for one of the functions -- but when you fsolve() you are asking for all of the functions to be solved.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!