How to make a multivariable goal optimization
2 views (last 30 days)
Show older comments
Im trying to understand multivariable goal optimization, I will need to optimize complex functions, but to start, I need to optimize the following function:
function ap_phase = objecfun(tau)
f = 1000; %Frequency
w = 2*pi*f; %Angular Frequency
trans_func = @(taux) (1-1i*w*taux)./(1+1i*w*taux); %Transfer function
trans_zero = trans_func(tau(1)); %Transfer function with the first variable
trans_quad = trans_func(tau(2)); %Transfer function with the second variable
ap_phase = rad2deg(phase(trans_zero)-phase(trans_quad)); %Phase difference
end
The function objecfun takes one vector of length 2 as an input, computes two transfer functions, then substracts the phase of the transfer functions.
My goal is that the phase should be around 90°
The script im using to make the optimization is the following
tau0 = [2E-5, 1E-3]; %Initial Value for tau(1) and tau(2)
lb = [1E-7, 1E-7]; %Lower bound for tau(1) and tau(2)
ub = [1E-2, 1E-2]; %Upper bound for tau(1) and tau(2)
goal = 90; %Optimization goal
weight = 1; %Weight
[x,fval] = fgoalattain(@objecfun,tau0,goal,weight,[],[],[],[],lb,ub)
The optimizer converges but im getting a wrong answer, im getting
x =
0.0100 0.0000
fval =
-178.1044
That's wrong, fval should be near 90°
0 Comments
Accepted Answer
Stephan
on 16 Oct 2018
Edited: Stephan
on 16 Oct 2018
Hi,
fgoalattain calculates a result:
f(x) <= goal
f(x)=0
Check this:
[x, fval] = phase_delta_90;
fprintf('tau(1) = %.12f\ntau(2) = %.12f\nPhase delta = %2.8f degree',x(1),x(2),fval)
function [x, fval] = phase_delta_90
goal = 90;
tau0 = [2E-5, 1E-3]; %Initial Value for tau(1) and tau(2)
x = fsolve(@calculate_tau,tau0);
fval = check_result(x);
function tau_result = calculate_tau(tau)
f = 1000; %Frequency
w = 2*pi*f; %Angular Frequency
trans_func = @(taux) (1-1i*w*taux)./(1+1i*w*taux); %Transfer function
trans_zero = trans_func(tau(1)); %Transfer function with the first variable
trans_quad = trans_func(tau(2)); %Transfer function with the second variable
tau_result = rad2deg(phase(trans_zero)-phase(trans_quad))-goal; %Phase difference minus goal
end
function ap_phase = check_result(x)
f = 1000; %Frequency
w = 2*pi*f; %Angular Frequency
trans_func = @(taux) (1-1i*w*taux)./(1+1i*w*taux); %Transfer function
trans_zero = trans_func(x(1)); %Transfer function with the first variable
trans_quad = trans_func(x(2)); %Transfer function with the second variable
ap_phase = rad2deg(phase(trans_zero)-phase(trans_quad)); %Phase difference after optimization
end
end
5 Comments
More Answers (0)
See Also
Categories
Find more on Get Started with Optimization Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!