acer

32490 Reputation

29 Badges

20 years, 7 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@chelchax Please don't repost duplicates of this. Duplicates will be flagged as such, and may be deleted.

Followup details are useful, and can be placed here (as Comment/Reply on the Question or one of its Answers).

You may need to have a little patience.

What progress have you made so far, on this?

If it's really a table then it has indices as well as entries. What are they?

If it's not actually a table (ie. a list or something else) then please show the details. You can upload a worksheet here using the green up-arrow in the Mapleprimes editor.

Please make sure to explain what kind of plot you want to produce.

@Kitonum I did consider whether to present exact values. I chose on purpose to compute with floating-point values.

I also chose deliberately to show several more steps than necessary.

It's often difficult to gauge what some particular Asker will find more useful and instructive, based only on a few lines of a Question.

 

@raj2018 Please don't repost this in other Question threads.

@dglevitt

This is a link.

@rlopez The simplify command attains the desired result directly in my Maple 2019.{0,1,2},  and Maple 2020.1, without the assumption that rho__m is real.

@Kitonum The expand command does it directly in Maple 2018.2 (and also in Maple 2020.1, as I showed in my Answer).

The evalc command assumes the unknown rho__m is real, but that is not a necessary condition.

@9009134 You could do it by writing your definition for it here, in words.

You need to tell us what you want.

@9009134 You've already identifed why the L31+L32+L33 for the new equation are not equal to its LHS. The difference consists of the mixed terms.

In order to "extract" them you should first specify a unique manner in which they may be grouped.

@Zeineb In your old Maple 12, does this run?

restart:
t0:=0; x0:=<1,2>;
f:= (t, v) -> <t*v[1], v[2]> ;
x[0]:= t -> x0;
for n to 5 do
x[n] := unapply( x0 + map(int, f(tau, x[n-1](tau)), tau=t0..t),  t);
print(x[n]= x[n](t));
od:

@ceight1 Where did you get the function (x,y)->y and exp(x) from, in your attempt? How do you think that those relate to this example's differential equation? [Perhaps your instructor or your textbook used a previous example like that. But this example's differential equation involves a different right-hand side formula. It is not the differential equation y'(x)=y(x) here.]

 

Slope Fields

 

restart

ode := diff(y(x), x) = -2*x*y(x)+1

diff(y(x), x) = -2*x*y(x)+1

ic := y(0) = 0

y(0) = 0

exactsol := dsolve({ic, ode})

y(x) = (1/2)*exp(-x^2)*Pi^(1/2)*erfi(x)

exactsolfunc := unapply(rhs(exactsol), x)

proc (x) options operator, arrow; (1/2)*exp(-x^2)*Pi^(1/2)*erfi(x) end proc

NULL 

Euler's Method

 

 

f := proc (x, y) options operator, arrow; -2*x*y+1 end proc

proc (x, y) options operator, arrow; -2*y*x+1 end proc

x[0] := 0; y[0] := 0; h := .1

.1

for n to 101 do x[n] := n*h; y[n] := y[n-1]+h*f(x[n-1], y[n-1]) end do

data1 := [seq([x[n], y[n]], n = 0 .. 101)]NULLNULL

 

t1 := plot(data1, style = point, color = blue)

t2 := plot(exactsolfunc, 0 .. 10, color = red)

h := 0.5e-1

0.5e-1

for n to 201 do x[n] := n*h; y[n] := y[n-1]+h*f(x[n-1], y[n-1]) end do
NULL``

 

data2 := [seq([x[n], y[n]], n = 0 .. 201)]

t3 := plot(data2, style = point, color = black)

plots[display]({t1, t2, t3}, gridlines)

NULL

NULL

NULL

Download HELP_CODE_ac.mw

Don't post this same problem more than once.

If you have followup queries of details for the example (in addition to the syntax issue with writing x*y(x) as xy) then put them in a Comment/Reply here.

Here's that other way (substitution into a template procedure, and nicer error message).

restart;

# assign some values to the global names,
# in order to catch mistakes in the namespace
# use if things break.
(m,n,x) := -17,-33,t;

-17, -33, t

