www.gusucode.com > mbc 工具箱 matlab 源码程序 > mbc/mbcSolveTQ.m

    function [Xlocal,XTS] = mbcSolveTQ(Models,Xlocal,Speed,TQDemand)
%mbcSolveTQ utility function to solve diesel models to find demanded torque
%
%   [Xlocal,XTS] = mbcSolveTQ(Models,Xlocal,Speed,TQDemand)
%   Physical constraints for AFR, PEAKPRESS and VGTSPEED are also applied.
%  
%   mbcSolveTQ is a utility function for mbcPointByPointCmdline
%
%   See also mbcPointByPointCmdLine

% Copyright 2009 The MathWorks, Inc.

n = size(Xlocal,1);
XTS = zeros(n,6);
XTS(:,2)= Speed;
XTS(:,3)= 100;
XTS(:,[1 4:end]) = Xlocal;

% use nonlinear least squares to find the fuel which delivers the demanded
% torque for each point in the local design
opts = optimset(optimset('lsqnonlin'),...
    'LargeScale','on',...
    'Display','none',...
    'JacobPattern',speye(size(Xlocal,1)));
% fuel is constrained to be between 20 and 220
[fuel,~,res] = lsqnonlin(@iFindTQ,XTS(:,3),...
    20*ones(n,1),220*ones(n,1),...
    opts,...
    Models.BTQ,XTS,TQDemand);

%find points where the desired torque was achieved
ValidTorque = abs(res)<1e-3;

% Apply other physical constraints
% These data points could not be collected from a real engine due to
% physical constraints. Here we use the models from the diesel case study
% to estimate the physical constraints
XTS(:,3) = fuel;
% AFR constraint
AFR = 14.46./Models.EQREXH.PredictedValue(XTS);
ValidAFR = AFR> 10 & AFR < 100;
% Peak pressure constraint
PEAKPRESS = Models.PEAKPRESS.PredictedValue(XTS);
ValidPeakPRESS = PEAKPRESS>0  &  PEAKPRESS < 18e6;
% Turbo speed constraint
VGTSPEED = Models.VGTSPEED.PredictedValue(XTS);
ValidVGTSPEED = VGTSPEED > 2500 & VGTSPEED < 12800;

Valid = ValidTorque & ValidAFR & ValidPeakPRESS & ValidVGTSPEED;

Xlocal = Xlocal(Valid,:);
XTS = XTS(Valid,:);


function e = iFindTQ(fuel,TQModel,XTS,TQDemand)

XTS(:,3) = fuel;
% normalize error by demanded torque
e = (TQModel.PredictedValue(XTS)-TQDemand)/TQDemand;