Function, tablelookup, is wrong
9 次查看(过去 30 天)
显示 更早的评论
I converted the 1 rc circuit to 2 rc circuit, but when I run it, I encounter this error. The 2nd rc I added is showing the error location. Below I share the code, error and view of circuit. Can you help me?
component C_table
% C_table
% Models a capacitor where the capacitance value (C) depends on an external
% physical signal inputs SOC and T. It is assumed that the capacitance value
% is slowly varying with time, and hence the equation i = C*dv/dt holds.
% Copyright 2012-2017 The MathWorks, Inc.
nodes
p = foundation.electrical.electrical; % +:left
n = foundation.electrical.electrical; % -:right
end
inputs
T = {293.15,'K'}; %T:left
SOC = {1,'1'}; %SOC:left
end
parameters
C_Table = {ones(5,3),'F'} % Matrix of capacitance values, C(SOC,T)
SOC_Table = {[0;0.1;0.5;0.9;1],'1'} % State of charge (SOC) breakpoints
Temp_Table = {[273.15 293.15 313.15],'K'} % Temperature (T) breakpoints
v0 = {0,'V'}; % Initial voltage across capacitor
end
variables(Access=private)
i = { 0, 'A' }; % Current
v = {value=v0, priority=priority.high}; % Voltage
end
branches
i : p.i -> n.i;
end
equations
assert(all(C_Table(:) > 0))
assert(all(SOC_Table(:) >= 0))
assert(all(Temp_Table(:) >= 0))
v == p.v - n.v;
let
% Perform the table lookup
C = tablelookup(SOC_Table,Temp_Table,C_Table,SOC,T,...
% Models a capacitor where the capacitance value (C) depends on
% an external physical signal inputs SOC and T.
% It is assumed that the capacitance value is slowly varying with time, and hence the equation i = C*dv/dt holds.
interpolation=linear,extrapolation=nearest)
in
% Electrical equation
i == C * v.der;
end
end
end
回答(1 个)
Anurag Ojha
2024-10-3
Hey
This commonly occurs when the input variables in the lookup table (i.e., SOC and T) do not have compatible units with the breakpoints defined in the table.
Ensure that all the input data to the tablelookup function, including SOC, T, SOC_Table, and Temp_Table, have commensurate units. If any of these parameters is passed in a different unit, it could cause this error.
If the inputs to "tablelookup" are unit-consistent, but you're still seeing the error, consider explicitly ensuring unit compatibility using the unitConvert function before passing values to "tablelookup".
Adding syntax and MATLAB documentation for your reference:
SOC_converted = unitConvert(SOC, '1');
T_converted = unitConvert(T, 'K');
C = tablelookup(SOC_Table, Temp_Table, C_Table, SOC_converted, T_converted, ...
interpolation=linear, extrapolation=nearest)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Circuit Envelope Simulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!