diff options
author | Vasil Zlatanov <v@skozl.com> | 2017-02-23 12:56:18 +0000 |
---|---|---|
committer | Vasil Zlatanov <v@skozl.com> | 2017-02-23 12:56:18 +0000 |
commit | 3cf86838be8a410e3bf70d450d50db3d799026e9 (patch) | |
tree | 66707e6fbbadd72cb60aafa63e22e2a233374a89 /coursework17 | |
parent | 0cf1fa44a5e8d35ce263954bd53bb94b7b0f9099 (diff) | |
download | e2-matlab-3cf86838be8a410e3bf70d450d50db3d799026e9.tar.gz e2-matlab-3cf86838be8a410e3bf70d450d50db3d799026e9.tar.bz2 e2-matlab-3cf86838be8a410e3bf70d450d50db3d799026e9.zip |
accept exerercise 3 form Alex
Diffstat (limited to 'coursework17')
-rw-r--r-- | coursework17/RK4second.m | 12 | ||||
-rw-r--r-- | coursework17/RLC_script.m | 27 |
2 files changed, 39 insertions, 0 deletions
diff --git a/coursework17/RK4second.m b/coursework17/RK4second.m new file mode 100644 index 0000000..7388c27 --- /dev/null +++ b/coursework17/RK4second.m @@ -0,0 +1,12 @@ +function [x, y] = RK4second(t,x,y,h,g,f)
+k1x = h*g(t, x,y);
+k1y = h*f(t, x,y);
+k2x = h*g(t+h/3, x+k1x/3, y+k1y/3);%if it doesnt work try k1y after y
+k2y = h*f(t+h/3, x+k1x/3, y+k1y/3);
+k3x = h*g(t+2*h/3, x-k1x/3+k2x, y-k1y/3+k2y);
+k3y = h*f(t+2*h/3, x-k1x/3+k2x, y-k1y/3+k2y);
+k4x = h*g(t+h, x+k1x-k2x+k3x, y+k1y-k2y+k3y);
+k4y = h*f(t+h, x+k1x-k2x+k3x, y+k1y-k2y+k3y);
+x = x+(1/8)*(k1x+3*k2x+3*k3x+k4x);
+y = y+(1/8)*(k1y+3*k2y+3*k3y+k4y);
+end
diff --git a/coursework17/RLC_script.m b/coursework17/RLC_script.m new file mode 100644 index 0000000..42f0344 --- /dev/null +++ b/coursework17/RLC_script.m @@ -0,0 +1,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);
|