acer

19387 Reputation

29 Badges

14 years, 309 days

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Firstly, using a common bracketed notation for pretty-printing the result, and then some alternatives.

restart;

MySumP := (j::integer) ->
  seq(%binomial((j+10),(i+10))*p^(j+i)*(1-p)^(j+i), i= 0..0):

foo := MySumP(10);

%binomial(20, 10)*p^10*(1-p)^10

foo;

%binomial(20, 10)*p^10*(1-p)^10

value(foo);

184756*p^10*(1-p)^10

# If you do not prefer the gray round brackets

InertForm:-Display(foo, ':-inert'=false);

%binomial(20, 10)*p^10*(1-p)^10

# optionally

`print/%binomial`:=proc() ':-C'(args); end proc:

 

foo;

%binomial(20, 10)*p^10*(1-p)^10

value(foo);

184756*p^10*(1-p)^10

`print/%binomial`:=proc(m,n) ':-C'[n]^m; end proc:

 

foo;

%binomial(20, 10)*p^10*(1-p)^10

value(foo);

184756*p^10*(1-p)^10

# Now with upright Roman "C"

`print/%binomial`:=proc(m,n)
    uses Typesetting;
    msubsup(mtext("C"),mn(convert(n,string)),
            mn(convert(m,string)));
end proc:

 

foo;

%binomial(20, 10)*p^10*(1-p)^10

value(foo);

184756*p^10*(1-p)^10

`print/%binomial`:=proc(m,n)
    uses Typesetting;
    mscripts(mi("C"),mn(convert(n,string)),
             none()$3,mn(convert(m,string)),none());
end proc:

 

foo;

%binomial(20, 10)*p^10*(1-p)^10

value(foo);

184756*p^10*(1-p)^10

# Now with upright Roman "C", and smaller numerals

`print/%binomial`:=proc(m,n)
    uses Typesetting;
    mscripts(mtext("C"),mn(convert(n,string),':-mathsize'=10),
             none()$3,mn(convert(m,string),':-mathsize'=10),none());
end proc:

 

foo;

%binomial(20, 10)*p^10*(1-p)^10

value(foo);

184756*p^10*(1-p)^10

NULL

Download inertbinomial.mw

If you don't want your PDF file interspersed with empty spaces due to forced page-breaks then you might also try using Array-plots for your 3D plots.

Eg,
   plots:-display(Array([plot3d(sin(x))]));
instead of,
   plot3d(sin(x));

That will put a Table border around each such plots, though you can toggle off the visibility of its borders using right-click menu choice Table->Properties just before exporting.

A:=[1,2,3]:
B:=[7,8,9]:

zip(f,A,B);

            [f(1, 7), f(2, 8), f(3, 9)]

I often adjust my Mapleprimes posts by switching the editor into "source" mode, using the icon at the top left of the editor.

In source mode, such gray fixed-width text areas can be delineated by the <pre> ... </pre> markup tags.

It works like the HTML tags of the same name.

 

Try,

  getenv("MAPLE");

instead of your attempt,

  getenv("$MAPLE"); 

Or see the examples on the ?getenv Help page, which do not include the dollar symbol.

 

Here is a way, for Maple 2015.

restart;

kernelopts(version);

`Maple 2015.2, X86 64 LINUX, Dec 20 2015, Build ID 1097895`

L := 1:

AAA := 3.888022*10^(-42)*p*q-4.75389*10^(-42)*y*p*q+7.4699*10^(-43)*y*p*q^2+9.1169*10^(-43)*y*p^2*q:

map(int,(int(q*AAA/sqrt(p^2+q^2+1),p=0..L)),q=0..L);

-0.1867377355e-42*y+0.453450449e-42+int(-0.4558450000e-42*q^4*y*ln(1.+(q^2+2.)^(1/2)), q = 0 .. 1)+int(-0.4558450000e-42*y*ln(1.+(q^2+2.)^(1/2))*q^2, q = 0 .. 1)

factor(expand(%));

-0.4211444464e-42*y+0.453450449e-42

#
# The following suggestion doesn't work in Maple 2015, since
# IntegrationTools:-Expand incorrectly pulls q out of both integrals.
#

restart;

L := 1:

AAA := 3.888022*10^(-42)*p*q-4.75389*10^(-42)*y*p*q+7.4699*10^(-43)*y*p*q^2+9.1169*10^(-43)*y*p^2*q:

Int(q*AAA/sqrt(p^2 + q^2 + 1), [p = 0 .. L, q = 0 .. L]):

evalf(IntegrationTools:-Expand(%));

0.1464659791e-41*q^2-0.1568649000e-41*q^2*y+0.2813991838e-42*q^3*y

 

Download question_integration_ac.mw

After some investigation, it seems that the problem is due to the plotting substructure COLOR(NONE) that is in the encoded output for the odeplot call(s) in your worksheet saved in Maple 7.

