acer

32587 Reputation

29 Badges

20 years, 36 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Try using the ImageTools:-Scale command to scale down the number of columns.

Make the Matrix datatype=float[8]. Much better for memory performance would be to make the 50x500000 Matrix with the float[8] datatype when first created. Less great, if numeric Matrix M is datatype=anything, would be to create the copy Matrix(M,datatype=float[8]) .

Eg,

restart;

n:=50000:

M:=Matrix(50,n,(i,j)->evalhf(sin(j*5*Pi/n)),datatype=float[8]):

ImageTools:-Scale(M, 1..500, 1..500);

ImageTools:-Scale(M, 1, 1..500);

In the top right of your web browser window your handle/name should appear. It's a link to your profile page.

Your profile contains a section containing all your posted Question/Answers/Replies.

Here is a link to all the Questions you've asked on this site.

I was only able to reproduce your 2D Input problem if I entered the Unit(s) appearing in that denominator by using the Units palette.

But if I used 2D command-completion then it worked ok. When you have the input cursor in that denominator then instead of using the s from the Units palette then instead type it in as follows. First type in Unit and then hit the Escape key, and then a popup menu of choices should appear. Select the top menu item, to enter a unit. That should enter the typeset template for the unit, with a dummy name like u highlighted. Simply type s to replace the dummy name. Then use the right-arrow to move the cursor to the next entry point.

But why not combine all the units in your expression first, to just J? You can do that programmatically, or in this case mentally.

restart

E__n := proc (n) options operator, arrow; (-1)*6.63*Unit('J')*Unit('s')*3*10^8*Unit('m'/'s')*1.097*10^7*Unit(1/'m')/(10^34*n^2) end proc

combine(E__n(4), units)

-0.1363708125e-18*Units:-Unit(J)

(1)

E__n := unapply(combine(-1.097*(6.63*10^(-34)*Unit('J')*Unit('s')*3)*10^8*Unit('m'/'s')*10^7*Unit(1/'m')/n^2, units), n)

proc (n) options operator, arrow; -0.2181933000e-17*Units:-Unit(J)/n^2 end proc

(2)

E__n(4)

-0.1363708125e-18*Units:-Unit(J)

(3)

kernelopts(version)

`Maple 2018.1, X86 64 LINUX, Jun 8 2018, Build ID 1321769`

(4)

``

Download Maple_prob1_ac.mw

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.

First 175 176 177 178 179 180 181 Last Page 177 of 338