Newcomer to IDL [message #94337] |
Thu, 13 April 2017 17:19  |
asmagal89
Messages: 2 Registered: April 2017
|
Junior Member |
|
|
Hello!
I would like to know why the following procedure, taken ipsis verbis from the Harris example does not compile without errors:
QUOTE
PRO agfunct, X, A, F, pder
bx=EXP(A[1]*X)
F=A[0]*bx+A[2]
;If the procedure is called with four parameters, calculate the
;partial derivatives.
IF N_PARAMS() GE 4 THEN $
pder=[[bx], [A[0] * X * bx], [replicate(1.0, N_ELEMENTS(X))]]
END
;Compute the fit to the function we have just defined.
;First, define the independent and dependent variables:
X = FLOAT(INDGEN(10))
Y = [12.0, 11.0, 10.2, 9.4, 8.7, 8.1, 7.5, 6.9, 6.5, 6.1]
;Define a vector of weights.
weights = 1.0/Y
;Provide an initial guess of the function’s parameters.
A = [10.0,-0.1,2.0]
;Compute the parameters.
yfit = CURVEFIT(X, Y, weights, A, SIGMA, FUNCTION_NAME='agfunct')
;Print the parameters returned in A.
PRINT, 'Function parameters: ', A
END
UNQUOTE
Thanks in advance,
Antonio.
|
|
|
Re: Newcomer to IDL [message #94338 is a reply to message #94337] |
Thu, 13 April 2017 19:16   |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
Looking at the example code in the CURVEFIT documentation
http://www.harrisgeospatial.com/docs/CURVEFIT.html
there are actually two procedures. The first one GFUNCT ends at the first END statement after seven lines. The next non-comment
X = FLOAT(INDGEN(10))
begins the new procedure. In the documentation, it is written as a main level procedure, i.e. commands that can be typed in at the IDL prompt. You could make it into a compileable procedure by adding a PRO or FUNCTION as the first line. For example, add
PRO MAIN
before the X = FLOAT(INDGEN(10)) line, and add an END statement at the end. It appears that you added the END statement but did not include the PRO statement. --Wayne
P.S. When asking questions about an error message, it is useful to say what the displayed error message is.
On Thursday, April 13, 2017 at 8:19:52 PM UTC-4, asma...@gmail.com wrote:
> Hello!
>
> I would like to know why the following procedure, taken ipsis verbis from the Harris example does not compile without errors:
>
> QUOTE
>
> PRO gfunct, X, A, F, pder
> bx=EXP(A[1]*X)
> F=A[0]*bx+A[2]
> ;If the procedure is called with four parameters, calculate the
> ;partial derivatives.
> IF N_PARAMS() GE 4 THEN $
> pder=[[bx], [A[0] * X * bx], [replicate(1.0, N_ELEMENTS(X))]]
> END
> ;Compute the fit to the function we have just defined.
> ;First, define the independent and dependent variables:
> X = FLOAT(INDGEN(10))
> Y = [12.0, 11.0, 10.2, 9.4, 8.7, 8.1, 7.5, 6.9, 6.5, 6.1]
> ;Define a vector of weights.
> weights = 1.0/Y
> ;Provide an initial guess of the function’s parameters.
> A = [10.0,-0.1,2.0]
> ;Compute the parameters.
> yfit = CURVEFIT(X, Y, weights, A, SIGMA, FUNCTION_NAME='agfunct')
> ;Print the parameters returned in A.
> PRINT, 'Function parameters: ', A
> END
>
> UNQUOTE
>
> Thanks in advance,
> Antonio.
|
|
|
Re: Newcomer to IDL [message #94339 is a reply to message #94337] |
Fri, 14 April 2017 02:00   |
lecacheux.alain
Messages: 325 Registered: January 2008
|
Senior Member |
|
|
Le vendredi 14 avril 2017 02:19:52 UTC+2, asma...@gmail.com a écrit :
> Hello!
>
> I would like to know why the following procedure, taken ipsis verbis from the Harris example does not compile without errors:
>
> QUOTE
>
> PRO agfunct, X, A, F, pder
> bx=EXP(A[1]*X)
> F=A[0]*bx+A[2]
> ;If the procedure is called with four parameters, calculate the
> ;partial derivatives.
> IF N_PARAMS() GE 4 THEN $
> pder=[[bx], [A[0] * X * bx], [replicate(1.0, N_ELEMENTS(X))]]
> END
> ;Compute the fit to the function we have just defined.
> ;First, define the independent and dependent variables:
> X = FLOAT(INDGEN(10))
> Y = [12.0, 11.0, 10.2, 9.4, 8.7, 8.1, 7.5, 6.9, 6.5, 6.1]
> ;Define a vector of weights.
> weights = 1.0/Y
> ;Provide an initial guess of the function’s parameters.
> A = [10.0,-0.1,2.0]
> ;Compute the parameters.
> yfit = CURVEFIT(X, Y, weights, A, SIGMA, FUNCTION_NAME='agfunct')
> ;Print the parameters returned in A.
> PRINT, 'Function parameters: ', A
> END
>
> UNQUOTE
>
> Thanks in advance,
> Antonio.
You likely made "ipsis verbis" some cute&paste from Harris documentation.
Unfirtunately, there are some non-ascii characters at the beginning of every uncommented lines (starting with bf=..., F=... and IF...) in the Agfunct subroutine, which are not accepted by the compiler.
Please remove them !
alx.
|
|
|
|