Error in my code
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Azzi Abdelmalek
on 19 May 2013
%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)
0 Comments
More Answers (5)
Walter Roberson
on 18 May 2013
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.
0 Comments
Edward Desmond
on 14 Jul 2023
% 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);
0 Comments
See Also
Categories
Find more on General Applications 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!