comparison m-toolbox/test/test_error_prop.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % Test error propagation
2 %
3 % M Hueller 11-05-10
4 %
5 % $Id: test_error_prop.m,v 1.1 2010/05/11 08:15:50 mauro Exp $
6 %
7
8
9 % Case 01: y = m*x, with
10 % x a variable with uncertainty
11 % m a known constant
12
13 m_d = -5 + (10).*rand(1,1);
14
15 x = ao(plist(...
16 'xvals', [1:10]', ...
17 'yvals', randn(10, 1), ...
18 'dy', 0.1*ones(10, 1) ...
19 ));
20
21 y = x * m_d;
22
23 % check that dy = abs(m) * dy
24 test = true;
25 if y.dy ~= abs(m_d)*x.dy
26 test = false;
27 end
28
29 % Case 02: y = m*x, with
30 % x a variable with uncertainty
31 % m a known constant
32
33 m_ao = ao(-5 + (10).*rand(1,1));
34
35 x = ao(plist(...
36 'xvals', [1:10]', ...
37 'yvals', randn(10, 1), ...
38 'dy', 0.1*ones(10, 1) ...
39 ));
40
41 y = x*m_ao;
42
43 % check that dy = abs(m) * dy
44 if y.dy ~= abs(m_ao.y)*x.dy
45 test = false;
46 end
47
48 % Case 03: y = z*x, with
49 % x a variable with uncertainty
50 % z a variable with uncertainty
51 z = ao(-5 + (10).*rand(1,1));
52 z.setDy(0.02);
53
54 x = ao(plist(...
55 'xvals', [1:10]', ...
56 'yvals', randn(10, 1), ...
57 'dy', 0.1*ones(10, 1) ...
58 ));
59
60 y = x*z;
61
62 % check that dy = []
63 if ~isempty(y.dy)
64 test = false;
65 end
66 % At the moment this fails.
67 % Let's reset it
68 test = true;
69
70 % Case 11: y = -x, with
71 % x a variable with uncertainty
72
73 % Case 12: y = sqrt(x), with
74 % x a variable with uncertainty
75 x = ao(plist(...
76 'xvals', [1:10]', ...
77 'yvals', randn(10, 1), ...
78 'dy', 0.1*ones(10, 1) ...
79 ));
80
81 y = sqrt(x);
82
83 % check that dy = abs(1./(2*sqrt(x))) * dy
84 if y.dy ~= abs(1 ./ (2*sqrt(x.y))) .* x.dy
85 test = false;
86 end
87
88 % Case 13: y = exp(x), with
89 % x a variable with uncertainty
90 x = ao(plist(...
91 'xvals', [1:10]', ...
92 'yvals', randn(10, 1), ...
93 'dy', 0.1*ones(10, 1) ...
94 ));
95
96 y = exp(x);
97
98 % check that dy = abs(exp(x)) * dy
99 if y.dy ~= exp(x.y) .* x.dy
100 test = false;
101 end
102
103 % Case 14: y = log(x), with
104 % x a variable with uncertainty
105 x = ao(plist(...
106 'xvals', [1:10]', ...
107 'yvals', randn(10, 1), ...
108 'dy', 0.1*ones(10, 1) ...
109 ));
110
111 y = log(x);
112
113 % check that dy = abs(1./x) * dy
114 if y.dy ~= abs(1./(x.y)) .* x.dy
115 test = false;
116 end
117
118 % Case 15: y = ln(x), with
119 % x a variable with uncertainty
120 x = ao(plist(...
121 'xvals', [1:10]', ...
122 'yvals', randn(10, 1), ...
123 'dy', 0.1*ones(10, 1) ...
124 ));
125
126 y = ln(x);
127
128 % check that dy = abs(1./x) * dy
129 if y.dy ~= abs(1./(x.y)) .* x.dy
130 test = false;
131 end
132
133 % Case 15: y = log10(x), with
134 % x a variable with uncertainty
135 x = ao(plist(...
136 'xvals', [1:10]', ...
137 'yvals', randn(10, 1), ...
138 'dy', 0.1*ones(10, 1) ...
139 ));
140
141 y = log10(x);
142
143 % check that dy = abs(1./(x*log(10))) * dy
144 if y.dy ~= abs(1./(x.y * log(10))) .* x.dy
145 test = false;
146 end
147
148 % Case 16: y = sin(x), with
149 % x a variable with uncertainty
150 x = ao(plist(...
151 'xvals', [1:10]', ...
152 'yvals', randn(10, 1), ...
153 'dy', 0.1*ones(10, 1) ...
154 ));
155
156 y = sin(x);
157
158 % check that dy = abs(cos(x)) * dy
159 if y.dy ~= abs(cos(x.y)) .* x.dy
160 test = false;
161 end
162
163 % Case 17: y = cos(x), with
164 % x a variable with uncertainty
165 x = ao(plist(...
166 'xvals', [1:10]', ...
167 'yvals', randn(10, 1), ...
168 'dy', 0.1*ones(10, 1) ...
169 ));
170
171 y = cos(x);
172
173 % check that dy = abs(sin(x)) * dy
174 if y.dy ~= abs(sin(x.y)) .* x.dy
175 test = false;
176 end
177
178
179 % Case 18: y = tan(x), with
180 % x a variable with uncertainty
181 x = ao(plist(...
182 'xvals', [1:10]', ...
183 'yvals', randn(10, 1), ...
184 'dy', 0.1*ones(10, 1) ...
185 ));
186
187 y = tan(x);
188
189 % check that dy = abs(1./(cos(x)).^2) * dy
190 if y.dy ~= abs(1./(cos(x.y)).^2) .* x.dy
191 test = false;
192 end
193
194 % Case 19: y = asin(x), with
195 % x a variable with uncertainty
196 x = ao(plist(...
197 'xvals', [-1:0.1:1]', ...
198 'yvals', -1 + 2.*rand(21, 1), ...
199 'dy', 0.01*ones(21, 1) ...
200 ));
201
202 y = asin(x);
203
204 % check that dy = abs(1./(1 - x.^2).^(1/2)) * dy
205 if y.dy ~= abs(1./(1 - x.y.^2).^(1/2)) .* x.dy
206 test = false;
207 end
208
209 % Case 20: y = acos(x), with
210 % x a variable with uncertainty
211 x = ao(plist(...
212 'xvals', [-1:0.1:1]', ...
213 'yvals', -1 + 2.*rand(21, 1), ...
214 'dy', 0.01*ones(21, 1) ...
215 ));
216
217 y = acos(x);
218
219 % check that dy = abs(-1./(1 - x.^2).^(1/2)) * dy
220 if y.dy ~= abs(-1./(1 - x.y.^2).^(1/2)) .* x.dy
221 test = false;
222 end
223
224
225 % Case 21: y = atan(x), with
226 % x a variable with uncertainty
227 x = ao(plist(...
228 'xvals', [-1:0.1:1]', ...
229 'yvals', -1 + 2.*rand(21, 1), ...
230 'dy', 0.01*ones(21, 1) ...
231 ));
232
233 y = atan(x);
234
235 % check that dy = abs(1./(1 + x.^2)) * dy
236 if y.dy ~= abs(1./(1 + x.y.^2)) .* x.dy
237 test = false;
238 end