functionB:=proc(k::nonnegint,M::nonnegint,
                epsilon::realcons, gamma::realcons)
    local K,h,m,n,x;
    if not is(epsilon>-1)<>false then
      error "expecting parameter epsilon>-1, but received %1",epsilon;
    end if;
    if not is(gamma>-1)<>false then
      error "expecting parameter epsilon>-1, but received %1",epsilon;
    end if;
    K:=2^(k-1):
    h:=simplify(2^(epsilon+gamma+1)*GAMMA(epsilon+m+1)
                *GAMMA(gamma+m+1)/((2*m+1+epsilon+gamma)
                                   *m!*GAMMA(epsilon+gamma+1)))
         assuming n::nonnegint, n<=K, m::nonnegint, m<=M-1;
    subs(subs([n=':-n',m=':-m',x=':-x'],
               __dummy=piecewise((n-1)/K <= x and x <= n/K,
                                 'simplify'(2^(k/2)*h
                                            *JacobiP(m,epsilon,gamma,2^(k)*x-2*n+1)),
                                 0)),
         __Kdummy=K, __Mdummy=M,
         eval(proc(n::nonnegint,m::nonnegint,x)
           if n>__Kdummy then error
             "expecting first parameter n to be less than or equal to %1, but received %2",
             __Kdummy,n;
           end if;
           if m>__Mdummy-1 then error
             "expecting second parameter m to be less than or equal to %1, but received %2",
             __Mdummy-1,m;
           end if;
           __dummy;
         end proc)),
    unapply((1-x)^(epsilon)*(1+x)^gamma, [x]);
end proc:

(psi,w):=functionB(3,4,1,2);
psi(1,1,x);

