summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasil Zlatanov <v@skozl.com>2017-02-21 19:49:46 +0000
committerVasil Zlatanov <v@skozl.com>2017-02-21 19:49:46 +0000
commitcf767337fb89aae07e791189e785cb46c0e92c09 (patch)
tree6a9b748b0642146adda8636fb941f98673cb35e4
parent07786a8de0f5f5cfc58138fe1f26a489c862f470 (diff)
downloade2-matlab-cf767337fb89aae07e791189e785cb46c0e92c09.tar.gz
e2-matlab-cf767337fb89aae07e791189e785cb46c0e92c09.tar.bz2
e2-matlab-cf767337fb89aae07e791189e785cb46c0e92c09.zip
finish exact solution
-rw-r--r--coursework17/error_script.m19
1 files changed, 13 insertions, 6 deletions
diff --git a/coursework17/error_script.m b/coursework17/error_script.m
index 2744ba9..08a42d2 100644
--- a/coursework17/error_script.m
+++ b/coursework17/error_script.m
@@ -6,21 +6,28 @@ data_points = 10000;
% Go on for 8 time constants
time_constant = L/R;
-step = time_constant*8/data_points;
+step = time_constant/data_points;
T=150e-6; % 150us
f = 1/T;
+w_c = 2*pi*f;
+A = 6;
-Vin = @(t) 6*cos(2*pi*f*t);
+Vin = @(t) A*cos(w_c*t);
current_initial=0;
-current_exact = @(t) --
-Vout_exact = @(t) --
+% e^m is the integratingn factor
+m = 0.5/0.0015;
+
+% Solution is made by multiplying by integrating factor and
+% then integrating both sides
+current_exact = @(t) 3/(m^2+w_c^2)*(2*m*cos(w_c*t) + 2*w_c*sin(w_c*t));
+Vout_exact = @(t) Vin(t) - current_exact(t)*R;
[time_array, Vout_array] = ralston(R, L, Vin, current_initial, step, data_points*step);
for j=1:data_points
- error_array(j) = Vout_exact(time_array(j)) - Vout_aray(j);
+ error_array(j) = Vout_exact(time_array(j)) - Vout_array(j);
end
-plot(log(time_array),log(error_array));
+loglog(time_array, error_array);