acer

32385 Reputation

29 Badges

19 years, 334 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

If you don't want to use the right-click context-menus then... just type out your command instead.

Also, it looks to me as if you wanted to map the commands over the whole Matrix and not over just the [1,1] entry. Yes?

 

M := Matrix([[1/7*(5*exp(-3*t)+2*exp(4*t))*exp(-t),
              2/7*(exp(-3*t)-exp(4*t))*exp(-t)],
             [5/7*(exp(-3*t)-exp(4*t))*exp(-t),
              1/7*(2*exp(-3*t)+5*exp(4*t))*exp(-t)]]);

M := Matrix(2, 2, {(1, 1) = ((5/7)*exp(-3*t)+(2/7)*exp(4*t))*exp(-t), (1, 2) = ((2/7)*exp(-3*t)-(2/7)*exp(4*t))*exp(-t), (2, 1) = ((5/7)*exp(-3*t)-(5/7)*exp(4*t))*exp(-t), (2, 2) = ((2/7)*exp(-3*t)+(5/7)*exp(4*t))*exp(-t)})

map(combine@expand,M);

Matrix(2, 2, {(1, 1) = (5/7)*exp(-4*t)+(2/7)*exp(3*t), (1, 2) = (2/7)*exp(-4*t)-(2/7)*exp(3*t), (2, 1) = (5/7)*exp(-4*t)-(5/7)*exp(3*t), (2, 2) = (2/7)*exp(-4*t)+(5/7)*exp(3*t)})

 

 

Download matrixmap.mw

acer

Yes, you can inline 2D Math into text sentences in a Document.

Use Ctl-t to toggle into text mode. In that mode you can type sentences. In mid-sentence you can use Ctl-r to toggle into 2D Input mode. And then you can toggle back to text. 

Such inlined 2D Math will not evaluate, unless you cause it to be evaluated. That is, by default it is inert 2D Math. The way to evaluate it inline is to select it (or have the cursor inside it) and then to use the keystrokes Ctl-=.

Ctl-t means the Control key and the lowercase `t` key pressed simultaneously. Similalry, Ctl-= means the Control key and the `=` key. That's on MS_Windows. On OS X (Mac) it is Command-= instead of Control-=. See here.

Here's a Document that I just made in Maple 2015 on Windows.

 

f := sin(x)

sin(x)

This is a Document. I used Ctl-t to get to text mode. Now I'll use Ctl-r to get to 2D Input mode, and I'll use Ctl-= to evaluate it inline. I'll do both those steps twice in the next sentence. The derivative of the original function f = sin(x) is diff(f, x) = cos(x). I did not type out sin(x)or cos(x)in the last sentence. Instead I used Ctl-= after using Ctl-r to enter 2D Input mode.

 

Download textandinlinedmath.mw

Note that once such inlined math is evaluated inline (within some text) it cannot be turned back into inert 2D Math. In can be deleted, though. If you change the code which assigns to `f` say, and then reevaluate the whole worksheet then the previously evaluated inline math involving `f` gets reevealuated and shows the new assigned value.

You can change the style used for displayed 2D Math output so that it appears black instead of blue. That's just part of the usual customizing of styles (character, paragraph, etc) that can be done within a Document,

acer

I'm not sure how you (or Maple TA) is generating the random aspects of the assignments. But you might try forcing the random seed which is used by several of Maple's internal random number generators. (Ie, the TA process might fortuitously happen to rely on this. You could at least try it..)

See the randomize comand. The idea is that you could try forcing its r parameter (the random seed) according to each student, at the start of the code which generates the assignments.

acer

On way to get that effect is via piecewise structures.

 

f:=x^3-5*x^2+x+5:

plot([piecewise(f>0,f,undefined),piecewise(f<0,f,undefined)],

     x=-2..5, color=[blue,red]);

 

 

Download 2Dplotcolor.mw

plot3d supports a colorfunc option to use a procedure for coloring. The plot command should be given that as well.

acer

You might prefer the result if you used inert Sum instead of active sum. The latter is producing the GAMMA calls which you had trouble getting rid of.


MTBF = solve(R = exp(t/MTBF) * (t/MTBF) * Sum(1/(i!), i=0..n),MTBF);

MTBF = t/LambertW(R/(Sum(1/factorial(i), i = 0 .. n)))

restart:

eqn1:= R = exp(t/MTBF) * (t/MTBF) * sum(1/(i!), i=0..n);