Typesetting:-mrow(Typesetting:-mi("&psi;", italic = "false", mathvariant = "normal"), Typesetting:-mo("&comma;", mathvariant = "normal", fence = "false", separator = "true", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.3333333em"), Typesetting:-mi("w", italic = "true", mathvariant = "italic"), Typesetting:-mo("&Assign;", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.2777778em", rspace = "0.2777778em"), Typesetting:-mrow(Typesetting:-mo("proc", bold = "true", mathvariant = "bold", fontweight = "bold", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.0em"), Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mi("n", italic = "true", mathvariant = "italic"), Typesetting:-mo("::", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.0em"), Typesetting:-mi("nonnegint", italic = "true", mathvariant = "italic")), Typesetting:-mo(",", mathvariant = "normal", fence = "false", separator = "true", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.3333333em"), Typesetting:-mrow(Typesetting:-mi("m", italic = "true", mathvariant = "italic"), Typesetting:-mo("::", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.0em"), Typesetting:-mi("nonnegint", italic = "true", mathvariant = "italic")), Typesetting:-mo(",", mathvariant = "normal", fence = "false", separator = "true", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.3333333em"), Typesetting:-mi("x", italic = "true", mathvariant = "italic")), mathvariant = "normal"), Typesetting:-mspace(height = "0.0ex", width = "0.5em", depth = "0.0ex", linebreak = "firstprocnewline"), Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mo("if", bold = "true", mathvariant = "bold", fontweight = "bold", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.0em"), Typesetting:-mspace(height = "0.0ex", width = "0.5em", depth = "0.0ex", linebreak = "auto"), Typesetting:-mrow(Typesetting:-mn("4", mathvariant = "normal"), Typesetting:-mo("<", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.2777778em", rspace = "0.2777778em"), Typesetting:-mi("n", italic = "true", mathvariant = "italic")), Typesetting:-mspace(height = "0.0ex", width = "0.5em", depth = "0.0ex", linebreak = "auto"), Typesetting:-mo("then", bold = "true", mathvariant = "bold", fontweight = "bold", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.0em"), Typesetting:-mspace(height = "0.0ex", width = "0.5em", depth = "0.0ex", linebreak = "increaseindentnewline"), Typesetting:-mrow(Typesetting:-mo("error", bold = "true", mathvariant = "bold", fontweight = "bold", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.0em"), Typesetting:-mspace(height = "0.0ex", width = "0.5em", depth = "0.0ex", linebreak = "auto"), Typesetting:-mrow(Typesetting:-ms("expecting first parameter n to be less than or equal to %1, but received %2"), Typesetting:-mo(",", mathvariant = "normal", fence = "false", separator = "true", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.3333333em"), Typesetting:-mn("4", mathvariant = "normal"), Typesetting:-mo(",", mathvariant = "normal", fence = "false", separator = "true", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.3333333em"), Typesetting:-mi("n", italic = "true", mathvariant = "italic"))), Typesetting:-mspace(height = "0.0ex", width = "0.5em", depth = "0.0ex", linebreak = "decreaseindentnewline")), Typesetting:-mo("end if", bold = "true", mathvariant = "bold", fontweight = "bold", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.0em")), Typesetting:-mo(";", mathvariant = "normal", fence = "false", separator = "true", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.2777778em"), Typesetting:-mspace(height = "0.0ex", width = "0.5em", depth = "0.0ex", linebreak = "firstprocnewline")), Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mo("if", bold = "true", mathvariant = "bold", fontweight = "bold", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.0em"), Typesetting:-mspace(height = "0.0ex", width = "0.5em", depth = "0.0ex", linebreak = "auto"), Typesetting:-mrow(Typesetting:-mn("3", mathvariant = "normal"), Typesetting:-mo("<", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.2777778em", rspace = "0.2777778em"), Typesetting:-mi("m", italic = "true", mathvariant = "italic")), Typesetting:-mspace(height = "0.0ex", width = "0.5em", depth = "0.0ex", linebreak = "auto"), Typesetting:-mo("then", bold = "true", mathvariant = "bold", fontweight = "bold", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.0em"), Typesetting:-mspace(height = "0.0ex", width = "0.5em", depth = "0.0ex", linebreak = "increaseindentnewline"), Typesetting:-mrow(Typesetting:-mo("error", bold = "true", mathvariant = "bold", fontweight = "bold", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.0em"), Typesetting:-mspace(height = "0.0ex", width = "0.5em", depth = "0.0ex", linebreak = "auto"), Typesetting:-mrow(Typesetting:-ms("expecting second parameter m to be less than or equal to %1, but received %2"), Typesetting:-mo(",", mathvariant = "normal", fence = "false", separator = "true", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.3333333em"), Typesetting:-mn("3", mathvariant = "normal"), Typesetting:-mo(",", mathvariant = "normal", fence = "false", separator = "true", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.3333333em"), Typesetting:-mi("m", italic = "true", mathvariant = "italic"))), Typesetting:-mspace(height = "0.0ex", width = "0.5em", depth = "0.0ex", linebreak = "decreaseindentnewline")), Typesetting:-mo("end if", bold = "true", mathvariant = "bold", fontweight = "bold", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.0em")), Typesetting:-mo(";", mathvariant = "normal", fence = "false", separator = "true", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.2777778em"), Typesetting:-mspace(height = "0.0ex", width = "0.5em", depth = "0.0ex", linebreak = "firstprocnewline")), Typesetting:-mrow(Typesetting:-mi("piecewise", italic = "true", mathvariant = "italic"), Typesetting:-mo("&ApplyFunction;", family = "Courier", size = "10", bold = "false", italic = "false", underline = "false", subscript = "false", superscript = "false", foreground = "[0,0,0]", background = "[255,255,255]", opaque = "false", executable = "false", readonly = "false", composed = "false", converted = "false", imselected = "false", placeholder = "false", `selection-placeholder` = "false", mathvariant = "normal", fence = "unset", separator = "unset", stretchy = "unset", symmetric = "unset", largeop = "unset", movablelimits = "unset", accent = "unset", lspace = "0.0em", rspace = "0.0em"), Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mn("1", mathvariant = "normal"), Typesetting:-mo("/", mathvariant = "normal", fence = "false", separator = "false", stretchy = "true", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.1666667em", rspace = "0.1666667em"), Typesetting:-mn("4", mathvariant = "normal")), Typesetting:-mo("*", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.1666667em", rspace = "0.1666667em"), Typesetting:-mrow(Typesetting:-mi("n", italic = "true", mathvariant = "italic"))), Typesetting:-mo(" − ", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.0em"), Typesetting:-mrow(Typesetting:-mn("1", mathvariant = "normal"), Typesetting:-mo("/", mathvariant = "normal", fence = "false", separator = "false", stretchy = "true", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.1666667em", rspace = "0.1666667em"), Typesetting:-mn("4", mathvariant = "normal"))), Typesetting:-mo("<=", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.2777778em", rspace = "0.2777778em"), Typesetting:-mi("x", italic = "true", mathvariant = "italic")), Typesetting:-mspace(height = "0.0ex", width = "0.5em", depth = "0.0ex", linebreak = "auto"), Typesetting:-mo("and", bold = "true", mathvariant = "bold", fontweight = "bold", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.0em"), Typesetting:-mspace(height = "0.0ex", width = "0.5em", depth = "0.0ex", linebreak = "auto"), Typesetting:-mrow(Typesetting:-mi("x", italic = "true", mathvariant = "italic"), Typesetting:-mo("<=", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.2777778em", rspace = "0.2777778em"), Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mn("1", mathvariant = "normal"), Typesetting:-mo("/", mathvariant = "normal", fence = "false", separator = "false", stretchy = "true", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.1666667em", rspace = "0.1666667em"), Typesetting:-mn("4", mathvariant = "normal")), Typesetting:-mo("*", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.1666667em", rspace = "0.1666667em"), Typesetting:-mrow(Typesetting:-mi("n", italic = "true", mathvariant = "italic"))))), Typesetting:-mo(",", mathvariant = "normal", fence = "false", separator = "true", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.3333333em"), Typesetting:-mrow(Typesetting:-mi("simplify", italic = "true", mathvariant = "italic"), Typesetting:-mo("&ApplyFunction;", family = "Courier", size = "10", bold = "false", italic = "false", underline = "false", subscript = "false", superscript = "false", foreground = "[0,0,0]", background = "[255,255,255]", opaque = "false", executable = "false", readonly = "false", composed = "false", converted = "false", imselected = "false", placeholder = "false", `selection-placeholder` = "false", mathvariant = "normal", fence = "unset", separator = "unset", stretchy = "unset", symmetric = "unset", largeop = "unset", movablelimits = "unset", accent = "unset", lspace = "0.0em", rspace = "0.0em"), Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mn("8", mathvariant = "normal"), Typesetting:-mo("/", mathvariant = "normal", fence = "false", separator = "false", stretchy = "true", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.1666667em", rspace = "0.1666667em"), Typesetting:-mn("3", mathvariant = "normal")), Typesetting:-mo("*", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.1666667em", rspace = "0.1666667em"), Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mn("2", mathvariant = "normal"), Typesetting:-mo("^", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.1111111em", rspace = "0.1111111em"), Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mn("1", mathvariant = "normal"), Typesetting:-mo("/", mathvariant = "normal", fence = "false", separator = "false", stretchy = "true", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.1666667em", rspace = "0.1666667em"), Typesetting:-mn("2", mathvariant = "normal")), mathvariant = "normal")), Typesetting:-mo("*", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.1666667em", rspace = "0.1666667em"), Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi("m", italic = "true", mathvariant = "italic"), Typesetting:-mo("+", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.2222222em", rspace = "0.2222222em"), Typesetting:-mn("1", mathvariant = "normal")), mathvariant = "normal"), Typesetting:-mo("*", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.1666667em", rspace = "0.1666667em"), Typesetting:-mrow(Typesetting:-mi("Γ", italic = "false", mathvariant = "normal"), Typesetting:-mo("&ApplyFunction;", family = "Courier", size = "10", bold = "false", italic = "false", underline = "false", subscript = "false", superscript = "false", foreground = "[0,0,0]", background = "[255,255,255]", opaque = "false", executable = "false", readonly = "false", composed = "false", converted = "false", imselected = "false", placeholder = "false", `selection-placeholder` = "false", mathvariant = "normal", fence = "unset", separator = "unset", stretchy = "unset", symmetric = "unset", largeop = "unset", movablelimits = "unset", accent = "unset", lspace = "0.0em", rspace = "0.0em"), Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mi("m", italic = "true", mathvariant = "italic"), Typesetting:-mo("+", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.2222222em", rspace = "0.2222222em"), Typesetting:-mn("2", mathvariant = "normal"))), mathvariant = "normal")), Typesetting:-mo("*", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.1666667em", rspace = "0.1666667em"), Typesetting:-mrow(Typesetting:-mi("JacobiP", italic = "false", mathvariant = "normal"), Typesetting:-mo("&ApplyFunction;", family = "Courier", size = "10", bold = "false", italic = "false", underline = "false", subscript = "false", superscript = "false", foreground = "[0,0,0]", background = "[255,255,255]", opaque = "false", executable = "false", readonly = "false", composed = "false", converted = "false", imselected = "false", placeholder = "false", `selection-placeholder` = "false", mathvariant = "normal", fence = "unset", separator = "unset", stretchy = "unset", symmetric = "unset", largeop = "unset", movablelimits = "unset", accent = "unset", lspace = "0.0em", rspace = "0.0em"), Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi("m", italic = "true", mathvariant = "italic"), Typesetting:-mo(",", mathvariant = "normal", fence = "false", separator = "true", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.3333333em"), Typesetting:-mn("1", mathvariant = "normal"), Typesetting:-mo(",", mathvariant = "normal", fence = "false", separator = "true", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.3333333em"), Typesetting:-mn("2", mathvariant = "normal"), Typesetting:-mo(",", mathvariant = "normal", fence = "false", separator = "true", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.3333333em"), Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mn("8", mathvariant = "normal"), Typesetting:-mo("*", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.1666667em", rspace = "0.1666667em"), Typesetting:-mi("x", italic = "true", mathvariant = "italic")), Typesetting:-mo(" − ", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.0em"), Typesetting:-mrow(Typesetting:-mn("2", mathvariant = "normal"), Typesetting:-mo("*", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.1666667em", rspace = "0.1666667em"), Typesetting:-mi("n", italic = "true", mathvariant = "italic")), Typesetting:-mo("+", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.2222222em", rspace = "0.2222222em"), Typesetting:-mn("1", mathvariant = "normal"))), mathvariant = "normal"))))), mathvariant = "normal")), Typesetting:-mo(",", mathvariant = "normal", fence = "false", separator = "true", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.3333333em"), Typesetting:-mn("0", mathvariant = "normal")), mathvariant = "normal"))), Typesetting:-mspace(height = "0.0ex", width = "0.5em", depth = "0.0ex", linebreak = "decreaseindentnewline"), Typesetting:-mo("end proc", bold = "true", mathvariant = "bold", fontweight = "bold", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.0em")), Typesetting:-mo("&comma;", mathvariant = "normal", fence = "false", separator = "true", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.3333333em"), Typesetting:-mrow(Typesetting:-mi("x", italic = "true", mathvariant = "italic"), Typesetting:-mo("&map;", mathvariant = "normal", fence = "false", separator = "false", stretchy = "true", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.2777778em", rspace = "0.2777778em"), Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mn("1", mathvariant = "normal"), Typesetting:-mo("&minus;", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.2222222em", rspace = "0.2222222em"), Typesetting:-mi("x", italic = "true", mathvariant = "italic")), mathvariant = "normal"), Typesetting:-mo("&InvisibleTimes;", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.0em", rspace = "0.0em"), Typesetting:-msup(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi("x", italic = "true", mathvariant = "italic"), Typesetting:-mo("&plus;", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.2222222em", rspace = "0.2222222em"), Typesetting:-mn("1", mathvariant = "normal")), mathvariant = "normal"), Typesetting:-mn("2", mathvariant = "normal"), superscriptshift = "0"))))

