%% Varying Tuning Goal With Frequency Focus and Loop Opening
% Create a tuning goal that specifies variable gain and phase margins across a grid of design points. Configure the tuning goal to be evaluated with a loop opening at a location 'LO' and to apply only in the frequency range between 1 and 100 rad/s.
%
% Specify the grid of design points and the corresponding grid of target gain margins and phase margins. Also, create the template function for the varying margins goal.

[alpha,V] = ndgrid(linspace(0,20,5),linspace(700,1300,5));
[GM,PM] = ndgrid(linspace(7,20,5),linspace(45,70,5));
FH = @(gm,pm) TuningGoal.Margins('u',gm,pm);

%
% Use the template function and the margin arrays to create the varying goal. Also, use Name,Value pairs to specify:
% The location at which the loop is opened for evaluating the tuning goal (Openings property).
% The frequency range in which the varying goal applies (Focus property).
% The property names and values that you specify for the underlying tuning goal are stored in the Settings property of the varying goal.

VG = varyingGoal(FH,GM,PM,'Openings','LO','Focus',[1,100])

%
% To make it easier to trace which goal applies to which design point, use the SamplingGrid property to attach the design-point information to VG.

VG.SamplingGrid = struct('alpha',alpha,'V',V);

% Copyright 2012 The MathWorks, Inc.