Azzera filtri
Azzera filtri

Error in Trying to Build a Custom Variable Resistor In MATLAB Simulink

8 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Abhishek Kumar Singh
Abhishek Kumar Singh il 18 Mag 2024
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!

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by