Error in my code
Mostrar comentarios más antiguos
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 comentarios
Azzi Abdelmalek
el 18 de Mayo de 2013
Can you post the values of A,Bc,C,Dc,u and t
Brwa
el 19 de Mayo de 2013
Respuesta aceptada
Más respuestas (5)
Walter Roberson
el 18 de Mayo de 2013
0 votos
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
el 19 de Mayo de 2013
Editada: Azzi Abdelmalek
el 19 de Mayo de 2013
Brwa
el 20 de Mayo de 2013
0 votos
Brwa
el 20 de Mayo de 2013
0 votos
Edward Desmond
el 14 de Jul. de 2023
0 votos
% 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);
Categorías
Más información sobre General Applications en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!