Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.maple > #218 > unrolled thread

Plot problem with function

Started by"I.N. Galidakis" <morpheus@olympus.mons>
First post2011-07-28 22:09 +0300
Last post2011-07-28 14:31 -0700
Articles 4 — 2 participants

Back to article view | Back to comp.soft-sys.math.maple


Contents

  Plot problem with function "I.N. Galidakis" <morpheus@olympus.mons> - 2011-07-28 22:09 +0300
    Re: Plot problem with function Joe Riel <joer@san.rr.com> - 2011-07-28 12:18 -0700
      Re: Plot problem with function "I.N. Galidakis" <morpheus@olympus.mons> - 2011-07-29 00:11 +0300
        Re: Plot problem with function Joe Riel <joer@san.rr.com> - 2011-07-28 14:31 -0700

#218 — Plot problem with function

From"I.N. Galidakis" <morpheus@olympus.mons>
Date2011-07-28 22:09 +0300
SubjectPlot problem with function
Message-ID<1311880181.170189@athprx04>
I am having some problems with Maple 9 when plotting a certain function. The 
function is:

> HW:=proc()
> local y,n,c,s,p,sol,i,aprx,dy,dist,r,oldr,newr,fun,dfun,eps;
> if nargs<2 then ERROR("At least two arguments required.") fi;
> n:= args[-1];y:=args[-2];c:= [args[1..-3]];
> if y=0 then 0 else
>  dist:=infinity;
>  eps:=1e-32;
>  fun:= 1;
>  for i from 1 to nargs-2 do fun:= exp(c[i]*fun) od;
>  fun:= z*fun-y;
>  dfun:=diff(fun,z);
>  s:=series(fun,z,n);
>  p:=convert(s,polynom);
>  sol:={fsolve(p=0,z,complex)}; #complex?
>  for i from 1 to nops(sol) do
>   aprx:=evalf(subs(z=op(i,sol),fun));
>   dy:=evalf(abs(aprx));
>   if dy<=dist then r:=op(i,sol);dist:=dy;fi;
>  od;
> #start Newton with approximate zero found.
>  oldr:=r;
>  newr:=r-evalf(subs(z=r,fun)/subs(z=r,dfun));
>  for i from 1 to 1000 while (abs((oldr-newr)/oldr)>eps) do
>   oldr:=newr;
>   newr:=newr-evalf(subs(z=newr,fun)/subs(z=newr,dfun));
>  od;
> newr;
> fi;
> end:

When I try to plot it (in this case the arguments make it equivalent to arcsin) 
I get:

> with(plots):
> plot(HW(log(sin(z)/z),y,10),y=-1..1);
Error, (in fsolve) y is in the equation, and is not solved for

while if I do a:

> N:=50;x1:=-1;x2:=1;
> x:=n->x1+abs(x2-x1)/N*n;
> L:=[seq([x(n),HW(log(sin(z)/z),x(n),10)],n=0..N)]:
> plot(L,scaling=constrained);

It works (shows the graph of arcsin).

Individual values seem to be calculated correctly. For example:

> HW(log(sin(z)/z),0.245,10);
.247519692533815916885429116210

Does anyone know why the plot command doesn't work with this function?

Many thanks,
--
I. 

[toc] | [next] | [standalone]


#219

FromJoe Riel <joer@san.rr.com>
Date2011-07-28 12:18 -0700
Message-ID<87mxfyfc31.fsf@san.rr.com>
In reply to#218
"I.N. Galidakis" <morpheus@olympus.mons> writes:

