acer

32363 Reputation

29 Badges

19 years, 333 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

How about just the following, if the file name is test.txt.

M := parse~(ImportMatrix("test.txt",delimiter=" "));

You would replace test.txt with the fully qualified file name, according to its actual location on your machine, or first call currentdir( ) appropriately.

restart:

kernelopts(version);

`Maple 2018.0, X86 64 LINUX, Mar 9 2018, Build ID 1298750`

with(Statistics):
N := 3:
X := RandomVariable(Binomial(N, 1/2)):

F := value(CDF(X, s, inert));

F := sum(piecewise(_t < 0, 0, binomial(3, _t)*(1/2)^_t*(1/2)^(3-_t)), _t = 0 .. s)

plot(F, s=-1..N+1,
     gridlines=true, axis[1]=[gridlines=N+1],
     thickness=3);

Download binomialcdf.mw

It wasn't clear to me whether you also needed the terms to be sorted. So I do it with and without, below.

restart;

 

P:=proc(expr, nm)
  local f, i, j, k, L, s;
  s:=`tools/gensym`(nm);
  f:=proc() `tools/genglobal`(s); end proc:
  f(),f();
  L:=PolynomialTools:-CoefficientList(expr,nm):
  add(add(`*`(seq(f(),j=1..i-1)),k=1..L[i]),i=1..nops(L));
end proc:

 

foo := 2*x + 3*x^3;

3*x^3+2*x

ans1 := P(foo, x);

x10*x11*x9+x3*x4*x5+x6*x7*x8+x1+x2

ans2 := P(foo, x);

x10*x11*x9+x3*x4*x5+x6*x7*x8+x1+x2

ans1-ans2;

0

sort( ans1, order=plex(seq(cat(x,i),i=1..nops(indets(ans1,name)))) );

x1+x2+x3*x4*x5+x6*x7*x8+x9*x10*x11

bar := expand(t*randpoly(t, degree=3, coeffs=rand(1..3), dense));

t^4+3*t^3+3*t^2+2*t

new := P(bar, t);

t18*t19*t20*t21+t10*t11*t9+t12*t13*t14+t15*t16*t17+t3*t4+t5*t6+t7*t8+t1+t2

sort( new, order=plex(seq(cat(t,i),i=1..nops(indets(new,name)))) );

t1+t2+t3*t4+t5*t6+t7*t8+t9*t10*t11+t12*t13*t14+t15*t16*t17+t18*t19*t20*t21

 

Download polygen.mw

Was the restriction on a subsequently added to the Question?

restart;

f := sin(x) / ( ( sin(a*x) )^a * ( sin((1-a)*x) )^(1-a) ):

MultiSeries:-limit(f, x=0, left) assuming a>0, a<1;

-1/((-1+a)^(1-a)*(-a)^a)

MultiSeries:-limit(f, x=0, right) assuming a>0, a<1;

1/((1-a)^(1-a)*a^a)

simplify(evala(%-%%)) assuming a>0, a<1;

0

 

Download limitparam.mw

 

You could have a look at this old discussion thread (and the links to yet older discussions, in my Answer there).

The reason that you see "so many" solutions is that by default for your example solve computes both real and complex solutions.

If you only want purely real solutions of your system of polynomial equations then pass the additional option real to the solve command.

restart;

f1:=x^2+y^2=1:

f2:=y=x^3:

solve({f1,f2},{x,y},real,explicit);

{x = -(1/6)*(6*(108+12*93^(1/2))^(1/3)-72/(108+12*93^(1/2))^(1/3))^(1/2), y = -(1/216)*(6*(108+12*93^(1/2))^(1/3)-72/(108+12*93^(1/2))^(1/3))^(3/2)}, {x = (1/6)*(6*(108+12*93^(1/2))^(1/3)-72/(108+12*93^(1/2))^(1/3))^(1/2), y = (1/216)*(6*(108+12*93^(1/2))^(1/3)-72/(108+12*93^(1/2))^(1/3))^(3/2)}

 

Download solvepolysysreal.mw

 

It is simply -> which are the keystrokes minus - , and greater-than > .

You can have a blank space before or after them, but no space between them.

As for the manual, see this section of the Programming Guide.

The following was all done in a terminal session (Command Line Interface, or CLI).

( x->sin(x)+x )( 5 );                                                                        

                     sin(5) + 5

( x -> sin(x)+x )( 5 );                                                                      

                     sin(5) + 5


map( x->sin(x)+x, [2,3,7] );                                                                 

          [sin(2) + 2, sin(3) + 3, sin(7) + 7]

