ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/cal/root.cal
Revision: 1.4
Committed: Mon Jun 10 13:56:52 2019 UTC (4 years, 11 months ago) by greg
Branch: MAIN
CVS Tags: rad5R4, rad5R3, HEAD
Changes since 1.3: +1 -2 lines
Log Message:
Added max() and min() as .cal library functions

File Contents

# User Rev Content
1 greg 1.4 { RCSid $Id: root.cal,v 1.3 2011/10/11 15:40:54 greg Exp $ }
2 greg 1.1 {
3     root.cal - calculate zeroes of functions using Newton's method.
4    
5     2/3/88
6     }
7    
8 greg 1.3 FTINY : 1e-9;
9 greg 1.1
10     root(f, x0) = root2(f, x0, x0-f(x0)/lim(f1(f,x0)), nit);
11    
12     root2(f, x0, x1, i) = if(i,
13     if(err-abs(x1-x0),
14     x1,
15     root2(f,x1,x1-f(x1)/lim(f1(f,x1)),i-1)),
16     0);
17    
18     abs(x) = if(x, x, -x);
19     lim(x) = if(x, max(x,err), -max(-x,err));
20    
21 greg 1.2 f1(f,x) = (f(x+FTINY)-f(x-FTINY))/(2*FTINY); { numerical derivative }
22 greg 1.1
23 greg 1.3 err = 1e-5;
24 greg 1.1 nit = 100;