In Maple 2015.2 and earlier that errant substructure seems to get ignored when the worksheet is reopened, but in Maple 2016 and later it causes the GUI's layout remndering to appear corrupted.

In Maple 16 through to Maple 2015, the errant substructure does not get stored in the encoded output in the re-saved XML .mw file.

I will submit a bug report, noting that:
  - Encountering a problematic PLOT substructure shouldn't ruin the whole sheet's rendering. At worst the plot's output could be ignored and discarded upon the problematic reopening.
  - Since Maple 7 allowed this to be created, and since versions up to Maple 2015 accomodated it fine, then later releases should also accomodate it upon re-opening  (and discard it).

I could write a script to that could fix up the problematic .mw file, and then open in a new GUI tab. But not until next week. The problem might even be isolated to the output returned by the odeplot command in the much older versions (I cannot check right now). It isn't a common issue.

The command plots:-display3d does nothing except pass on its arguments to the same internal procedure that plots:-display does.

You might as well use plots:-display in all cases where you'd want to use either, and not make things confusing to your students.

The only difference is minor, in that plots:-display utilizes a try..catch so that its errors are caught and rethrown (which can affect where they appear to come from).

showstat(plots:-display3d);

  plots:-display3d := proc()
     1   `plots/display`(_passed)
  end proc
showstat(plots:-display);

  plots:-display := proc()
     1   try
     2       `plots/display`(_passed)
         catch :
     3       error
         end try
  end proc

By the way, your last example is just wrong. There is no display3DA command, which name you called. Your call to it may produce output as a pair of plots wrapped in an unevaluated function call to that same name, but that signifies nothing. You'd get a similar output if your called  foobar({p1,p2});  where foobar is just some unassigned name.

Alternatively, in a single statement,

restart;
expr := Sum((-1)^n - 1, n = 1 .. infinity):

simplify(subs(n=nn,op(1,expr))) assuming nn::even;

                     0

I mention the above because it might help in a similar situation where the wrapping command is not simplify and doesn't provide for its own assume option.

I should probably also mention this mechanism.

restart;
Physics:-Setup(assumingusesAssume = true):

expr := Sum((-1)^n - 1, n = 1 .. infinity):

simplify(op(1,expr)) assuming n::even;
                     0

More tricky, ie. harder IMO to get right more generally,

value(simplify('`%assuming`'([op(1,expr)],[n::even])));

                     0

value('`%assuming`'(['simplify'(op(1,expr))],[n::even]));

                     0

Your call removes entries whose value equals the value of A[1], which is 1. Both the entries A[1] and A[3] satisfy that criterion of having the same value as A[1], and consequently both are removed.

If you simply want to chop off only the first entry then it's more efficient to do it via indexing, eg.
  A:=Array([1,4,1,7]);
  A[2..-1];  # without reindexing from 1
  rtable_redim(A[2..-1],1..op([2,2],A)-1); # with reindexing from 1

(If you care about reindexing a great deal then it could be easier to use a Vector instead of an Array.)

But you haven't indicated clearly what your actual purpose is, so it's tricky to guess what might be best.

 

I am not sure what you are shooting for. Is it an expression that you could manipulate symbolically, or a fast procedure to evaluate at numeric values, or...?

You can use a symbol j (in lieu of 6) if you utilize binomial, and obtain various forms. I don't really see why hypergeom would serve much better than inert Sum, primarily because you didn't tell us anything about how you plan to use your result. I don't really understand what kind of formula or general expression you might be hoping for.

Or you could use a procedure taking j (or j and w) as arguments.

restart;

Sg:=(n,w)->1-(1-w)^n*add(binomial(n-1+i,n-1)*w^i,i=0..n-1):
Sg(6,3);

-4682367

Sg(6,w);
eval(%,w=3);

1-(1-w)^6*(252*w^5+126*w^4+56*w^3+21*w^2+6*w+1)

-4682367

S:=sum(w*binomial(j+i,i+1)*w^(j-1)*(1-w)^(i+1),i=-1..j-2);

1-w*binomial(2*j-1, j)*w^(j-1)*(1-w)^j*hypergeom([1, 2*j], [j+1], 1-w)

S6:=convert(eval(S,j=6),elementary);

1-(1-w)^6*(252*w^5+126*w^4+56*w^3+21*w^2+6*w+1)

eval(S6,w=3);

-4682367

add(w*binomial(6+i,i+1)*w^(6-1)*(1-w)^(i+1),i=-1..6-2);

w^6+6*w^6*(1-w)+21*w^6*(1-w)^2+56*w^6*(1-w)^3+126*w^6*(1-w)^4+252*w^6*(1-w)^5

eval(%,w=3);

-4682367

add(eval(w*binomial(6+i,i+1)*w^(6-1)*(1-w)^(i+1),w=3),i=-1..6-2);

-4682367

A:=simplify(1-(1-w)^j*sum(binomial(j-1+i,j-1)*w^i,i=0..j-1));
convert(eval(A,[j=6,w=3]),elementary);
convert(eval(A,[j=6]),elementary);
eval(%,w=3);

