step response comparison of linear and non linear model

7 次查看(过去 30 天)
NON-LINEAR MODEL EQUATIONS:
xdot1,xdot2,xdot = states derivatives; x1,x2,x3=states; u1,u2,u3=inputs; y1,y2,y3=outputs
xdot1= (-0.0018*u2*x1^(9/8))+(0.9*u1) -(0.15*u3);
xdot2=((((0.73*u2)-0.16)*x1^(9/8)-x2))/10;
xdot3= ((141*u3)-((1.1*u2)-0.19)*x1)/85;
y1= x1;
y2= x2;
y3= 0.05*((0.13073*x3) + (100*((1-(0.001538*x3))*((0.8*x1)- 25.6))/(x3*(1.0394-0.00123404*x1))) +(((((0.854*u2) -0.147)*x1) + (45.59*u1) -(2.514*u3) -2.096)/9) -67.975);
LINEAR STATE SPACE MODEL FROM THE NON LINEAR MODEL:
a = [-0.0025087 0 0
0.069424 -0.1 0
-0.0066941 0 0];
b= [ 0.9 -0.34904 -0.15
0 14.155 0
0 -1.3976 1.6588];
c=[1 0 0
0 1 0
0.0063465 0 0.004705];
d=[0 0 0
0 0 0
0.25328 0.5124 -0.013967];
I have attached the step response for linear model. i want the step response for non linear model and compare with the linear model for the initial conditions (x10=108;x20=66.65;x30=428)

回答(1 个)

Sam Chak
Sam Chak 2023-12-16
To compare the results, you need to solve the linear system and generate the linear outputs, just as you would for the nonlinear system in this link: Step Response of Nonlinear Model. Once you have both the linear and nonlinear results, you can plot them for comparison using the uipanel() and tiledlayout() commands.
% ------ The Beginning of Script ------
%% Task 1: Call ode45 to solve both linear & nonlinear systems
tspan = [0 1];
x0 = [108; 66.65; 428]; % <-- non-zero initial values
[tL, xL] = ode45(@kruthikaLNS, tspan, x0);
[tN, xN] = ode45(@kruthikaLNS, tspan, x0);
%% Task 2: Generate both linear & nonlinear output vectors
% Outputs from Linear system
for j = 1:numel(tL)
[~, yL(j,:)] = kruthikaLNS(tL(j), xL(j,:).');
end
% Outputs from Nonlinear system
for k = 1:numel(tN)
[~, yN(k,:)] = kruthikaNLS(tN(k), xN(k,:).');
end
%% Task 3: Plot Output responses
% Setup UI panels for Tiled Layouts
f = figure;
p1 = uipanel('parent', f);
p2 = uipanel('parent', f);
p1.BackgroundColor = [1, 1, 1];
p2.BackgroundColor = [1, 1, 1];
% p.Position = [X_Start, Y_start, Length, Height];
p1.Position = [0.0, 0.0, 0.5, 1.0];
p2.Position = [0.5, 0.0, 0.5, 1.0];
T1 = tiledlayout(p1, 3, 1);
T2 = tiledlayout(p2, 3, 1);
% Plot the desired graphs in the tiles
nexttile(T1);
plot(tL, yL(:,1)), grid on, ylabel('y_{1}') % Linear Output y1
nexttile(T1);
plot(tL, yL(:,2)), grid on, ylabel('y_{2}') % Linear Output y2
nexttile(T1);
plot(tL, yL(:,3)), grid on, ylabel('y_{3}') % Linear Output y3
nexttile(T2);
plot(tN, yN(:,1)), grid on, ylabel('y_{1}') % Nonlinear Output y1
nexttile(T2);
plot(tN, yN(:,2)), grid on, ylabel('y_{2}') % Nonlinear Output y2
nexttile(T2);
plot(tN, yN(:,3)), grid on, ylabel('y_{3}') % Nonlinear Output y3
% Label the axes of shared tiles
title( T1, 'Linear System')
xlabel(T1, 'Time')
ylabel(T1, 'Output states')
title( T2, 'Nonlinear System')
xlabel(T2, 'Time')
ylabel(T2, 'Output states')
% ------ The End of Script ------
% Put local function files at the end of the executable script
%% Linear System
function [xdot, y] = kruthikaLNS(t, x)
% Initialzations
xdot = zeros(3, 1);
y = zeros(3, 1);
u = zeros(3, 1);
% Input signals: step functions
u(1) = (t >= 0)*1;
u(2) = u(1);
u(3) = u(2);
% State matrix
A = [-0.0025087 0 0;
0.069424 -0.1 0;
-0.0066941 0 0];
% Input matrix
B = [ 0.9 -0.34904 -0.15;
0 14.155 0;
0 -1.3976 1.6588];
% Output matrix
C = [ 1 0 0;
0 1 0;
0.0063465 0 0.004705];
% Direct matrix
D = [ 0 0 0;
0 0 0;
0.25328 0.5124 -0.013967];
% Linear State-Space
xdot = A*x + B*u;
% Linear Output equation
y = C*x + D*u;
end
%% Nonlinear System
function [xdot, y] = kruthikaNLS(t, x)
% Initialzations
xdot = zeros(3, 1);
y = zeros(3, 1);
% Definitions
x1 = x(1);
x2 = x(2);
x3 = x(3);
% Input signals: step functions
u1 = (t >= 0)*1;
u2 = u1;
u3 = u2;
% ODEs
xdot(1) = (-0.0018*u2*x1^(9/8)) + (0.9*u1) - (0.15*u3);
xdot(2) = ((((0.73*u2)-0.16)*x1^(9/8)-x2))/10;
xdot(3) = ((141*u3)-((1.1*u2)-0.19)*x1)/85;
% Outputs
y(1) = x1;
y(2) = x2;
y(3) = 0.05*((0.13073*x3) + (100*((1-(0.001538*x3))*((0.8*x1)-25.6))/(x3*(1.0394-0.00123404*x1))) +(((((0.854*u2) -0.147)*x1) + (45.59*u1) -(2.514*u3) -2.096)/9) -67.975);
end

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by