-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathminquad.f90
More file actions
108 lines (102 loc) · 2.52 KB
/
minquad.f90
File metadata and controls
108 lines (102 loc) · 2.52 KB
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
105
106
107
108
subroutine minquad ( x1, y1, x2, y2, x3, y3, xmin, ymin )
!*****************************************************************************80
!
!! MINQUAD finds a local minimum of F(X) = A * X * X + B * X + C.
!
! Discussion:
!
! MINQUAD is primarily intended as a utility routine.
! The square of the distance function between a point
! and a line segment has the form of F(X). Hence, we can seek
! the line on the second segment which minimizes the square of
! the distance to the other line segment.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 02 November 1998
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input/output, double precision X1, Y1, X2, Y2, X3, Y3, three sets of data
! of the form ( X, F(X) ). The three X values must be distinct.
! On output, the data has been sorted so that X1 < X2 < X3,
! and the Y values have been rearranged accordingly.
!
! Output, double precision XMIN, YMIN. XMIN is a point within the interval
! spanned by X1, X2 and X3, at which F takes its local minimum value YMIN.
!
implicit none
integer ierror
double precision x
double precision x1
double precision x2
double precision x3
double precision xleft
double precision xmin
double precision xrite
double precision y
double precision y1
double precision y2
double precision y3
double precision ymin
!
! Refuse to deal with coincident data.
!
if ( x1 == x2 .or. x2 == x3 .or. x3 == x1 ) then
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'MINQUAD - Fatal error!'
write ( *, '(a)' ) ' X values are equal.'
stop 1
end if
!
! Find the interval endpoints.
!
xleft = min ( x1, x2, x3 )
xrite = max ( x1, x2, x3 )
!
! Find the minimizer and its function value, over the three input points.
!
if ( y1 <= y2 .and. y1 <= y3 ) then
xmin = x1
ymin = y1
else if ( y2 <= y1 .and. y2 <= y3 ) then
xmin = x2
ymin = y2
else
xmin = x3
ymin = y3
end if
!
! Find the minimizer and its function value over the real line.
!
call parabola_ex ( x1, y1, x2, y2, x3, y3, x, y, ierror )
!
! If F is linear, then take the already computed min.
!
if ( ierror == 2 ) then
!
! If F has a maximum, then take the already computed min.
!
else if ( ymin < y ) then
!
! If the minimizer is to the left, take the already computed min.
!
else if ( x < xleft ) then
!
! If the minimizer is to the right, take the already computed min.
!
else if ( xrite < x ) then
else
xmin = x
ymin = y
end if
return
end