how to discretize a nonlinear model using Matlab

I have this continuous nonlinear system and I want to discretize it using Matlab
If anyone can help me? This is the differential equations of the system
This is the state space model according to the authors of the paper that I’m studying
I want to know how to insert it in m files and how to make it discrete .. any idea??

 채택된 답변

Alan Stevens
Alan Stevens 2020년 7월 14일

0 개 추천

This is a simultaneous, linear system.
You could do something like the following (replacing my arbitrary data with your actual data):
% Initial conditions
Te0 = 300; Tr0 = 300;
y0 = [Te0, Tr0];
tspan = [0 10];
[t, y] = ode45(@rates, tspan, y0);
Te = y(:,1); Tr = y(:,2);
plot(t,Te,t,Tr)
function dydt = rates(~,y)
% Data (obviously replace with the true values)
Ce = 1; Cpc = 1; Cr = 1; Cpa = 1;
Qin = 2; Qo = 2;
mdotr = 3; mdotf = 3;
en = 1;
Tinf = 273;
% Components
Te = y(1); Tr = y(2);
% Equations
dTedt = Qin/Ce - Cpc*mdotr*(Te - Tr)/Ce;
dTrdt = -Qo/Cr + Cpc*mdotr*(Te - Tr)/Cr - en*Cpa*mdotf*(Te - Tinf);
% Return rates
dydt = [dTedt; dTrdt];
end

댓글 수: 5

F.M
F.M 2020년 7월 15일
thank u very much.. but my main problem is how to discretize this system, your code is solving the differential equations. is there a way to disretize my system??
Alan Stevens
Alan Stevens 2020년 7월 15일
편집: Alan Stevens 2020년 7월 15일
It is discretised! The solution gives discrete values of Te and Tr at discrete times.
If you want to discretise it yourself, you can set dTe/dt = (Te(i+1) - Te(i))/deltat (and a similar representation of dTr/dt), where i refers to the i'th timestep. On the right hand side you could use Te(i) and Tr(i), which would give a simple, explicit, Euler representation, or Te(i+1) and Tr(i+1), which would lead to an implicit Euler solution. Alternatively, you could use a higher order discretisation, but then you might as well use Matlab's ode45, which does just that.
It's possible I haven't fully understood what it is you want to do!
F.M
F.M 2020년 7월 15일
yes yes.. it seems right .. thank you very much..
but can I do the same using state space representation? I mean somthing like the code above? can I write a code inserting the system as matricess instead of diff equations?? what should i change?
You mean something like this:
% Time data
endtime = 10;
N = 1000; % number of timesteps
dt = endtime/N;
% Initial conditions
Te0 = 300; Tr0 = 300;
x(:,1) = [Te0; Tr0];
t = zeros(1,N);
% Loop through timesteps
for k = 1:N-1
x(:,k+1) = x(:,k) + xdot(x(:,k))*dt; % Simple Euler integration
t(k+1) = dt + t(k);
end
Te = x(1,:); Tr = x(2,:);
plot(t,Te,t,Tr)
function dxdt = xdot(x)
% Data
Ce = 1; Cpc = 1; Cr = 1; Cpa = 1;
Qin = 2; Qo = 2;
mdotr = 3; mdotf = 3;
en = 1;
Tinf = 273;
Te = x(1); Tr = x(2); % Extract temperatures
% Define f, g and u
f = [Qin/Ce; -Qo/Cr];
g = [-Cpc/Ce*(Te - Tr) 0; Cpc/Cr*(Te - Tr) -en*Cpa/Cr*(Te - Tinf)];
u = [mdotr; mdotf];
%Calculate rates of change wrt time
dxdt = f + g*u;
end
F.M
F.M 2020년 7월 19일
I think it may work with some modifications.. thank you very much..

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

제품

질문:

F.M
2020년 7월 14일

댓글:

F.M
2020년 7월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by