Non linear optimization problem in a range of frequencies

Hello, I need to optimize the phase difference of two transfer functions, such as:
f = phase(1/(1+tau1*j*w)) - phase(1/(1+tau2*j*w))
The variables to optimize are tau1 and tau2, "j" is the imaginary number and "w" is a vector of frequencies. I need to optimize the function in a range of frequencies (specifically between 100 and 4000 Hz) so function "f" stays within a lower and upper bound (-10 to 10) in the range of 100 Hz to 4000 Hz.
Im using the optimization tool, my objective function is
function f = objecfun(tau)
freq = 100:0.1:4000; %Frequency vector
w = 2*pi*freq; %Frequency in radians per seccond
trans_func = @(taux) 1./(1+1i*w*taux); % Anonymous transfer function
trans_func_1=trans_func(tau(1)); % Calculates first transfer function
trans_func_2=trans_func(tau(2)); % Calculates second transfer function
f = phase(trans_func_1)-phase(trans_func_2); %Takes phase of each transfer function and substracts
end
And my non-linear constraints function is
function [c,ceq] = nonlconstr(tau)
freq = 100:0.1:4000; %Frequency vector
w = 2*pi*freq; %Frequency in radians per seccond
trans_func = @(taux) 1./(1+1i*w*taux); % Anonymous transfer function
trans_func_1=trans_func(tau(1)); % Calculates first transfer function
trans_func_2=trans_func(tau(2)); % Calculates second transfer function
f = phase(trans_func_1)-phase(trans_func_2); %Takes phase of each transfer function and substracts
c = [f -10; -f 10]; %Lower and upper bounds
ceq = [];
end
However when I run the optimization tool, It gives me an error that the "Supplied objective function must return a scalar value.", I know that it is because im using a vector of frequencies "w" instead of using a single frequency, so my question is: How can I run the optimization tool so the phase difference of my transfer functions (f) stays between -10 to 10 in the frequency range of interest?

Answers (0)

Products

Release

R2018a

Asked:

Joe
on 11 Oct 2018

Commented:

Joe
on 13 Oct 2018

Community Treasure Hunt

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

Start Hunting!