MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Re: what's wrong about my package?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg45467] RE: [mg45457] Re: what's wrong about my package?
  • From: "David Park" <djmp at earthlink.net>
  • Date: Fri, 9 Jan 2004 05:20:33 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Andy,

I don't completely understand your code or the theory behind it. But if
BernsteinPolynomial is supposed to return a polynomial in some variable then
you could pass the variable symbol as a last optional argument.

BernsteinPolynomial[fx_, x_, n_, var_:Global`t] :=
   Module[{}, Sum[Replace[fx, x -> i/n]*
      Bernstein[i, n, var], {i, 0, n}]];

Notice that I changed t to var in the body of the definition. I then
included var as a last optional argument in the calling sequence, giving it
the optional value of Global`t. The Global context is necessary, otherwise
since this is defined within you package t would be put in the Private
context of your package. (When you develop a routine like this in a notebook
you don't need the Global` context, but as soon as you move it to a package
you do. This is a common error.)

This way the polynomials would come out as polynomials in t, unless the user
choose to pass some other symbol. t might be used for something else, or
have a value so the user might want to use another symbol and not have one
forced on him.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

From: ANDY [mailto:wangzhengyao at hotmail.com]
To: mathgroup at smc.vnet.net

is there some simple method to handle it?
thank you?



"David Park" <djmp at earthlink.net> wrote in message
news:btg8lj$8ug$1 at smc.vnet.net...
> Andy,
>
> In your last statement
>
> BernsteinPolynomial[fx_, x_,n_] :=Module[{},Sum[Replace[fx,
> x ->i/n]*Bernstein[i, n, t], {i, 0, n}]];
>
> you introduced the symbol t and since this is introduced in the Private
> section of your package it has the complete domain specification of
>
> CAGD`Private`t
>
> and that is what you are complaining about. But I have no idea what should
> be there instead of t. If t is supposed to be a variable that is used in
the
> answer, you may want to replace the last call with
>
> Bernstein[i, n, Global`t]
>
> But it might be better to let the user pass the symbol he wishes to use.
>
> David Park
> djmp at earthlink.net
> http://home.earthlink.net/~djmp/
>
> From: ANDY [mailto:wangzhengyao at hotmail.com]
To: mathgroup at smc.vnet.net
>
> hello,
> i want to build a package about computer aided Geometirc design for me!
>
> ____________________________________
> ......
> Begin["`Private`"]
> Bernstein[i_, n_, v_] := Binomial[n, i]*(1 - v)^(n - i)*v^i
>
> BezierCurve[pts : {{_, _} ..} | {{_, _, _} ..}, v_] :=
>     Module[{n = Length[pts] - 1},
>       Simplify[
>         Table[Bernstein[i, n, v], {i, 0, n}].pts]
>       ];
>
> BernsteinPolynomial[fx_, x_,n_] :=Module[{},Sum[Replace[fx,
> x ->i/n]*Bernstein[i, n, t], {i, 0, n}]];
>
> End[]
> EndPackage[]
> ___________________________________
>
>  i want use BernsteinPolynomial to compute the Bernstein Polynomial of the
> function fx (f(x)),but when i use it in mathematica,there are something
> wrong:
>
>
> In[28]:=
> \!\(BernsteinPolynomial[x\^2 + x, x, 8]\)
>
> Out[28]=
> \!\(\((1 - CAGD`Private`t)\)\^8\ \((x + x\^2)\) + 8\ \((1 -
> CAGD`Private`t)\)\
> \^7\ CAGD`Private`t\ \((x + x\^2)\) + 28\ \((1 - CAGD`Private`t)\)\^6\ \
> CAGD`Private`t\^2\ \((x + x\^2)\) + 56\ \((1 - CAGD`Private`t)\)\^5\ \
> CAGD`Private`t\^3\ \((x + x\^2)\) + 70\ \((1 - CAGD`Private`t)\)\^4\ \
> CAGD`Private`t\^4\ \((x + x\^2)\) + 56\ \((1 - CAGD`Private`t)\)\^3\ \
> CAGD`Private`t\^5\ \((x + x\^2)\) + 28\ \((1 - CAGD`Private`t)\)\^2\ \
> CAGD`Private`t\^6\ \((x + x\^2)\) + 8\ \((1 - CAGD`Private`t)\)\ \
> CAGD`Private`t\^7\ \((x + x\^2)\) + CAGD`Private`t\^8\ \((x + x\^2)\)\)
>
>
> Why?
> how to correct it??
> thank you?
>
>
> Andy
> 2004.1.5
>
>
>
>
>




  • Prev by Date: Re: 2^20991011-1
  • Next by Date: Re: Mathematica exports curves in pieces to Illustrator
  • Previous by thread: Context of option symbols
  • Next by thread: Using loops inside NMaximize