aboutsummaryrefslogtreecommitdiffstats
path: root/Part 1/Huen_script.m
diff options
context:
space:
mode:
Diffstat (limited to 'Part 1/Huen_script.m')
-rw-r--r--Part 1/Huen_script.m41
1 files changed, 41 insertions, 0 deletions
diff --git a/Part 1/Huen_script.m b/Part 1/Huen_script.m
new file mode 100644
index 0000000..f9f4561
--- /dev/null
+++ b/Part 1/Huen_script.m
@@ -0,0 +1,41 @@
+function Huen_script (tf) %tf is the end time
+
+%initailise the circuits
+R = 0.5;
+L = 1.5*10^(-3);
+h = 0.00001; %step size
+
+
+%initailise the container
+
+N = round(tf/h); %number of iterations
+t = zeros(1, N);
+Vout = zeros(1, N);
+current = zeros(1,N);
+
+%input voltage
+% step function of 5 volt
+%Vin = @(t)5*heaviside(t);
+Vin = @(t)4*sin(2*pi*6000*t);
+
+%the initial condition
+t(1) = 0;
+current(1) = 0;
+
+
+%the equation
+func = @(t,current) (Vin(t)-R*(current))/L; %Function input for difference method
+
+
+%Huen
+for j = 1 : N-1
+ [t(j + 1),current(j + 1)] = heun(func, t(j), current(j), h);
+ Vout(j + 1) = Vin(t(j)) - R*current(j); %Create Vout array from Iout, R and Vin
+end
+
+%plot
+
+plot(Vout);
+xlabel('T/s');
+ylabel('Vout/V');
+end \ No newline at end of file