diff options
Diffstat (limited to 'Part 1/error_script_heun.m')
-rw-r--r-- | Part 1/error_script_heun.m | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Part 1/error_script_heun.m b/Part 1/error_script_heun.m new file mode 100644 index 0000000..bb511bd --- /dev/null +++ b/Part 1/error_script_heun.m @@ -0,0 +1,30 @@ +function error_script_heun (tf)
+
+ts = 0; % set initial value of x_0
+is = 0;
+h = 0.0001; % set step-size
+R = 0.5;
+L = 0.0015;
+
+
+A = 6;
+T = 0.00015;
+
+vin = @(t) A * cos(2*pi*t/T);
+func = @(t, iout) (vin(t) - iout*R) / L; % define func
+[t, iout ] = heun(func, ts, is, h);
+
+%numerical solution
+vout = vin(t) - iout * R;
+
+%obtaining the exact solution with favorite method
+exact= @(t) 0.07553*cos( 41883.7*(t) ) + 0.94901*sin( 41883.7*(t) ); % works for arrays
+
+%error as a function of t
+error=exact-vout;
+
+figure(1);
+plot(t,error); %for heun
+loglog(error);
+
+end
\ No newline at end of file |