On 12.04.2013 22:22, Herman Rubin wrote:
> On 2013-04-12, Axel Vogt <&
nor...@axelvogt.de> wrote:
>> On 12.04.2013 19:29, Herman Rubin wrote:
>>> On 2013-04-12, Axel Vogt <&
nor...@axelvogt.de> wrote:
>>>> On 12.04.2013 00:12, Herman Rubin wrote:
>>>>> Suppose one has a procedure P which takes a function or functions
>>>>> and produces a number or numbers. The numbers produced are NOT
>>>>> integrals. Now suppose one has a function with a parameter (I
>>>>> know that Maple does not have this, but does it as a function
>>>>> of two arguments) and I want to produce a graph of the values
>>>>> of P on the function as a function of the parameter. How to do
>>>>> this without rewriting everything?
...
> Here is the procedure which I constructed; it works.
> In practice, n will be 128 or 256.
>
> eff:=proc(f,n,start,F)
> local s1,s2,i,x,h;
> s2:=0;x:=start;
> for i from 1 to n do
> h:=f(x);
> x:= x+ 1/(n*f(x));
> s2:=s2+(1-f(x)/h);
> end do;
> s2:=s2/n;
> s1:=F(x);
> return s1,s2;
> end proc;
I would amend it to return a pair (and personally only return s2, since s1 = F(s2)).
Likewise I would use a subsequent proc to do modify the output.
An 'option hfloat' will speed up computations (the code can be improved a bit more).
Eff:=proc(f,n,start,F)
option hfloat; # to speed up numerics
local s1,s2,i,x,h;
s2:=0;x:=start;
for i from 1 to n do
h:=f(x);
x:= x+ 1/(n*f(x));
s2:=s2+(1-f(x)/h);
end do;
s2:=s2/n;
s1:=F(x);
return [s1,s2]; # return as pair
end proc;
# a small test
Eff(exp, 8, 2.1, 'x -> x^2');
[4.91205739100430, -0.0146458557860588]
Then I can plot (using only few data points by option 'numpoints')
nTst:=8; fTst:=ln; FTst:='x -> x';
plot( Eff(fTst, nTst, s, FTst), s=1 ..4, numpoints=5);