> I am having some problems with Maple 9 when plotting a certain
> function. The function is:
>
>> HW:=proc()
>> local y,n,c,s,p,sol,i,aprx,dy,dist,r,oldr,newr,fun,dfun,eps;
>> if nargs<2 then ERROR("At least two arguments required.") fi;
>> n:= args[-1];y:=args[-2];c:= [args[1..-3]];
>> if y=0 then 0 else
>>  dist:=infinity;
>>  eps:=1e-32;
>>  fun:= 1;
>>  for i from 1 to nargs-2 do fun:= exp(c[i]*fun) od;
>>  fun:= z*fun-y;
>>  dfun:=diff(fun,z);
>>  s:=series(fun,z,n);
>>  p:=convert(s,polynom);
>>  sol:={fsolve(p=0,z,complex)}; #complex?
>>  for i from 1 to nops(sol) do
>>   aprx:=evalf(subs(z=op(i,sol),fun));
>>   dy:=evalf(abs(aprx));
>>   if dy<=dist then r:=op(i,sol);dist:=dy;fi;
>>  od;
>> #start Newton with approximate zero found.
>>  oldr:=r;
>>  newr:=r-evalf(subs(z=r,fun)/subs(z=r,dfun));
>>  for i from 1 to 1000 while (abs((oldr-newr)/oldr)>eps) do
>>   oldr:=newr;
>>   newr:=newr-evalf(subs(z=newr,fun)/subs(z=newr,dfun));
>>  od;
>> newr;
>> fi;
>> end:
>
> When I try to plot it (in this case the arguments make it equivalent
> to arcsin) I get:
>
>> with(plots):
>> plot(HW(log(sin(z)/z),y,10),y=-1..1);
> Error, (in fsolve) y is in the equation, and is not solved for
>
> while if I do a:
>
>> N:=50;x1:=-1;x2:=1;
>> x:=n->x1+abs(x2-x1)/N*n;
>> L:=[seq([x(n),HW(log(sin(z)/z),x(n),10)],n=0..N)]:
>> plot(L,scaling=constrained);
>
> It works (shows the graph of arcsin).
>
> Individual values seem to be calculated correctly. For example:
>
>> HW(log(sin(z)/z),0.245,10);
> .247519692533815916885429116210
>
> Does anyone know why the plot command doesn't work with this function?

The cause is premature evaluation.  The plot procedures (as most Maple
procedures) first evaluates its arguments.   But

 HW(log(sin(z)/z),y,10);

raises the error because y is not numeric.  An easy solution is
to delay the evaluation of HW.  You can do that via

  plot('HW'(log(sin(z)/z),y,10),y=-1..1);

-- 
Joe Riel

[toc] | [prev] | [next] | [standalone]


#220

From"I.N. Galidakis" <morpheus@olympus.mons>
Date2011-07-29 00:11 +0300
Message-ID<1311887488.649668@athprx03>
In reply to#219
Joe Riel wrote:
> "I.N. Galidakis" <morpheus@olympus.mons> writes:
>
>> I am having some problems with Maple 9 when plotting a certain
>> function. The function is:
>>
>>> HW:=proc()
>>> local y,n,c,s,p,sol,i,aprx,dy,dist,r,oldr,newr,fun,dfun,eps;
>>> if nargs<2 then ERROR("At least two arguments required.") fi;
>>> n:= args[-1];y:=args[-2];c:= [args[1..-3]];
>>> if y=0 then 0 else
>>>  dist:=infinity;
>>>  eps:=1e-32;
>>>  fun:= 1;
>>>  for i from 1 to nargs-2 do fun:= exp(c[i]*fun) od;
>>>  fun:= z*fun-y;
>>>  dfun:=diff(fun,z);
>>>  s:=series(fun,z,n);
>>>  p:=convert(s,polynom);
>>>  sol:={fsolve(p=0,z,complex)}; #complex?
>>>  for i from 1 to nops(sol) do
>>>   aprx:=evalf(subs(z=op(i,sol),fun));
>>>   dy:=evalf(abs(aprx));
>>>   if dy<=dist then r:=op(i,sol);dist:=dy;fi;
>>>  od;
>>> #start Newton with approximate zero found.
>>>  oldr:=r;
>>>  newr:=r-evalf(subs(z=r,fun)/subs(z=r,dfun));
>>>  for i from 1 to 1000 while (abs((oldr-newr)/oldr)>eps) do
>>>   oldr:=newr;
>>>   newr:=newr-evalf(subs(z=newr,fun)/subs(z=newr,dfun));
>>>  od;
>>> newr;
>>> fi;
>>> end:
>>
>> When I try to plot it (in this case the arguments make it equivalent
>> to arcsin) I get:
>>
>>> with(plots):
>>> plot(HW(log(sin(z)/z),y,10),y=-1..1);
>> Error, (in fsolve) y is in the equation, and is not solved for
>>
>> while if I do a:
>>
>>> N:=50;x1:=-1;x2:=1;
>>> x:=n->x1+abs(x2-x1)/N*n;
>>> L:=[seq([x(n),HW(log(sin(z)/z),x(n),10)],n=0..N)]:
>>> plot(L,scaling=constrained);
>>
>> It works (shows the graph of arcsin).
>>
>> Individual values seem to be calculated correctly. For example:
>>
>>> HW(log(sin(z)/z),0.245,10);
>> .247519692533815916885429116210
>>
>> Does anyone know why the plot command doesn't work with this
>> function?
>
> The cause is premature evaluation.  The plot procedures (as most Maple
> procedures) first evaluates its arguments.   But
>
> HW(log(sin(z)/z),y,10);
>
> raises the error because y is not numeric.  An easy solution is
> to delay the evaluation of HW.  You can do that via
>
>  plot('HW'(log(sin(z)/z),y,10),y=-1..1);

