I am having trouble implementing the minF_conj_grad routine that is
meant to minimize the expression (Ax-b) where x,b are vectors and A is
a matrix. The program I wrote is as below.
I would really appreciate it if someone can help me with this.
Regards
Siddharth
PRO s
; THIS FINDS THE SOLUTION TO Ax=b WHERE THE MATRIX "A" AND VECTOR "b"
; ARE GIVEN
x_min = replicate(1.,2)
px = x_min
a = fltarr(2,2)
a[0,0] = 2.
a[0,1] = 1.
a[1,0] = 5.
a[1,1] = 7.
b = fltarr(2,1)
b[0,0] = 9.
b[1,0] = 45.
thematrix = a#px - b
print, 'a##x-b= ', thematrix
gradient = reform(transpose(thematrix)#a,2,1)
print, 'gradient outside: ', gradient
f = funky(px,gradient)
print, 'x = ', px
print, 'the function = ', f
minF_conj_grad, x_min, f_min, conv_factor, FUNC_NAME='funky',/
INITIALIZE
while (conv_factor GT 0) do begin
print, 'running more than once...'
minF_conj_grad, px, f_min, conv_factor, FUNC_NAME='funky'
PRINT, 'CURRENT ITERATION OF SOLUTION: ', px
endwhile
;PRINT, 'SOLUTION IS: ', x
END
function funky, px,gradient
c = fltarr(2,2)
c[0,0] = 2.
c[0,1] = 1.
c[1,0] = 5.
c[1,1] = 7.
d = fltarr(2,1)
d[0,0] = 9.
d[1,0] = 45.
thematrixwa = c#px - d
print, 'x inside funky:'
print, px
print, 'the matrixwa inside funky: ', thematrixwa
gradient= reform((transpose(thematrixwa))#c,2,1)
print, 'gradient inside funky:', gradient
print, 'the function inside funky: ',
(transpose(thematrixwa))#(thematrixwa)
f_min=(transpose(thematrixwa))#(thematrixwa)
return, f_min
end


|