summaryrefslogtreecommitdiff
path: root/coursework17/RLC_script.m
blob: 42f0344c6906e3c102bb9f20627ef8aed5ff17b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
h = 1e-4;
R = 280;
C = 4*10^(-6);
L = 600*10^(-3);
t0 = 0;
tf = 0.04;
N = round((tf-t0)/h);

y = zeros(1, N);
x = zeros(1, N);
t = zeros(1, N);
n = zeros(1, N);


t(1) = t0;
Vout = zeros(1, N);
x(1) = 500*10^(-9);
y(1) = 0;
Vin = @(a)5;
g = @(t,x,y) y;
f = @(t,x,y)(Vin(t) - x/C - R*y)/L;
for i = 1:N-1
    [x(i+1), y(i+1)] = RK4second(t(i),x(i),y(i),h,g,f);
    t(i+1) = t(i) + h;
    Vout(i) = R*y(i);
end
plot(Vout);