f := x->sin(x)+x;                                                                            

                 f := x -> sin(x) + x

f(t);                                                                                        

                     sin(t) + t

expr := cos(x)^2;                                                                            

                                  2
                    expr := cos(x)

g := unapply( expr, x );                                                                     

                                  2
                  g := x -> cos(x)

g(t);                                                                                        

                         2
                   cos(t)

x -> tan(x)^2;                                                                               

                          2
               x -> tan(x)

proc(x) option operator, arrow; tan(x)^2; end proc;

                          2
               x -> tan(x)

Why do you expect the conjugate on r^(1/4) to resolve just because r is assumed real? You seem to be overlooking the possibility that r could be negative.

restart;

Psi00 := exp(-(1/2)*r^2)/sqrt(Pi):

ig := conjugate(Psi00*r^(1/4))*Psi00*r^(1/4)*r assuming r>0;

(exp(-(1/2)*r^2))^2*r^(3/2)/Pi

int(int(ig, r = 0 .. infinity), phi = 0 .. 2*Pi);

(1/4)*Pi*2^(1/2)/GAMMA(3/4)

restart;

assume(r>0);

Psi00 := exp(-(1/2)*r^2)/sqrt(Pi):

ig := conjugate(Psi00*r^(1/4))*Psi00*r^(1/4)*r;

(exp(-(1/2)*r^2))^2*r^(3/2)/Pi

int(int(ig, r = 0 .. infinity), phi = 0 .. 2*Pi);

(1/4)*Pi*2^(1/2)/GAMMA(3/4)

 

Download conj.mw

Let us know if you want to build these things programmatically and have any trouble with that (it should be pretty straightfroward). Or if you want additional aspects like color, or fonts/color/weight on 2D Math.

restart;

MyTitle:=Typesetting:-mrow(Typesetting:-mn("Identity function",
                                           fontfamily=Times,size=14,bold=true),
                           Typesetting:-mn("\n(illustration)",
                                           fontfamily=Times,size=12)):

plot(x, x=0..1, title=MyTitle);

 

Download plottitlefont.mw

While the ShowSolutions command fails on this example (because of the presence of parameter s, I suspect), a step-by-step solution is still attainable.

restart;

with(Student:-Calculus1):

floatJ:=Int(.5*exp(-s*t)*exp(-4.5*t)*sin(2*Pi*t), t):

J:=convert(floatJ,rational);

Int((1/2)*exp(-s*t)*exp(-(9/2)*t)*sin(2*Pi*t), t)

(1)

j:=value(J):
simplify(j);

((-2*s-9)*sin(2*Pi*t)-4*Pi*cos(2*Pi*t))*exp(-s*t-(9/2)*t)/(16*Pi^2+4*s^2+36*s+81)

(2)

Rule[constantmultiple](J):
Rule[change, u = -(s+9/2)*t, u](%):
Rule[constantmultiple](%):
Rule[parts, exp(u), int(sin(4*Pi*u/(2*s+9)),u)](%):
Rule[constantmultiple](%):
Rule[parts, exp(u), int(cos(4*Pi*u/(2*s+9)),u)](%):
Rule[constantmultiple](%):
Rule[solve](%):
ans := Rule[revert](%);

CALCULUS1OBJECT([1, [], []], {s, t}) = -exp(-(1/2)*(2*s+9)*t)*(4*Pi*cos(2*Pi*t)+2*s*sin(2*Pi*t)+9*sin(2*Pi*t))/(16*Pi^2+4*s^2+36*s+81)

(3)

simplify(ans);

CALCULUS1OBJECT([1, [], []], {s, t}) = ((-2*s-9)*sin(2*Pi*t)-4*Pi*cos(2*Pi*t))*exp(-s*t-(9/2)*t)/(16*Pi^2+4*s^2+36*s+81)

(4)

 

Download stepbystepexample.mw

The case of a parsing error can be handled by doing the parse before calling dsolve. And you could put that in a try...catch and deal with it as you prefer.

When there is no previous parsing error, there's no hard set of rules that will always allow you to distinguish subsequently between cases like your 1.) and 2.), for arbitrary commands. It varies from command to command.

You can often make some distinctions of case 3) versus the other two, according to lastexception[1] which you have not utilized yet. It will often denote which named procedure emitted the error. So you could programmatically test -- or otherwise distinguish -- between the case that dsolve threw the error or some other procedure did. For example, simply printing it:

restart;

try
  ode := parse( "diff(y(x),x) +? y", ':-statement' );
