summaryrefslogtreecommitdiff
path: root/coursework17
diff options
context:
space:
mode:
authorVasil Zlatanov <v@skozl.com>2017-03-05 19:13:21 +0000
committerVasil Zlatanov <v@skozl.com>2017-03-05 19:13:21 +0000
commit0c4597af1ff1c30f4f7df8735fb8e38e1e6e6b86 (patch)
treec11950b228168d1b8eaef07024fcf0efdfe908b0 /coursework17
parenta9a72731a9f563344f27cd6a07eed431ec673c51 (diff)
downloade2-matlab-0c4597af1ff1c30f4f7df8735fb8e38e1e6e6b86.tar.gz
e2-matlab-0c4597af1ff1c30f4f7df8735fb8e38e1e6e6b86.tar.bz2
e2-matlab-0c4597af1ff1c30f4f7df8735fb8e38e1e6e6b86.zip
fix exact solution mistake and plot h vs error
Diffstat (limited to 'coursework17')
-rw-r--r--coursework17/error_script.m38
1 files changed, 24 insertions, 14 deletions
diff --git a/coursework17/error_script.m b/coursework17/error_script.m
index 5a37fe8..f17f234 100644
--- a/coursework17/error_script.m
+++ b/coursework17/error_script.m
@@ -2,7 +2,8 @@
R = 0.5; % 0.5Ohm
L = 0.0015; % 1.5mH
-data_points = 10000;
+data_points = 100000;
+h_divisions = 1000;
% Go on for a time constant
time_constant = L/R;
@@ -17,24 +18,33 @@ Vin = @(t) A*cos(w_c*t);
current_initial=0;
% e^m is the integratingn factor
-m = 0.5/0.0015;
+% 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));
+
+A = 6*R/(R^2 + (w_c*L)^2);
+B = 6*w_c*L/(R^2 + (w_c*L)^2);
+
+current_exact = @(t) A*cos(w_c*t) + B*sin(w_c*t) - A*exp((-R/L)*t);
+%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 k=1:h_divisions
-for j=1:data_points
- error_array(j) = Vout_exact(time_array(j)) - Vout_array(j);
- % Vout_plot(j) = Vout_exact(time_array(j));
-end
+ [time_array, Vout_array] = ralston(R, L, Vin, current_initial, step*k, data_points*step);
-% plot(time_array, Vout_array);
-% figure;
-% plot(time_array, Vout_plot);
-%
-% max(Vout_plot-Vout_array)
+ for j=1:data_points/k
+ error_array(j) = Vout_exact(time_array(j)) - Vout_array(j);
+ % Vout_plot(j) = Vout_exact(time_array(j));
+ end
+
+ % plot(time_array, Vout_array);
+ % figure;
+ % plot(time_array, Vout_plot);
+ %
+ max_array(k) = max(error_array);
+ max_t(k) = k*step;
+end
-loglog(time_array, error_array);
+loglog(max_t, max_array);