i have the next error but idk wheres the problem.
Show older comments
Heres the error.
Error using nlmpc/nlmpcmove
Expected "Parameters" to be a vector.
Error in TESIS_JL (line 94)
[uk, info] = nlmpcmove(nlobj, xk, uk, ref);
heres my program, NMPC:
%% NMPC
% Parámetros de la planta de temperatura
Ta = 23 + 273.15; % K
U = 10.0; % W/m^2-K
m = 4.0/1000.0; % kg
Cp = 0.5 * 1000.0; % J/kg-K
A = 12.0 / 100.0^2; % Area in m^2
alpha = 0.01; % W % heater
eps = 0.9; % Emissivity
sigma = 5.67e-8; % Stefan-Boltzman
Par = [Ta;U;m;Cp;A;alpha;eps;sigma];
%% Crear objeto NMPC
nx = 1; %Estados
ny = 1; %Salidas
nu = 1; %entradas
nlobj = nlmpc(nx,ny,nu);
nlobj.States.Name = 'T';
nlobj.MV.Name = 'H';
nlobj.Model.StateFcn = @(x,u,Par) prediction_model_jl(x,u,Par);
% No output function specified. Assuming "y = x" in the prediction model.
nlobj.Model.IsContinuousTime = true;
nlobj.Model.NumberOfParameters=1;
%% Restricciones NMPC
nlobj.States.Min = 0;
nlobj.MV.Min = 0;
nlobj.MV.Max = 100;
nlobj.MV.RateMin = -100;
nlobj.MV.RateMax = 100;
%% NMPC Sintonización
N=14;
Nu=10;
delta=0.69408;
lambda=0.24209;
Ts = 8;
nlobj.Ts = Ts;
nlobj.PredictionHorizon = N;
nlobj.ControlHorizon = Nu;
nlobj.Weights.OutputVariables = delta;
nlobj.Weights.ManipulatedVariablesRate = lambda;
%% Validacion de las funciones;
T = 23 + 273.15;
x0 = T;
Q = 0;
u0 = (Q);
validateFcns(nlobj,x0,u0,[],{Par});
%% Ingreso de señales de referencia
t = linspace(0, 10, 1000); % Adjust the time range and number of samples as needed
% Define the initial value before the step
initialValue = 23+273.15;
% Define the value after the step
stepValue = 50;
% Define the step time
stepTime = 5;
% Create the step function
ref = initialValue + stepValue * (t >= stepTime);
ref = reshape(ref, [], 1);
%% Simulation settings
% Define simulation parameters
timestep = 0.1; % Time step for simulation
numSteps = 100; % Number of simulation steps
% Preallocate arrays to store results
time = linspace(0, timestep*numSteps, numSteps);
states = zeros(1, numSteps);
controls = zeros(1, numSteps);
% Initial state and control input
xk = Ta; % Initial temperature
uk = 0; % Initial control input
% Simulate the NMPC applied to the plant
for k = 1:numSteps
% Measure the current state of the plant
yk = xk; % Here, we assume the measured state is equal to the actual state
% Compute the optimal control action using NMPC
[uk, info] = nlmpcmove(nlobj, xk, uk, ref);
% Apply the control action to the plant and simulate the dynamics
[~, xk_next] = ode45(@(t, x) heat2(t, x, Q), [0 timestep], xk);
% Update the current state
xk = xk_next(end);
% Store the state and control input for analysis
states(k) = xk;
controls(k) = uk;
end
% Plot the results
figure;
plot(time, states);
xlabel('Time');
ylabel('Temperature');
title('Temperature Response');
Prediction model
function dTdt = prediction_model_jl(x,u,Par)
% Parameters
Ta = Par(1); % K
U = Par(2); % W/m^2-K
m = Par(3); % kg
Cp = Par(4); % J/kg-K
A = Par(5); % Area in m^2
alpha = Par(6); % W / % heater
eps = Par(7); % Emissivity
sigma = Par(8); % Stefan-Boltzman % Stefan-Boltzman
% Temperatura
T= x(1);
% Entradas
Q= u(1);
% Ecuaciones de los balances de energía
dTdt = (1.0/(m*Cp))*(U*A*(Ta-T) ...
+ eps * sigma * A * (Ta^4 - T^4) ...
+ alpha*Q);
end
Plant model
function dTdt = heat2(time,x,Q)
% Parameters
Ta = 23 + 273.15; % K
U = 10.0; % W/m^2-K
m = 4.0/1000.0; % kg
Cp = 0.5 * 1000.0; % J/kg-K
A = 12.0 / 100.0^2; % Area in m^2
alpha = 0.01; % W / % heater
eps = 0.9; % Emissivity
sigma = 5.67e-8; % Stefan-Boltzman
% Temperature State
T = x(1);
% Nonlinear Energy Balance
dTdt = (1.0/(m*Cp))*(U*A*(Ta-T) ...
+ eps * sigma * A * (Ta^4 - T^4) ...
+ alpha*Q);
end
Answers (1)
Walter Roberson
on 18 Jul 2023
0 votes
You might need to set nlobj.Parameters to a cell array containing the sample time.
Categories
Find more on Wind Power 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!