Error in my code

1 次查看(过去 30 天)
Brwa
Brwa 2013-5-18
Hi everyone, Im trying to run a dynamic system, but i got some error. if someone know the source of this error please explain it. sys=ss(A,Bc,C,Dc); y=lsim(sys,u,t);
??? Error using ==> DynamicSystem.lsim at 85 When simulating the response to a specific input signal, the input data U must be a matrix with as many rows as samples in the time vector T, and as many columns as *input channels.***
number of rows of U is exactly the same as T. I dont know what does Input Channels mean?
Your help will be apprecuated
  2 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2013-5-18
Can you post the values of A,Bc,C,Dc,u and t
Brwa
Brwa 2013-5-19
Hi Azzi, its abig matrix, so please look at my answer i have explained the question in more detail
Thanks

请先登录,再进行评论。

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2013-5-19
%Dc is (9,2), which means that your system has 2 inputs ans 9 outputs
the input u should be (100,2)
and t (100,1)

更多回答(5 个)

Walter Roberson
Walter Roberson 2013-5-18
If I recall correctly (dubious), the number of input channels is set when you construct "sys", so you have to match one of the sizes with that.

Brwa
Brwa 2013-5-19
编辑:Azzi Abdelmalek 2013-5-19
thanks for your answers and comments. actually Im trying to solve a state space sytem which is
x'=Ax + Bc*u
y =Cx + Dc*u
sys=ss(A,Bc,C,Dc);
y=lsim(sys,u,t);
where
A (6,6) matrix
Bc is (6,2)
C is (9,6)
Dc is (9,2).
u is (100,1) vector
t is (100,1) vector
I hope someone can help me, I appreciate all your helps

Brwa
Brwa 2013-5-20
Thanks Mr. Azzi Abdelmalek. yes, you are right.

Brwa
Brwa 2013-5-20
I have posted another question, please take alook if you can answer me. I appreciate your help

Edward Desmond
Edward Desmond 2023-7-14
% Given parameters
Pr = 2.65; % Average density (g/cm³)
Kr = 7.75e-3; % Thermal conductivity (cal/cm s °C)
Cp = 0.197; % Heat capacity (cal/g °C)
Tinit = 323; % Initial temperature (K)
Tapplied = 423; % Applied temperature (K)
tmax = 2; % Simulation time (years)
reservoirExtent = 75; % Reservoir extent (m)
% Convert units
Kr = Kr * 418.4; % Convert thermal conductivity to (W/m K)
Cp = Cp * 4.184; % Convert heat capacity to (J/kg K)
% Discretization parameters
nr = 100; % Number of radial grid points
dr = reservoirExtent / (nr - 1); % Radial grid spacing
% Time discretization parameters
dt = 0.01; % Time step size
nt = round(tmax * 365.25 * 24 * 60 * 60 / dt); % Number of time steps
% Initialize temperature matrix
T = zeros(nr, nt+1);
T(:, 1) = Tinit; % Set initial temperature
% Perform time-stepping
for i = 1:nt
% Perform radial discretization
for j = 2:nr-1
% Calculate thermal diffusivity
alpha = Kr / (Cp * Pr);
% Calculate radial derivatives
dT_dr = (T(j+1, i) - T(j-1, i)) / (2 * dr);
d2T_dr2 = (T(j+1, i) - 2 * T(j, i) + T(j-1, i)) / (dr^2);
% Update temperature using finite difference method
T(j, i+1) = T(j, i) + alpha * dt * (d2T_dr2 + (1 / j) * dT_dr);
end
% Apply boundary conditions
T(1, i+1) = T(2, i+1); % Symmetry boundary condition
T(nr, i+1) = T(nr-1, i+1) + dr * (Tapplied - T(nr, i+1)); % Heat conduction at reservoir boundary
end
% (1) Reservoir temperature at a distance of 20 m after 2 years
distance = 20;
index = round(distance / dr) + 1; % Add 1 to account for MATLAB indexing
temperature = T(index, end);
% (2) Energy needed to heat the reservoir at 20 m
mass = Pr * reservoirExtent * pi * dr^2;
energy = mass * Cp * (Tapplied - Tinit);
% (3) Viscosity change at 20 m (using a hypothetical correlation)
viscosityInitial = 10; % Initial viscosity (cP)
correlationConstant = 0.5;
viscosityChange = correlationConstant * (temperature - Tinit);
% Plotting temperature profile
r = linspace(0, reservoirExtent, nr);
figure;
plot(r, T(:, end));
xlabel('Radial Distance (m)');
ylabel('Temperature (K)');
title('Temperature Profile in the Reservoir');
% Displaying the results
fprintf('Reservoir temperature at 20 m after 2 years: %.2f K\n', temperature);
fprintf('Energy needed to heat the reservoir at 20 m: %.2f J\n', energy);
fprintf('Viscosity change at 20 m: %.2f cP\n', viscosityChange);

类别

Help CenterFile Exchange 中查找有关 General Applications 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by