aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAufar Laksana <apl115@ic.ac.uk>2017-03-12 14:39:19 +0000
committerGitHub <noreply@github.com>2017-03-12 14:39:19 +0000
commitb665a01b921753dfd3cfc4c26711685c93848145 (patch)
treecb005a135648b05a0754c8d4039d7943426dea68
parentb9dbb11c8acdbe20c56f5f22342c62d050bbe146 (diff)
downloadNumericalAnalysis-b665a01b921753dfd3cfc4c26711685c93848145.tar.gz
NumericalAnalysis-b665a01b921753dfd3cfc4c26711685c93848145.zip
Added different input functions
-rw-r--r--Part 2/RLC_script.m29
1 files changed, 21 insertions, 8 deletions
diff --git a/Part 2/RLC_script.m b/Part 2/RLC_script.m
index 881d941..f17f77e 100644
--- a/Part 2/RLC_script.m
+++ b/Part 2/RLC_script.m
@@ -1,4 +1,4 @@
-function RLC_script (tf)
+function RLC_Script (tf)
%initailise the circuits
R = 250;
@@ -15,31 +15,44 @@ t = zeros(1, N);
Vout = zeros(1, N);
%input voltage
-% step function of 5 volt
-Vin = @(t)5*heaviside(t);
-%Vin = @(t)
+%%step function of 5 volt
+%Vin = @(t)5*heaviside(t);
+
+%%Impulse with Exponential Decay
+%Tau = 3*(10^-6);
+%Vin = @(t)5*exp(-(t^2)/Tau);
+
+%%Square Wave (5Hz, 100Hz, 500Hz)
+%Vin = @(t)5*square(2*pi*5*t);
+
+
+%%Sine Wave (5Hz, 100Hz, 500Hz)
+Vin = @(t)5*sin(2*pi*5*t);
%the coupled equation
func1 = @(t, qc, qc_dash)qc_dash;
func2 = @(t, qc, qc_dash)(Vin(t) - qc/C - R*qc_dash)/L;
+
%the initial condition
qc_dash(1) = 0;
qc(1) = 500*(10.^-9);
t(1) = 0;
-%Rouge Kutta
+%Runge Kutta
for i = 1 : N - 1
t(i + 1) = t(i) + h;
[qc(i + 1), qc_dash(i + 1)] = RK4second(t(i), qc(i), qc_dash(i), h, func1, func2);
Vout(i) = R*qc_dash(i);
end
-%plot
+%Plot the input function
+plot(t, Vin(t));
-plot(Vout);
+%Plot the output of the system
+figure
+plot(t, Vout);
xlabel('Time');
ylabel('Amplitude');
end
-