aboutsummaryrefslogtreecommitdiffstats
path: root/Part 1/ralston_script.m
blob: 91da2a9314915e41d08d3b598811521525e56a89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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)');