summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasil Zlatanov <v@skozl.com>2017-03-08 16:57:52 +0000
committerVasil Zlatanov <v@skozl.com>2017-03-08 16:57:52 +0000
commit213cb6e2aa88360c2847555f062fbe54b0b274db (patch)
tree60f281dfeb30c9fcc746efc57adfb66286ef6df8
parent2adb0e8d1735bbd4dc68e1d39d3e2682aba5400e (diff)
downloade2-matlab-master.tar.gz
e2-matlab-master.tar.bz2
e2-matlab-master.zip
clean up error_scriptHEADmaster
-rw-r--r--coursework17/error_script.m91
1 files changed, 41 insertions, 50 deletions
diff --git a/coursework17/error_script.m b/coursework17/error_script.m
index f17f234..83cf428 100644
--- a/coursework17/error_script.m
+++ b/coursework17/error_script.m
@@ -1,50 +1,41 @@
-% This script will carry out error analysis
-R = 0.5; % 0.5Ohm
-L = 0.0015; % 1.5mH
-
-data_points = 100000;
-h_divisions = 1000;
-
-% Go on for a time constant
-time_constant = L/R;
-step = time_constant/data_points;
-
-T=150e-6; % 150us
-f = 1/T;
-w_c = 2*pi*f;
-A = 6;
-
-Vin = @(t) A*cos(w_c*t);
-current_initial=0;
-
-% e^m is the integratingn factor
-% m = 0.5/0.0015;
-
-% Solution is made by multiplying by integrating factor and
-% then integrating both sides
-
-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;
-
-for k=1:h_divisions
-
- [time_array, Vout_array] = ralston(R, L, Vin, current_initial, step*k, data_points*step);
-
- 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(max_t, max_array);
+% This script will carry out error analysis
+R = 0.5; % 0.5Ohm
+L = 0.0015; % 1.5mH
+
+data_points = 100000;
+h_divisions = 1000;
+
+% Go on for a time constant
+time_constant = L/R;
+step = time_constant/data_points;
+
+T=150e-6; % 150us
+f = 1/T;
+w = 2*pi*f;
+A = 6;
+
+Vin = @(t) A*cos(w*t);
+current_initial=0;
+
+
+A = 6*R/(R^2 + (w*L)^2);
+B = 6*w*L/(R^2 + (w*L)^2);
+
+current_exact = @(t) A*cos(w*t) + B*sin(w*t) - A*exp((-R/L)*t);
+Vout_exact = @(t) Vin(t) - current_exact(t)*R;
+
+for k=1:h_divisions
+
+ [time_array, Vout_array] = ralston(R, L, Vin, current_initial, step*k, data_points*step);
+
+ for j=1:data_points/k
+ error_array(j) = Vout_exact(time_array(j)) - Vout_array(j);
+ end
+ max_array(k) = max(error_array);
+ max_t(k) = k*step;
+end
+
+loglog(max_t, max_array);
+title('Order of error')
+xlabel('Time step size')
+ylabel('Maximum error')