RLC circuit impulse response

Hello, i'm really new to Matlab and i don't understand how it works.
I need to plot the impulse of a series rlc circuit, using discrete analysis.
Here is my code:
function [ y ] = rlc( C,R,L,t )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
alpha=t*R*C+L*C+t.^2;
beta=R*C+2*L*C;
for k=1:10;
x = k==1;
y(k+2)=x(k).*(t^2./alpha) + (beta./alpha)*y(k+1) - ((L*C)./alpha)*y(k);
plot(y,t)
end
But every time i run it, i got
A(I)=B, the number of elements in B and I must be the same.
I don't know how to fix it.
Can someone help me?
Thanks

Answers (4)

Geoff
Geoff on 2 Apr 2012
Are you expecting y to be a vector, or a matrix?
When you assign to y(k+2), it needs to be a single value. But on the right-hand side it looks like you have a vector.
Nicolas
Nicolas on 2 Apr 2012
Thanks for your answer.
I expect y to be a value that i can plot after the for loop. What should I do to get value on the two sides of the equation?

1 Comment

Well, I don't know what assumptions there are about the rest of your variables. Whether they are scalars or vectors... It LOOKS like you are doing a vector operation, that's all. What exactly are the values C, R, L, and t?
Also, your line 'x = k==1' makes no sense. That makes 'x' a logical scalar, but you then access it as an array.

Sign in to comment.

Nicolas
Nicolas on 2 Apr 2012
Hey, you just clearly shown that i'm a newbie :)
Well, C = 1.e-6 , R=0.1, L=1.e-6:1.e-1:1.e-10, and t=0:1.e-8:1.e-6;
Does the problem arise from the fact that R and C are constant?

1 Comment

That's okay. It's not an issue with your constants. But your value for L is not right - it's an empty matrix. The start is bigger than the end, and the increment is bigger than the range.
Also, L has to be the same length as T for 'alpha' formula to work. If that doesn't make logical sense then there is something fundamentally erroneous about how you are using these values.
We need to clear this up before we can even look at the formula in the loop.
As an aside, you may want to look up the function 'linspace' for generating series. It _might_ be more appropriate for dividing up your time scale.

Sign in to comment.

Nicolas
Nicolas on 2 Apr 2012
Ok, what if I use C,R,L as constant, and only time range T ? And, i want x(k) to be 1 when k = 1 , x(k)=0 for any other k, that's why i used x = k==1

3 Comments

Can you please reply in the comments unless you need to post some code?
So this still doesn't explain why t^2 is in the equation for alpha. To me, alpha looks like it should be a scalar. But using t^2 makes it an array.
Why do you loop from 1 to 10? Are you trying to calculate a value for the first 10 times, or are you trying to calculate the entire vector for all times and then refine that 10 times?
Remember, people here don't necessarily understand the theory behind what you are doing.
So, can you please explain what your formula for 'y' is trying to express, and what alpha and beta mean?
For your query about 'x', just multiply by 'x' not by 'x(k)'.
I have an rlc circuit, and i have to use the discrete analysis to plot its impulse response. So, from the circuit i've got the differential equation and from the DE i got the discrete equation which is y(k+2)= something in function of y(k) and y(k-1).
At the end i'd like to plot y in function of t. My loop is from 1 to 10 because i need to calculate some values for my graph.
Thanks
Please realise that you understand what an RLC circuit is, and you understand what the equations mean, but I don't. I'm a programmer. I want to help you with your code, but because I don't understand the meaning of the equations I can't help to identify the problem. I understand you want to calculate values for a graph, and we'll get to that, but I'm asking what those values are.
What is k? How does it relate to time, if at all? You have a problem because your equation uses a time vector to create supposedly a single value.
Here's what I think:
k is an iteration. You compute the entire graph (for all values of t) once, but it's only an approximation. You have to repeat this several times and then you want to graph the result. So y(k) in fact relates to an iteration and not a single value. One calculation of the vector 'y' relies on the two previous calculations for 'y'. Is this correct?

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Asked:

on 2 Apr 2012

Community Treasure Hunt

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

Start Hunting!