Error in Trying to Build a Custom Variable Resistor In MATLAB Simulink
19 ビュー (過去 30 日間)
古いコメントを表示
Hey everyone, I'm in the process of trying to build a custom variable resistor using simulink. I created a code for a simscape component in MATLAB but it's giving me an error saying "Invalid use of a MATLAB function in This Context" when I try inserting the simscape component in simulink. Shown below is my code:
The error happens on line 26 (the equation with variable R). Are there any tips or suggestions to fix my error?
component VoltageDependentResistor
% Voltage-dependent resistor
% This resistor's value changes based on the voltage across it.
nodes
p = foundation.electrical.electrical; % positive terminal
n = foundation.electrical.electrical; % negative terminal
end
parameters
alpha = {1, '1/V'}; % Coefficient for voltage dependence
epsilon = 0.6;
sigma = 5.67E-8
end
variables
v = { 0, 'V' }; % Voltage across the resistor
i = { 0, 'A' }; % Current through the resistor
end
branches
i : p.i -> n.i; % Current from p to n
end
equations
v == p.v - n.v; % Voltage across the resistor
R == 1/((epsilon*sigma*(p.v^2+n.v^2)*(p.v+n.v))/(2-epsilon)); % Resistance as a function of radiative heat transfer
v == R * i; % Ohm's Law
end
end
Thanks for your time and help,
Elias Lynch
0 件のコメント
採用された回答
Abhishek Kumar Singh
2024 年 5 月 18 日
Hi Elias,
When attempting to use your provided code within MATLAB R2023a, I encountered an error within the Block Parameter dialog box of the Simscape component, specifically for 'VoltageDependentResistor':
Failed to generate 'VoltageDependentResistor'
Caused by:
'R' is not defined in this scope.
To address this, I introduced the following line of code to define the resistance:
R = { 0, 'Ohm' }; % Defining the resistance of the resistor
However, this led to a subsequent error:
Failed to generate 'VoltageDependentResistor'
Caused by:
Type mismatch for equation. The left hand side of the equation is {[1x1 double], 'Ohm'} and the right hand side of the equation is {[1x1 double], '1/V^3'}.
R = {[1x1 double], 'Ohm'}
epsilon = 0.6000
sigma = 5.6700e-08
p.v = {[1x1 double], 'V'}
n.v = {[1x1 double], 'V'}
The error suggests a dimensional analysis issue within the formula implementation. To rectify this, I suggest introducing a new parameter, k, with units that, when multiplied by the right-hand side (RHS) of the resistance equation, yield units that match the left-hand side (LHS) resistance units. Here's how you might define k:
k = {1, 'V^4/A'}; % New parameter to adjust unit mismatch
Then, update the resistance equation as follows to incorporate k:
R == k * (1/((epsilon * sigma * (p.v^2 + n.v^2) * (p.v + n.v)) / (2 - epsilon))); % Updated resistance equation
This adjustment is just a workaround to resolve the encountered error.
It's crucial to revisit the original formula and its implementation within Simscape to ensure accuracy and correctness.
Hope it helps!
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Electrical Sensors についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!