piecewise(0 <= t and t <= 1/4, (32/3)*2^(1/2)*(-3+20*t), 0)

local Psi:=x->Array([seq(seq(psi(i,j,x),j=0..4-1),i=1..2^(2-1))] )^+:
Psi(4/10);
w(x);
psi(-1,0,x);
psi(5,0,x);
psi(0,4,x);

Vector(8, {(1) = 0, (2) = 0, (3) = 0, (4) = 0, (5) = (8/3)*sqrt(2), (6) = 0, (7) = -(1008/25)*sqrt(2), (8) = -(8192/125)*sqrt(2)})

(1-t)*(t+1)^2

Error, invalid input: psi expects its 1st argument, n, to be of type nonnegint, but received -1

Error, (in psi) expecting first parameter n to be less than or equal to 4, but received 5

Error, (in psi) expecting second parameter m to be less than or equal to 3, but received 4

functionB(-3,4,1,2);

Error, invalid input: functionB expects its 1st argument, k, to be of type nonnegint, but received -3

functionB(3,4,1,Q);

Error, invalid input: functionB expects its 4th argument, gamma, to be of type realcons, but received Q

functionB(3,4,1,-2);

Error, (in functionB) expecting parameter epsilon>-1, but received 1

(psi,w) := functionB(1,4,0,0);
psi(0,0,0);
psi(-1,0,1);

