Error in Trying to Build a Custom Variable Resistor In MATLAB Simulink
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 LynchHey 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 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 simulink, matlab, simscape MATLAB Answers — New Questions