RLC Circuit Equation Implementation-Runge Kutta

Hello, I need to convert an RLC equation to work inside the functions I have wirtten. Currently MatLab is telling me there are too many variables inside my equation for it to work. Here is the code of the function I am trying to work with
function [derriv_value] = RLC(y)
%Function that contains the derrivative value
%RLC Implementation: The equation is given by L*Q'' + R*Q' + (1/C)*Q = E(t)
% E(t) is the sum of total voltage drop across the circuit.
% R is resistance, L is indunctance, and C is capacitance. Q Is the charge
% in coloumbs. This equation is currently in a second order form.
% In most cases, the voltage in the system is known, it is usually the
% current (I) that is unknown.
% If we differentiate both sides and subsitute Q for I, we get,
% L*I'' + R*I' + (1/C)*I = E'(t)
% Since this is the more pratical case, we will use this format.
% Here are some values that could be used to simulate this.
% These above are some example values.
R = 10; % Resistance (Series RL Branch), Ohms..
L = 100e-3; % Inductance (Series RL Branch), H..
C = 50e-6; % Capacitor (Series RLC Branch), F
derriv_value = L*y(3)+R*y(2)+(1/C)*y;
end
And this function will be called in a Runge Kutta implementation file. I'll attach it. I have another file called FunctionC that has a format that matlab accepts. It works with the Runge Kutta file.

댓글 수: 2

darova
darova 2019년 11월 12일
Read this
Yeah I already looked over that. I have the equation converted fine on paper, the issue is trying to set up a system of 3 first order ODEs in a format that will run like the equation in FunctionC.

댓글을 달려면 로그인하십시오.

 채택된 답변

Daniel M
Daniel M 2019년 11월 12일

1 개 추천

Instead of this
derriv_value = L*y(3)+R*y(2)+(1/C)*y;
Do you mean this?
derriv_value = L*y(3)+R*y(2)+(1/C)*y(1);

댓글 수: 9

Yes, I meant to use y(1), I've corrected it in my current copy of the code, but it still does not work. MatLab says the equation I am trying to use has too many input arguments for MyVec_Function2
Daniel M
Daniel M 2019년 11월 12일
편집: Daniel M 2019년 11월 12일
Can you show exactly how you are calling these three functions in a script and the exact error message. If you're passing RLC as the input F into MyVec_Function2, then your error is the fact that you're trying to access F(x(i), y(i)), but RLC only has one input RLC(y). So, yes, you are putting in too many input arguments. You need to adapt either MyVec_Function2, or RLC.
It would be fairly straightforeward to turn RLC into an anonymous function of x and y, which you could just put somewhere in the script that calls MyVec_Function2.
% set the constants
R = 10;
L = 100e-3;
C = 50e-6;
RLC_anon = @(x,y) L*y(3) + R*y(2) + (1/C)*y(1);
% renamed it RLC_anon, since you probably still have the original RLC() in the same directory.
% now pass RLC as the first input into MyVec_Function2
[x,y] = MyVec_Function2(@RLC,0.01,1,20,[0;1])
This is how I call RLC into MyVec_Function2
Oh, and here is the error,
Error using RLC
Too many input arguments.
Error in MyVec_Function2 (line 9)
k1 = F( x(i) , y(:,i) ); % Altered
Right. So you are passing in x(i), which is a single element, and y(:,i) which is a 2x1 array, into RLC which only takes a single input that is [1x3] or [3x1].
Do you intend x(i) to be the value for y(1), and y be the values for y(2) and y(3)? If so, you can adapt RLC like this:
function [derriv_value] = RLC2(y1,y23)
R = 10;
L = 100e-3;
C = 50e-6;
derriv_value = L*y23(2)+R*y23(1)+(1/C)*y1;
end
Otherwise.... you're just calling the function wrong.
darova
darova 2019년 11월 12일
THe main equation is here i think
321.png
That seemed to work, that last format you posted there. I think that is what the problem was. Setting the xi values up for the function. Thanks!
How would you get this equation into a system of 3 first order ODEs?
Your equation is of second order
% L*Q'' + R*Q' + (1/C)*Q = E(t)
% Q'' = 1/L*( E(t) - R*Q' - Q/C );
f = @(t,y) [y(2)
1/L*(E - R*y(2) - y(1)/C)];
[t,y] = ode45(f,ts,y0);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Circuits and Systems에 대해 자세히 알아보기

태그

질문:

2019년 11월 12일

댓글:

2019년 11월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by