R = exp(t/MTBF)*t*exp(1)*GAMMA(n+1, 1)/(MTBF*GAMMA(n+1))

eqn2:= MTBF = solve(eqn1,MTBF):

simplify(convert(eqn2,compose,Sum,factorial)) assuming n::posint;

MTBF = t/LambertW((Sum((-1)^_k1/factorial(_k1), _k1 = 0 .. infinity))*R*exp(1)/(Sum(1/factorial(_k1), _k1 = 0 .. n)))

 


Download LW.mw

acer

You could try something like this, with alias.


restart:

aliasedlatex:=proc(e)
  local lookup;
  lookup:=op(eval(alias:-ContentToGlobal)):
  :-latex(eval(e,lookup));
  NULL;
end proc:

alias(Y=X(a,b,c)):

test:=X(a,b,c):

latex(test);

X \left( a,b,c \right)

aliasedlatex(test);

Y

H:=sin(test)+1/test:

latex(H);

\sin \left( X \left( a,b,c \right)  \right) + \left( X \left( a,b,c

 \right)  \right) ^{-1}

aliasedlatex(H);

\sin \left( Y \right) +{Y}^{-1}

 


Download aliasedlatex.mw

acer

I'd be interested to know whether this procedure `UpdatingRead` accomplishes what you want. It seems to work, in my 64bit Maple 18.02 and 2015.1 on Windows 7.

proc()
  assign(':-UpdatingRead',
         proc(fn::string)
           local oldanames;
           oldanames := {anames(':-user')};
           read fn;
           if IsWorksheetInterface(':-Standard') then
             try
               map(:-_UIUtils:-VariableManager:-AddToVariableManager,
                   {anames(':-user')} minus oldanames);
             catch:
               WARNING("variable manager update interrupted");
             end try;
           end if;
           NULL;
         end proc);
  NULL;
end proc();

The idea is to call it with the (string) name of the .m file.

UpdatingRead( cat(kernelopts(homedir),"/Downloads/foo.m") );

acer

Here are two ways, for lists of numeric entries (like your example L).

The first of these seems faster than the second, for long L.

ListTools:-SelectFirst(nops(L),`>`,L,0,output=indices);

[ListTools:-SearchAll(1,map(signum,L))];

But the first of those may have stack limit problems if tried repeatedly for long L (10^6 entries, say).

If you also want L to be able to contain nonnumeric entries then adjust the predicate in the SelectFirst approach above.

acer

Do you need something fancier than this?

G := (L::list(name),n::posint)->op((`*`@op)~(combinat[choose](L,n))):

G( [a,b,c], 2 );
                                a b, a c, b c

G( [q,r,s,t], 3 );
                         q r s, q r t, q s t, r s t

G( [q,r,s,t], 2 );
                        q r, q s, q t, r s, r t, s t

It wasn't clear to me that your input must be names. If not, then change the operator's first parameter from L::list(name) to just L::list, say.

acer

This particular problem can be solved using eliminate and without having to use solve or fsolve. In my opinion this is clean and simple. Others are free to hold their own opinions.

eq1:=convert( X=cos(theta) + 0.8e-1*cos(3.*theta), rational):
eq2:=convert( Y=-sin(theta)+ 0.8e-1*sin(3.*theta), rational):

sols:=[eliminate({eq1,eq2},{Y,theta})]:

S:=seq(eval(Y,sols[i][1]),i=1..nops(sols)):

Now S[1] is a formula for Y in terms of X alone.

There is another solution. I give just one way of obtaining it -- there are others. Observe that the formula for X is even (in theta), and formula for Y is odd. Hence we note that for a given X we can look to Y and -Y. No need to take my word for it: substitute -theta for theta, and re-eliminate.

osols:=[eliminate(subs(theta=-theta,{eq1,eq2}),{Y,theta})]:

oS:=seq(eval(Y,osols[i][1]),i=1..nops(osols)):

The other solution is oS[1] which is also a formula for Y in terms of X alone.

plot([S[1],oS[1]],X=-1-0.8e-1..1+0.8e-1,color=red);

Another thing that the eliminate command returns is further restrictions (second operand) on its main result (first operand). In this case there are no qualifying restrictions involving the eliminated variable(s).

seq(sols[i][2], i=1..nops(sols));  # restrictions on X (NULL)

                           {}, {}, {}

seq(osols[i][2], i=1..nops(osols));  # restrictions on X (NULL)

                           {}, {}, {}

