aboutsummaryrefslogtreecommitdiffstats
path: root/Part 1/ralston_script.m
diff options
context:
space:
mode:
Diffstat (limited to 'Part 1/ralston_script.m')
-rw-r--r--Part 1/ralston_script.m104
1 files changed, 104 insertions, 0 deletions
diff --git a/Part 1/ralston_script.m b/Part 1/ralston_script.m
new file mode 100644
index 0000000..91da2a9
--- /dev/null
+++ b/Part 1/ralston_script.m
@@ -0,0 +1,104 @@
+clear;
+ts = 0; % set initial value of x_0
+is = 0;
+h = 0.0001; % set step-size
+tf = 0.03; % stop here
+R = 0.5;
+L = 0.0015;
+
+vin = @(t) 3.5;
+func = @(t, iout) (vin(t) - iout*R) / L; % define func
+[t, iout ] = ralston(func, ts, tf, is, h);
+
+vout = vin(t) - iout * R;
+plot(t,vout);
+xlabel({'Time', '(seconds)'});
+ylabel({'V_{out}', '(volt)'});
+title('V_{out} versus time (original function)');
+%____________________________________________________________________
+h = 0.0001;
+tf = 0.03;
+figure;
+A = 3.5;
+tau = 0.000150;
+
+vin = @(t) A * exp(-t.^2/tau);
+func = @(t, iout) (vin(t) - iout*R) / L; % define func
+[t, iout ] = ralston(func, ts, tf, is, h);
+
+vout = vin(t) - iout * R;
+plot(t,vout);
+xlabel({'Time', '(seconds)'});
+ylabel({'V_{out}', '(volt)'});
+title('V_{out} versus time (exponential square funtion)');
+%____________________________________________________________________
+h = 0.0001;
+tf = 0.03;
+figure;
+A = 3.5;
+tau = 0.000150;
+
+vin = @(t) A * exp(-t/tau);
+func = @(t, iout) (vin(t) - iout*R) / L; % define func
+[t, iout ] = ralston(func, ts, tf, is, h);
+
+vout = vin(t) - iout * R;
+plot(t,vout);
+xlabel({'Time', '(seconds)'});
+ylabel({'V_{out}', '(volt)'});
+title('V_{out} versus time (exponential function)');
+
+%____________________________________________________________________
+h = 0.0001;
+tf = 0.03;
+figure;
+A = 4;
+T = 0.0015;
+
+vin = @(t) A * sin(2*pi*t/T);
+func = @(t, iout) (vin(t) - iout*R) / L; % define func
+[t, iout ] = ralston(func, ts, tf, is, h);
+
+vout = vin(t) - iout * R;
+plot(t,vout);
+xlabel({'Time', '(seconds)'});
+ylabel({'V_{out}', '(volt)'});
+title('V_{out} versus time (sine function)');
+%____________________________________________________________________
+h = 0.0001;
+tf = 0.03;
+figure;
+A = 4;
+T = 0.0015;
+
+vin = @(t) A * square(2*pi*t/T);
+func = @(t, iout) (vin(t) - iout*R) / L; % define func
+[t, iout ] = ralston(func, ts, tf, is, h);
+
+vout = vin(t) - iout * R;
+plot(t,vout);
+xlabel({'Time', '(seconds)'});
+ylabel({'V_{out}', '(volt)'});
+title('V_{out} versus time (square function)');
+%____________________________________________________________________
+h = 0.0001;
+tf = 0.03;
+figure;
+A = 4;
+T = 0.0015;
+
+vin = @(t) A * sawtooth(2*pi*t/T);
+func = @(t, iout) (vin(t) - iout*R) / L; % define func
+[t, iout ] = ralston(func, ts, tf, is, h);
+
+vout = vin(t) - iout * R;
+plot(t,vout);
+xlabel({'Time', '(seconds)'});
+ylabel({'V_{out}', '(volt)'});
+title('V_{out} versus time (sawtooth function)');
+
+
+
+
+
+