Last active
July 1, 2019 22:00
-
-
Save ethanmpeterson/3703bf824e350bb826f2ee36a02d2aa1 to your computer and use it in GitHub Desktop.
MATLAB RLC circuit demo code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| clc | |
| caps = [1, 2, 3, 4]; % put actual capacitor numbers here (Converted to SI units ie. Ferads) | |
| inductors = [1, 2, 3, 4]; % put inductor values here (Converted to SI units ie. Henrys) | |
| targetFrequency = 1200 * 10^3; | |
| for i = 1 : length(caps) % goes through elements in caps array | |
| for j = 1 : length(inductors) % goes through all inductors | |
| % run the amplitude function (the loops will take care of every combo) | |
| A = amp(caps(i), inductors(j), targetFrequency); | |
| % print the amplitude result | |
| out = sprintf('amplitude: %f, cap: %f, inductor: %f', A, i, j); | |
| disp(out) | |
| end | |
| end | |
| % amplitude func takes inductor cap and target freq values returns resulting amplitude | |
| function amplitude = amp(L, C, f) | |
| amplitude = (f*2*pi) / sqrt((L*(2*pi*f)^2 - 1/C)^2 + (f * 2 * pi)^2); | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment