- You needed the current to also be a variable, along with its corresponding branches section defining the polarity of the current.
- You did not need need to define omega as a variable and create a separate equation for it.
Simscape language: AC Voltage Source - variable frequency input - Problem: Number of equations exceeds number of variables.
17 views (last 30 days)
Show older comments
Hello everyone,
I try to write a file which will produce an AC Voltage Source in Simscape using the Simscape language. My goal is to vary the frequency by using an external signal.
This is my code:
component AC_frequ
%AC_frequ
%
%AC Voltage source - variable frequencies
%
nodes
v_p = foundation.electrical.electrical; %+ :top
v_n = foundation.electrical.electrical; %- :bottom
end
variables
v = { 0, 'V' }; % Voltage
omega = { 0, 'rad/s' }; % angular velocity
end
inputs
f = { 0, 'Hz' } %Frequenz :bottom
end
parameters
amp = { 1, 'V' }; % Peak amplitude
shift = { 0, 'deg' }; % Phase shift
end
equations
v == v_p.v - v_n.v;
v == amp*sin(omega*time + shift);
omega == {2*pi,'rad'}*f;
end
end
When I use the file in my simulation, it tells me the following: "Number of equations exceeds number of variables."
Can anyone spot my mistake?
0 Comments
Accepted Answer
Sebastian Castro
on 29 Mar 2016
Edited: Sebastian Castro
on 29 Mar 2016
As the error message suggested, you have 3 equations but 2 variables. Two issues:
This component file worked perfectly for me:
component AC_frequ
nodes
p = foundation.electrical.electrical; % +:top
n = foundation.electrical.electrical; % -:bottom
end
variables
i = { 0, 'A' }; % Current
v = { 0, 'V' }; % Voltage
end
parameters
amp = { 1, 'V' }; % Peak amplitude
shift = { 0, 'deg' }; % Phase shift
end
inputs
frequency = { 60, 'Hz' }; % f: bottom
end
branches
i : p.i -> n.i;
end
equations
v == p.v - n.v;
v == amp*sin(frequency*time + shift);
end
end
- Sebastian
3 Comments
Sebastian Castro
on 30 Mar 2016
No problem!
Omega could be a variable, but it would introduce an extra set of equations into the system that you don't exactly need.
Variables are mostly necessary if you want to keep track of, log, initialize, or measure time-varying dynamic variables. If it's just some internal counter like in this case (frequency*time), a variable isn't necessary.
- Sebastian
Ali Degan
on 19 Mar 2017
Edited: Ali Degan
on 19 Mar 2017

I tried to mimic what you have written but I got an error. Can you please help me to resolve this error?
"The following block(s) do not have resolved block library links: 'acfre/AC_frequ' Physical Modeling blocks cannot have broken or inactive library links. Please restore library links for all Physical Modeling blocks."
Also, Can I make my own model in simscape technology instead of simscape component?
More Answers (0)
See Also
Categories
Find more on Electrical Sensors in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!