No exact, symbolic method will work for all such problems in general. Approximate floating-point back-solving (eg. fsolve) is sometimes slower (like in this case), and it is prone to solution-tracking issues, especially for multivalued solutions. So if you can obtain a reasonably short explicit formula in a short amount of time then it's useful. Of course it is also easy to find example problems for which exact symbolic solving takes an enormous amount of resources to obtain an impractically un-useful result.

I'll probably ignore irrelevant comments.

acer

[edit: I initially misread your question as being about how to plot the intersection of the surfaces, and I initially focused on your Question's title. Sorry. Later down I get to the region, and to restricting the surface faces.]

There is a command for this in the plots package, called intersectplot. It produces the red spacecurve below.

If you don't want the gray plane as well, then just omit it from the call to display.

I deliberately used x^2=4-y^2 , for a circular cylinder below (though the axes scaled are displayed unconstrained). Change that as you wish.

restart:

with(plots):

display(intersectplot( x^2=4-y^2, z=2-y, x=0..4, y=0..2, z=0..2, thickness=4),
        plot3d(2-y, x=0..4, y=0..2, style=surface, color=gray, transparency=0.4),
        implicitplot3d(x^2=4-y^2, x=0..4, y=0..2, z=0..2, style=surface,
                       color=gold, transparency=0.4, grid=[30,30,10]),
        lightmodel=none, axes=box);

 

There are several other ways to accomplish this example, of course.

And, using your x=4-y^2 one could obtain the following. (I constrain the scaling of the axes here, for fun).

display(intersectplot( x=4-y^2, z=2-y, x=0..4, y=0..2, z=0..2, thickness=4),
        plot3d(2-y, x=0..4, y=0..2, style=surface, color=gray, transparency=0.4),
        implicitplot3d(x=4-y^2, x=0..4, y=0..2, z=0..2, style=surface,
                       color=gold, transparency=0.4, grid=[30,30,10]),
        lightmodel=none, axes=box, scaling=constrained);

As I mentioned, apoligies for focusing on the intersecting curve, while you really mentioned wanting to plot the enclosed region.

Note that the range arguments of the plot3d command can be variable. That's how I restrict the plane z=2-y in one of the plot3d calls below.

Also, a coordinate-transformed surface from plot3d can sometimes have less jagged rendered edges than a surface from implicitplot3d. Changing coordinate systems can be another way to deal with that. Below I take the portion of the parabolic sheet (what you called a cylinder) as being x=f(z,y) a mathematical function. And then I transformed to flip x and z coordinates.

restart:
with(plots):

display(intersectplot( x=4-y^2, z=2-y, x=0..4, y=0..2, z=0..2, thickness=4),
        plot3d(2-y, x=0..4-y^2, y=0..2, style=surface,
               color=gold, transparency=0.4),
        plottools:-transform((z,y,x)->[x,y,z])(plot3d(4-y^2, z=0..2-y, y=0..2,
                                               style=surface, color=gold,
                                               transparency=0.4)),
        lightmodel=Light4, glossiness=1.0, axes=box, scaling=constrained,
        view=[0..4, 0..2, 0..2]);

I'll leave the bottom and back plane portions to you. The variable range is the key.

acer


restart:

kernelopts(version);

`Maple 18.02, X86 64 LINUX, Oct 20 2014, Build ID 991181`

# -0.15356213  says wolframalpha.com for ee
# -0.15356212695352467  says wolframalpha for F5

MK := 1/96*(3^(3/5) - 9)*sqrt(10-2*sqrt(5))*GAMMA(7/5):

evalf[500](MK): evalf[15](%);

-.153562126953523

ee := Int(sin((x - 1/x)^5)^3/x^3, x=0..infinity);

Int(sin((x-1/x)^5)^3/x^3, x = 0 .. infinity)

with(IntegrationTools):

Split(ee, 1);

Int(sin((x-1/x)^5)^3/x^3, x = 0 .. 1)+Int(sin((x-1/x)^5)^3/x^3, x = 1 .. infinity)

# ee = f1 + f2

f1,f2 := op(%);

Int(sin((x-1/x)^5)^3/x^3, x = 0 .. 1), Int(sin((x-1/x)^5)^3/x^3, x = 1 .. infinity)

# ee = F1 + f2

F1 := student[changevar](t=x, student[changevar](t=1/x, f1, t), x);

Int(sin((1/x-x)^5)^3*x, x = 1 .. infinity)

# ee = F1a + f2

F1a := Int(subs(x=-x,op(1,F1)), op(2,F1));

Int(-sin((x-1/x)^5)^3*x, x = 1 .. infinity)

# Last was ok (even)
simplify(F1 - F1a);

0

# ee = EE = F1a + f2

EE := frontend(combine, [F1a+f2], [{`+`,specfunc(Int)},{}]);

Int(-sin((x-1/x)^5)^3*x+sin((x-1/x)^5)^3/x^3, x = 1 .. infinity)

# ee equals EEa

EEa := simplify(student[changevar](u=x-1/x, EE, u));

Int(-sin(u^5)^3*u, u = 0 .. infinity)

# ee equals EEb

EEb := student[changevar](w=u^5, EEa, w);

Int(-(1/5)*sin(w)^3/w^(3/5), w = 0 .. infinity)

func := Int(op(1,EEb), w=2*k*Pi..(2*k+2)*Pi);

Int(-(1/5)*sin(w)^3/w^(3/5), w = 2*k*Pi .. (2*k+2)*Pi)

# ee equals add(func, k=0..infinity))

add(func, k=0..2); # you get the idea...

Int(-(1/5)*sin(w)^3/w^(3/5), w = 0 .. 2*Pi)+Int(-(1/5)*sin(w)^3/w^(3/5), w = 2*Pi .. 4*Pi)+Int(-(1/5)*sin(w)^3/w^(3/5), w = 4*Pi .. 6*Pi)

# evalf(ee) equals evalf(Sum(func, k=0..infinity)))

evalf[15](Sum(func, k=0..infinity));

-.153562126953523

 


Download mk1.mw

acer

SFloat@op seems to work even if UseHardwareFloats=true.

> restart:

> t := HFloat(1.00000000000002):

> lprint(t);
HFloat(1.00000000000001998)

> (SFloat@op)(t);

                             1.00000000000001998

> lprint(%);
1.00000000000001998

> evalf((SFloat@op)(t));

                                 1.000000000
> restart:

> UseHardwareFloats:=true:

> t := HFloat(1.00000000000002):

> lprint(t);
HFloat(1.00000000000001998)

> (SFloat@op)(t);

                             1.00000000000001998

> lprint(%);
1.00000000000001998

> evalf((SFloat@op)(t));

                                 1.000000000

acer

AFAIK the text in a TextArea component doesn't have any Character or Paragraph style associated with it.

Combined with it not being a property of the component, this all indicates to me that it probably can't be done.

I recall resorting to marked up text at some time in the past, to get colored, bold text inside a MathContainer component.

acer

Is the list L below the kind of thing that you want?

restart:

f := (x) -> (310*(x+0.5)^0.2)+70:

z := [ -0.5, 0.5 ]:

P1 := plot( f, z[1]..z[2], view=-100..400 ):

P1;

L := [ seq( z[2]-(z[2]-z[1])/(50/(51-i))^(3), i=1..50 ) ];

# The entries of L are getting successively closer together.
#
seq( L[i+1]-L[i], i=1..49 );

P2 := plots:-pointplot( [ seq( [t,f(t)], t=L ) ], view=0..400, symbolsize=15 ):

plots:-display( P1, P2 );

# Or, do you need to ensure that
#    abs(f(L[i+1])-f(L[i])) < abs(f(L[i])-f(L[i-1]))
# ?
# That happens to be the case for your f. The successive
# abs(f(L[i+1])-f(L[i])) are decreasing.
#
plots:-listplot( [ seq( abs(f(L[i+1])-f(L[i])), i=1..49 ) ] );

Or do you want the reverse, with the L[i] or f(L[i]) becoming closer toward the left?

Or do you just want the L[i] taken uniformly over -0.5 .. 0.5, including end-points, where for your particular f it happens that abs(f(L[i+1])-f(L[i])) is decreasing?

restart:

f := (x) -> (310*(x+0.5)^0.2)+70:

z := [ -0.5, 0.5 ]:

L := [ seq( z[1] + (i-1)*(z[2]-z[1])/(50-1), i=1..50 ) ];

[ seq( abs(f(L[i+1])-f(L[i])), i=1..49 ) ];

plots:-listplot( [ seq( abs(f(L[i+1])-f(L[i])), i=1..49 ) ] );

plots:-display(
  plots:-pointplot( [ seq( [t,f(t)], t=L ) ], view=0..400, symbolsize=15 ),
  plot( f, z[1]..z[2], view=-100..400 ) );

Sorry that I'm finding your explanation difficult to read.

acer

First 223 224 225 226 227 228 229 Last Page 225 of 336