Function, tablelookup, is wrong
조회 수: 4 (최근 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!