catch:
  print("parsing error");
  print(StringTools:-FormatMessage( lastexception[2..-1]));
end try;

"parsing error"

"incorrect syntax in parse: character `?` unexpected (near 15th character of parsed string)"

ode := parse( "diff(y(x),x) + y", ':-statement' );

diff(y(x), x)+y

try
   dsolve(ode,y(x));
catch:
   # Or do something else if lastexception[1] is not `dsolve`
   print(cat(sprintf("%a: ",lastexception[1]),
         StringTools:-FormatMessage( lastexception[2..-1])));
end try;

 

"dsolve: y(x) and y cannot both appear in the given ODE."

 

Download lastexception1.mw

ps. Please don't delete your question once someone's responded and you've resolved your difficulty, as like last week on stackexchange.

The situation you're describing involves what's called a optional positional parameter.

You should use the quote-protected global name as the default value, to avoid problems such as when the global name is already assigned a value.

Eg,

restart;

sim := proc( x, n,
             o::identical(exactly,maximum,minimum) := ':-exactly' )
          return o;
       end proc:

sim();
                            exactly

exactly := 4:

sim();
                            exactly

That also helps avoid undesirable side-effects even if exactly were an unevaluated function call. (Such situations do occur.) Defensive programming is a good habit -- and I'll advocate it even if I don't always follow my own advice.

Your expectation is not valid.

Perhaps you meant to query   max(abs(Q))  ?

restart

A := Matrix(10, 10, {(1, 1) = 0.358665012985547e-3, (1, 2) = -0.164628637225196e-2, (1, 3) = 0.808705603350256e-3, (1, 4) = 0.131914692392149e-2, (1, 5) = -0.120745384995453e-2, (1, 6) = -0.127685186328850e-3, (1, 7) = -0.368262140727460e-3, (1, 8) = 0.722934152182773e-3, (1, 9) = 0.406838157326509e-3, (1, 10) = -0.270949354604275e-3, (2, 1) = -1.04811784877605, (2, 2) = -0.227246433636184e-2, (2, 3) = 1.12987295590946, (2, 4) = 0.320910227706809e-2, (2, 5) = -0.837137925723646e-1, (2, 6) = -0.590494756927829e-3, (2, 7) = 0.141893953127997e-2, (2, 8) = -0.431705701475750e-3, (2, 9) = 0.529611988652095e-3, (2, 10) = 0.876913927974057e-4, (3, 1) = -0.186537779517955e-2, (3, 2) = 0.731113455007046e-3, (3, 3) = -0.916700660778503e-2, (3, 4) = -0.429742144388156e-2, (3, 5) = 0.171402262358938e-1, (3, 6) = 0.147242552352914e-2, (3, 7) = -0.837021118160759e-2, (3, 8) = 0.348174114649671e-2, (3, 9) = 0.225687533471807e-2, (3, 10) = -0.139775301206369e-2, (4, 1) = -1.52107139964422, (4, 2) = 0.808077875491177e-2, (4, 3) = 1.64372029140351, (4, 4) = -0.847286100516818e-2, (4, 5) = -.127335986762229, (4, 6) = 0.118070315638635e-2, (4, 7) = 0.424032693235149e-2, (4, 8) = -0.111038208252920e-2, (4, 9) = 0.434602411991222e-3, (4, 10) = 0.318930385884084e-3, (5, 1) = 0.289424730370674e-2, (5, 2) = -0.172887794344293e-2, (5, 3) = 0.157061251396572e-1, (5, 4) = -0.363778806608431e-2, (5, 5) = -0.221497403961738e-1, (5, 6) = 0.205810013144210e-2, (5, 7) = 0.290388608347142e-2, (5, 8) = 0.554530769943721e-2, (5, 9) = 0.645600822073613e-3, (5, 10) = -0.223995662113480e-2, (6, 1) = 4.05367823691209, (6, 2) = -0.669541776787987e-2, (6, 3) = -4.37687402333541, (6, 4) = 0.100071882622313e-1, (6, 5) = .331612307231483, (6, 6) = -0.222866442868341e-2, (6, 7) = -0.854247230826875e-2, (6, 8) = -0.198825849939076e-2, (6, 9) = 0.144764377225621e-3, (6, 10) = 0.887581546748840e-3, (7, 1) = 0.437884803847533e-3, (7, 2) = -0.468560550990847e-2, (7, 3) = -0.274035269283456e-2, (7, 4) = 0.132221205985872e-2, (7, 5) = 0.587286710360397e-2, (7, 6) = 0.141670610986008e-2, (7, 7) = -0.324890905770655e-2, (7, 8) = 0.346314407352620e-2, (7, 9) = -0.313507643096885e-3, (7, 10) = -0.150449109852917e-2, (8, 1) = -1.74365543905306, (8, 2) = 0.329936253329467e-2, (8, 3) = 1.88180005384087, (8, 4) = -0.307966351872919e-2, (8, 5) = -.141724173079475, (8, 6) = 0.461487956516473e-3, (8, 7) = 0.455622531837965e-2, (8, 8) = -0.147959204065083e-2, (8, 9) = -0.964311997155483e-3, (8, 10) = 0.776900663643289e-3, (9, 1) = -0.182153308681337e-2, (9, 2) = 0.731579627122705e-2, (9, 3) = -0.459671306590223e-2, (9, 4) = 0.528628529817773e-2, (9, 5) = 0.340926625224384e-3, (9, 6) = -0.480044705401815e-2, (9, 7) = 0.906564729308528e-2, (9, 8) = -0.131891681339107e-1, (9, 9) = -0.298963526401197e-2, (9, 10) = 0.539189475787896e-2, (10, 1) = .259153153490112, (10, 2) = -0.239896326933024e-2, (10, 3) = -.278509331317189, (10, 4) = -0.165332320182602e-2, (10, 5) = 0.211686310866469e-1, (10, 6) = 0.115660284907533e-2, (10, 7) = -0.165524436062079e-2, (10, 8) = 0.496708050164578e-2, (10, 9) = -0.161592001287913e-3, (10, 10) = -0.203232293033617e-2})