proc (n::nonnegint, m::nonnegint, x) if 1 < n then error "expecting first parameter n to be less than or equal to %1, but received %2", 1, n end if; if 3 < m then error "expecting second parameter m to be less than or equal to %1, but received %2", 3, m end if; piecewise(n-1 <= x and x <= n, simplify(2*2^(1/2)*GAMMA(m+1)*JacobiP(m, 0, 0, 2*x-2*n+1)/(2*m+1)), 0) end proc, proc (x) options operator, arrow; 1 end proc

2*2^(1/2)

Error, invalid input: psi expects its 1st argument, n, to be of type nonnegint, but received -1

 

Download functionB_rev2.mw

@Maple_lover1 The interesting bit is making the first generated procedure (the first result from calling functionB) issue nice error messages if subsequently called with either n greater than the precomputed K or m greater than M-1.

I see two ways to accomplish that. The first (which I've done below) is have the n and m parameters be specified using the satisfies parameter-processing modifier. This is easier to code, although as you may see when there is a violation the error message is slightly awkward.

Another way (which I have not done here) is to substitute the piecewise into a template procedure that is coded to emit a more graceful error message. The piecewise itself can contain the protected global name equivalents for n,m,x after another substitution.

restart;

functionB:=proc(k::nonnegint,M::nonnegint,
                epsilon::realcons, gamma::realcons)
    local K,h,n,m,x,dummy;
    if not is(epsilon>-1)<>false then
      error "expecting parameter epsilon>-1, but received %1",epsilon;
    end if;
    if not is(gamma>-1)<>false then
      error "expecting parameter epsilon>-1, but received %1",epsilon;
    end if;
    K:=2^(k-1):
    h:=simplify(2^(epsilon+gamma+1)*GAMMA(epsilon+m+1)
                *GAMMA(gamma+m+1)/((2*m+1+epsilon+gamma)
                                   *m!*GAMMA(epsilon+gamma+1)))
         assuming n::nonnegint, n<=K, m::nonnegint, m<=M-1;
    unapply(piecewise((n-1)/K <= x and x <= n/K,
                      'simplify'(2^(k/2)*h
                                 *JacobiP(m,epsilon,gamma,2^(k)*x-2*n+1)),
                      0),
         [n::And(nonnegint,satisfies(subs(dummy=K,u->u<=dummy))),
          m::And(nonnegint,satisfies(subs(dummy=M-1,u->u<=dummy))),x]),
    unapply((1-x)^(epsilon)*(1+x)^gamma, [x]);
end proc:

(psi,w):=functionB(3,4,1,2);
local Psi:=x->Array([seq(seq(psi(i,j,x),j=0..4-1),i=1..2^(2-1))] )^+:
Psi(4/10);
w(x);
psi(-1,0,x);
psi(5,0,x);
psi(0,4,x);

psi, w := proc (n::(`and`('nonnegint', satisfies(proc (u) options operator, arrow; u <= 4 end proc))), m::(`and`('nonnegint', satisfies(proc (u) options operator, arrow; u <= 3 end proc))), x) options operator, arrow; piecewise((1/4)*n-1/4 <= x and x <= (1/4)*n, simplify((8/3)*sqrt(2)*(m+1)*GAMMA(2+m)*JacobiP(m, 1, 2, 8*x-2*n+1)), 0) end proc, proc (x) options operator, arrow; (1-x)*(x+1)^2 end proc

Vector[column](%id = 18446884443842064502)

(1-x)*(x+1)^2

Error, invalid input: psi expects its 1st argument, n, to be of type And(nonnegint, satisfies(proc (u) options operator, arrow; u <= 4 end proc)), but received -1

Error, invalid input: psi expects its 1st argument, n, to be of type And(nonnegint, satisfies(proc (u) options operator, arrow; u <= 4 end proc)), but received 5

Error, invalid input: psi expects its 2nd argument, m, to be of type And(nonnegint, satisfies(proc (u) options operator, arrow; u <= 3 end proc)), but received 4

functionB(-3,4,1,2);

Error, invalid input: functionB expects its 1st argument, k, to be of type nonnegint, but received -3

functionB(3,4,1,Q);

Error, invalid input: functionB expects its 4th argument, gamma, to be of type realcons, but received Q

functionB(3,4,1,-2);

Error, (in functionB) expecting parameter epsilon>-1, but received 1

(psi,w) := functionB(1,4,0,0);
psi(0,0,0);
psi(-1,0,1);

psi, w := proc (n::(`and`('nonnegint', satisfies(proc (u) options operator, arrow; u <= 1 end proc))), m::(`and`('nonnegint', satisfies(proc (u) options operator, arrow; u <= 3 end proc))), x) options operator, arrow; piecewise(n-1 <= x and x <= n, simplify(2*sqrt(2)*GAMMA(m+1)*JacobiP(m, 0, 0, 2*x-2*n+1)/(2*m+1)), 0) end proc, proc (x) options operator, arrow; 1 end proc

2*2^(1/2)

Error, invalid input: psi expects its 1st argument, n, to be of type And(nonnegint, satisfies(proc (u) options operator, arrow; u <= 1 end proc)), but received -1

 

Download functionB_rev1.mw

By the way, how do you expect functionB to be used by someone? If it is to be invoked many times on-the-fly in the same session with (occasionally, or often) the exact same arguments then it might benefit performancewise to give option remember to functionB. (Ie, memoization)

First 151 152 153 154 155 156 157 Last Page 153 of 594