binomial(2*j-1, j-1)*w^j*hypergeom([1, 2*j], [j+1], w)*(1-w)^j

-4682367

-w^6*(252*w^5-1386*w^4+3080*w^3-3465*w^2+1980*w-462)*(1-w)^6/(-1+w)^6

-4682367

 

Download addbinomial.mw

[edit] The OP has not said much about how this is to be used. There is at least one other interesting case -- where an expression denoting the case that j is unspecified has to be passed around, but which is supposed to compute to a numeric result when the parameter is subsequently substituted by a number. Using uneval-quotes around a function call can be tricky and fragile, and passing around such a beast can be irksome.

So another possible useful case is the procedure which returns unevaluated unless some arguments are numeric. For example, below the calls Sg(j,w) or Sj(j,3) can be passed around without worry of prematurely invoking add with wrong arguments -- until such time as j gets a numeric value. Modify as needed.

restart;

Sg:=proc(n,w)
      if not n::numeric then return 'procname'(args); end if;
      1-(1-w)^n*add(binomial(n-1+i,n-1)*w^i,i=0..n-1);
end proc:

Sg(6,3);

-4682367

Sg(j,3); # no error emitted
eval(%,[j=6]);

Sg(j, 3)

-4682367

# And, now, for example...
#plot([Sg(2,w),Sg(3,w)], w=0..1);

 

Download addbinomial2.mw

As I'm sure you're aware, there are several ways to manually store a Matrix between sessions, by issuing a command. Eg. storing to .mla, text file, or workbook.

But you seem to be asking about the Matrix being automatically and dynamically stored/saved so that its saved version matches its running values -- with no command needed prior to closing/restart apart from normal closing of the Worksheet/Document.

The answer is that this is one of the purposes why the DataTable was invented. It provides this functionality that otherwise did not conveniently and robustly exist.

(The "State" embedded-component provides a similar mechanism, but it is really just a kind of hidden DataTable -- and is designed more for programmatically constructed embedded-component assemblies.)

As I showed you in your earlier question, you can utilize eval(...,1) to useful effect. In particular, you can compare it against the result from a full eval call.

restart;

ode1 := :-parse("diff(y(x),x$2)=0"):

lprint(eval(ode1,1));

diff(y(x),x $ 2) = 0

evalb(eval(ode1)=eval(ode1,1));

false

f := proc()
  local ode1;
  ode1 := :-parse("diff(y(x),x$2)=0");
  evalb(eval(ode1)=eval(ode1,1));
end proc:
f();

false

ode1 := eval(:-parse("diff(y(x),x$2)=0")):

lprint(eval(ode1,1));

diff(diff(y(x),x),x) = 0

evalb(eval(ode1)=eval(ode1,1));

true

f := proc()
  local ode1;
  ode1 := eval(:-parse("diff(y(x),x$2)=0"));
  evalb(eval(ode1)=eval(ode1,1));
end proc:
f();

true

restart;

ode1 := 'sin(2.1)':

lprint(eval(ode1,1));

sin(2.1)

evalb(eval(ode1)=eval(ode1,1));

false

f := proc()
  local ode1;
  ode1 := 'sin(2.1)';
  evalb(eval(ode1)=eval(ode1,1));
end proc:
f();

false

ode1 := sin(2.1):

lprint(eval(ode1,1));

.8632093666

evalb(eval(ode1)=eval(ode1,1));

true

f := proc()
  local ode1;
  ode1 := eval(sin(2.1));
  evalb(eval(ode1)=eval(ode1,1));
end proc:
f();

true

 

Download eval_1.mw

If you call the parse command with no options then it does not evaluate its result. And inside your procedure the local ode gets only 1-level evaluation.

You can wrap parse with a call to eval, or you can supply the option statement.

restart;
foo:=proc()
  local ode,func;  
  local x,y; #adding this did not  help

  ode  :=  :-parse("diff(y(x),x$2)=0", statement);
  func :=  :-parse("y(x)");

  try
     dsolve(ode), DEtools:-odeadvisor(ode,func);
  catch:
     error lastexception;
  end try;

end proc:

foo();

y(x) = _C1*x+_C2, [[_2nd_order, _quadrature]]

restart;
foo:=proc()
  local ode,func;  
  local x,y; #adding this did not  help

  ode  :=  eval(:-parse("diff(y(x),x$2)=0"));
  func :=  :-parse("y(x)");

  try
     dsolve(ode), DEtools:-odeadvisor(ode,func);
  catch:
     error lastexception;
  end try;

end proc:

foo();

y(x) = _C1*x+_C2, [[_2nd_order, _quadrature]]

 

Download parse_example.mw

If that is assigned to the name M then try accessing the entry by indexing, eg.   M[1,1]

Upload and attach your worksheet, if you want to help us to help you.

1 2 3 4 5 6 7 Last Page 1 of 221