Q := A/max(abs(A))

max(Q)

.926158307610656317

(1)

max(1/max(A).A)

1.00000000011419887

(2)

max(1/max(abs(A)).abs(A))

1.00000000021082958

(3)

L := [4, -10]:

max(abs~(L));

10

(4)

1/max(abs~(L)) * L;
max(%); # so what!

[2/5, -1]

 

2/5

(5)

1/max(abs~(L)) * abs~(L);
max(%);

[2/5, 1]

 

1

(6)

1/max(L) * L;
max(%);

[1, -5/2]

 

1

(7)

``

Download suuual_ac.mw 

 

One way that the error message "bad index into Array" can occur is where Maple tries to access the Array using a non-numeric index.

A typical example would be where Maple tries to access, say, Y[i] where the name i does not yet have an integer value. Eg,

restart;
Y := Array(1..10, i->i):

Y[i];
Error, bad index into Array

The seq command has special evaluation rules, which prevents Y[i] from being evaluated until i gets actual values. So this works.

restart;
Y := Array(1..10, i->i):

seq(Y[i], i=1..10);
               1, 2, 3, 4, 5, 6, 7, 8, 9, 10

But the sum command does not have special evaluation rules. The following produces the same error as does the first example above,

restart;
Y := Array(1..10, i->i):

sum(Y[i], i=1..10);
Error, bad index into Array

What just happened was that Maple tried to evaluate the first argument passed to the sum call before i got any value, which is Maple's usual evaluation rules for procedure calls. But, for what you are trying to accomplish, the Array reference Y[i] was evaluated prematurely.

Here are two alternative ways to do summation involving Array elements:

1) Use the add command instead of the sum command, since the add command also has special evaluation rules.

restart;
Y := Array(1..10, i->i):
add(Y[i], i=1..10);
                           55

2) Delay the indexed Array reference using unevaluation quotes (single right-quotes).

restart;
Y := Array(1..10, i->i):
sum('Y[i]', i=1..10);
                           55

Now, I am guessing that this kind of premature evaluation of an indexed Array reference is your problem, mostly based on your use of the words, "summation index" and the particular error message you cited. If I've guess wrongly then please provide the full example.

I'll note that at least one other Answer seems to be indicating that you've accessed Array entries using invalid numeric values for the index. I suspect that is not your problem, however, mostly because the error message for that situation is different than your Question's title.

restart;
Y := Array(1..10, i->i):

seq(Y[i+1]-Y[i], i=1..10);
Error, Array index out of range

seq(Y[i+1]-Y[i], i=0..9);
Error, Array index out of range

On MS-Windows and Linux you can use the keyboard short-cuts Ctl-r to temporarily switch from text mode to 2D Input mode, and Ctl-t to switch back.

On Mac OS X I believe that it's similar, Cmd-r and Cmd-t .

See the help-pages for more.

First 173 174 175 176 177 178 179 Last Page 175 of 336