optimization value not able to acheive
2 views (last 30 days)
Show older comments
Kundan Prasad
on 8 Dec 2021
Commented: Kundan Prasad
on 17 Dec 2021
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);
0 Comments
Accepted Answer
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
Walter Roberson
on 15 Dec 2021
Edited: Walter Roberson
on 15 Dec 2021
N=[linspace(700,5000,500) linspace(0,0.5,0.01)];
% N= linspace(700,5000,0.5)
y = cell2mat(arrayfun(@(n)roo2d(n*ones(1,4)), N, 'uniform', 0));
plot(N, y.');
yline(0, 'k')
legend(cellstr(string(1:13)), 'location', 'best')
format long g
[sol, fval] = fsolve(@roo2d, 2001*ones(1,4))
function F = roo2d(n)
F=[((sin(pi*((n(1)/700)-1))/(pi*((n(1)/700)-1)))^2)*n(3)+...
((sin(pi*((n(2)/700)-1))/(pi*((n(2)/700)-1)))^2)*n(4)-0.31;
((sin(pi*((n(1)/1100)-1))/(pi*((n(1)/1100)-1)))^2)*n(3)+...
((sin(pi*((n(2)/1100)-1))/(pi*((n(2)/1100)-1)))^2)*n(4)-0.42;
((sin(pi*((n(1)/1500)-1))/(pi*((n(1)/1500)-1)))^2)*n(3)+....
((sin(pi*((n(2)/1500)-1))/(pi*((n(2)/1500)-1)))^2)*n(4)-0.50;
((sin(pi*((n(1)/2000)-1))/(pi*((n(1)/2000)-1)))^2)*n(3)+.....
((sin(pi*((n(2)/2000)-1))/(pi*((n(2)/2000)-1)))^2)*n(4)-0.59;
((sin(pi*((n(1)/2500)-1))/(pi*((n(1)/2500)-1)))^2)*n(3)+......
((sin(pi*((n(2)/2500)-1))/(pi*((n(2)/2500)-1)))^2)*n(4)-0.64;
((sin(pi*((n(1)/3000)-1))/(pi*((n(1)/3000)-1)))^2)*n(3)+.....
((sin(pi*((n(2)/3000)-1))/(pi*((n(2)/3000)-1)))^2)*n(4)-0.655;
((sin(pi*((n(1)/3500)-1))/(pi*((n(1)/3500)-1)))^2)*n(3)+....
((sin(pi*((n(2)/3500)-1))/(pi*((n(2)/3500)-1)))^2)*n(4)-0.64;
((sin(pi*((n(1)/4000)-1))/(pi*((n(1)/4000)-1)))^2)*n(3)+.....
((sin(pi*((n(2)/4000)-1))/(pi*((n(2)/4000)-1)))^2)*n(4)-0.59;
((sin(pi*((n(1)/4500)-1))/(pi*((n(1)/4500)-1)))^2)*n(3)+.....
((sin(pi*((n(2)/4500)-1))/(pi*((n(2)/4500)-1)))^2)*n(4)-0.50;
((sin(pi*((n(1)/5000)-1))/(pi*((n(1)/5000)-1)))^2)*n(3)+.....
((sin(pi*((n(2)/5000)-1))/(pi*((n(2)/5000)-1)))^2)*n(4)-0.39;
abs(n(3));
abs(n(4));
n(3)+n(4)-1];
end
More Answers (1)
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
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!