Thanks. I thought of premature evaluation, but I didn't know what delimiters to 
put around HW. On Maple V rel 5, it was `HW`(..) so I tried that and it didn't 
work.

Now it seems to be 'HW'(...).
-- 
I. 

[toc] | [prev] | [next] | [standalone]


#221

FromJoe Riel <joer@san.rr.com>
Date2011-07-28 14:31 -0700
Message-ID<87ipqmf5yh.fsf@san.rr.com>
In reply to#220
"I.N. Galidakis" <morpheus@olympus.mons> writes:

> Joe Riel wrote:
>> "I.N. Galidakis" <morpheus@olympus.mons> writes:
>>
>>> I am having some problems with Maple 9 when plotting a certain
>>> function. The function is:
>>>
>>>> HW:=proc()
>>>> local y,n,c,s,p,sol,i,aprx,dy,dist,r,oldr,newr,fun,dfun,eps;
>>>> if nargs<2 then ERROR("At least two arguments required.") fi;
>>>> n:= args[-1];y:=args[-2];c:= [args[1..-3]];
>>>> if y=0 then 0 else
>>>>  dist:=infinity;
>>>>  eps:=1e-32;
>>>>  fun:= 1;
>>>>  for i from 1 to nargs-2 do fun:= exp(c[i]*fun) od;
>>>>  fun:= z*fun-y;
>>>>  dfun:=diff(fun,z);
>>>>  s:=series(fun,z,n);
>>>>  p:=convert(s,polynom);
>>>>  sol:={fsolve(p=0,z,complex)}; #complex?
>>>>  for i from 1 to nops(sol) do
>>>>   aprx:=evalf(subs(z=op(i,sol),fun));
>>>>   dy:=evalf(abs(aprx));
>>>>   if dy<=dist then r:=op(i,sol);dist:=dy;fi;
>>>>  od;
>>>> #start Newton with approximate zero found.
>>>>  oldr:=r;
>>>>  newr:=r-evalf(subs(z=r,fun)/subs(z=r,dfun));
>>>>  for i from 1 to 1000 while (abs((oldr-newr)/oldr)>eps) do
>>>>   oldr:=newr;
>>>>   newr:=newr-evalf(subs(z=newr,fun)/subs(z=newr,dfun));
>>>>  od;
>>>> newr;
>>>> fi;
>>>> end:
>>>
>>> When I try to plot it (in this case the arguments make it equivalent
>>> to arcsin) I get:
>>>
>>>> with(plots):
>>>> plot(HW(log(sin(z)/z),y,10),y=-1..1);
>>> Error, (in fsolve) y is in the equation, and is not solved for
>>>
>>> while if I do a:
>>>
>>>> N:=50;x1:=-1;x2:=1;
>>>> x:=n->x1+abs(x2-x1)/N*n;
>>>> L:=[seq([x(n),HW(log(sin(z)/z),x(n),10)],n=0..N)]:
>>>> plot(L,scaling=constrained);
>>>
>>> It works (shows the graph of arcsin).
>>>
>>> Individual values seem to be calculated correctly. For example:
>>>
>>>> HW(log(sin(z)/z),0.245,10);
>>> .247519692533815916885429116210
>>>
>>> Does anyone know why the plot command doesn't work with this
>>> function?
>>
>> The cause is premature evaluation.  The plot procedures (as most Maple
>> procedures) first evaluates its arguments.   But
>>
>> HW(log(sin(z)/z),y,10);
>>
>> raises the error because y is not numeric.  An easy solution is
>> to delay the evaluation of HW.  You can do that via
>>
>>  plot('HW'(log(sin(z)/z),y,10),y=-1..1);
>
> Thanks. I thought of premature evaluation, but I didn't know what
> delimiters to put around HW. On Maple V rel 5, it was `HW`(..) so I
> tried that and it didn't work.
>
> Now it seems to be 'HW'(...).

The interpretation of backquotes and forward quotes has not changed.
Backquotes create a symbol from non-alphanumeric characters.
Forward quotes delay evaluation.

-- 
Joe Riel

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.maple


csiph-web