05-15-2008 07:53 AM
05-15-2008 11:19 AM
05-15-2008 11:48 AM
05-15-2008 12:04 PM
05-16-2008 02:44 AM
Call
ApprAnsatzOff ' Deactivates all function termsApprAnsatzFct
(1) = "Yes" ' Activates function term constantApprAnsatzFct
(2) = "Yes" ' Activates function term xApprAnsatzFct
(3) = "Yes" ' Activates function term x^2ApprAnsatzFct
(4) = "Yes" ' Activates function term x^3Call
ChnApprXYCalc("[1]/Time","[1]/Speed","/ApproximatedX","/ApproximatedY","Partition complete area",100,1) '... XW,Y,E,E,XChnStyle,XNo,XDivCall
ChnCopy("[1]/Time", "x")Call
GlobalDim("a0") : a0 = ApprAnsatzCoef(1)Call
GlobalDim("a1") : a1 = ApprAnsatzCoef(2)Call
GlobalDim("a2") : a2 = ApprAnsatzCoef(3)Call
GlobalDim("a3") : a3 = ApprAnsatzCoef(4)Call
ChnCalculate("Ch(""y"") = a0 + a1*Ch(""x"") + a2*Ch(""x"")^2 + a3*Ch(""x"")^3")05-20-2008 09:09 PM
Here is the subroutine that I came up with. It is a generic routine that determines the order of the polynomial based on the number of coefficients sent to the routine. "x" is the channel name with the x values, and "yf" is the result of evaluating the polynomial. The routine works correctly, but it is very slow. Since this sub is called hundreds of times for each data set containing 500+ points that needs evaluating, I would appreciate any assistance in making it faster. I tried to do the inner loop with Ch() notation, but I couldn't get the correct answer out.
Thanks in advance for the help.
Wayne
sub PolyVal (c,x,yf)
'this sub will evaluate the polynomial with coeficients c at all values of x the result is in yf
Dim a,b,NumCoeff,length
NumCoeff = ubound(c)
length = ChnPropValGet(x,"Length")
For a = 1 to length
For b = 0 to NumCoeff
Call FormulaCalc("CHD(" & a & ",'" & yf & "') := " & CStr(c(b)) & " * CHD(" & a & ",'" & x & "')^" & CStr(b) & " + CHD(" & a & ",'" & yf & "')")
Next 'b
Next 'a
end sub
05-21-2008 11:16 AM
Hi Wayne,
This is a really good suggestion. We should make this easier than it is today in DIAdem 10.x or will be in DIAdem 11. You don't need to call ChD() in the FormulaCalc() function-- it already implicitly loops over all the x values if you use the Ch() syntax. I also prefer to reference the channels with DIAdem temporary variables (L1, L2), since I think that makes the formula expression much easier to read and debug. Finally, you should build up the formula expression in the loop over the coefficients and then execute the resulting expression exactly once. This should be blazing fast.
x = "[1]/Time"
yf = "[1]/Fit of Speed"
c = Array(8.47495366905276, 2.28126534943276, 0.0230625271557868, -0.0021154305278767, 1.69053818072781E-05)
Call PolyVal(c,x,yf)
sub PolyVal(c,x,yf)
Dim b
IF NOT IsArray(c) THEN Exit Sub
IF NOT UBound(c) >= 0 THEN Exit Sub
L1 = CNo(x)
L2 = CNo(yf)
IF L1 = 0 OR L2 = 0 THEN Exit Sub
FormulaTxt = "Ch(L2):= " & c(b)
For b = 1 to ubound(c)
FormulaTxt = FormulaTxt & " + " & c(b) & "*Ch(L1)^" & b
Next 'b
Call FormulaCalc(FormulaTxt)
end sub
Brad Turpin
DIAdem Product Support Engineer
National Instruments
05-21-2008 12:38 PM