acer

32363 Reputation

29 Badges

19 years, 332 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Those should be single left quotes in that call to lprint, but you appear to have them as single right quotes.

You could also do the printing by using printf instead of lprint, ie, replace

lprint(r1, `=`, q, `*`, r2, `+`, r3);

by, say,

printf("%a = %a * %a + %a\n", r1,q,r2,r3);

acer

restart:

MyHandler := proc(operator,operands,default_value)
   NumericStatus( division_by_zero = false );
   return infinity;
end proc:

NumericEventHandler(division_by_zero=MyHandler):

for i in {1, 2/0, -3, 1/4, 5} do
if i::posint then print(i)  fi;
od;

                               1
                               5

select(x->is(x::posint), {1, 2/0, -3, 1/4, 5});

                             {1, 5}

acer

So, something like this?

restart:

lambda0:=PL-R3*x:
Psi0:=PL+R3*S0*(R1-1)-R1*R3*x:
S0:=(Q-1)/Q:

P:=piecewise(x<S0,lambda0,x>S0,Psi0):

plot3d(eval(P,[R3=-5,k=4,R1=0.0006,Q=1.2]),x=0..1,PL=0..1,labels=[x,PL,'P']);

acer

You could try simplification with side relations, ie, see ?simplify,siderels

restart:

ee:=-1/4*m*omega*sin(1/2*omega*T)*(2*cos(1/2*omega*T)^2*xa^2      
    +2*cos(1/2*omega*T)^2*xb^2-xa^2-2*xa*xb-xb^2)/                
    (cos(1/2*omega*T)^2-1)/cos(1/2*omega*T):                      

EE:=simplify(combine(simplify(simplify(ee,                        
             {cos(omega*T/2)^2-1=-sin(omega*T/2)^2}),size)),size);

                                  2     2
                      omega m ((xa  + xb ) cos(omega T) - 2 xa xb)
            EE := 1/2 --------------------------------------------
                                      sin(omega T)

length(ee), length(EE);

                                   247, 113

acer

It's not clear to me whether you also want to keep the collection of scalar products by assigning that to some variable name, or whether you are just interested in the final sum. Below, I presume the latter, but let us know if that's not the case.

If you are asking how to sum all the entries of the elementwise product of Matrices A and B then there are several ways, including,

add(x, x in A*~B);

add(x, x in zip(`*`,A,B));

add( add( A[i,j]*B[i,j], i=1..N), j=1..N );

convert(A,Vector) . convert(B,Vector);

That last way above is slower for default datatype=anything Matrices but faster for datatype=float[8] Matrices.

acer

See the help-page for the interface command, and in particular the setting for warnlevel on thay page.

By invoking interface(warnlevel=1) or interface(warnlevel=0) the warnings about implicitly declared locals should be suppressed.

It's a better idea to declare your locals explicitly, rather than to suppress such warnings. If you leave them only implicitly declared then future readers of your code (a course instructor, colleague, or even you) may be left wondering whether you intended them as locals or as globals and whether your code functions as intended.

acer

You can comstruct an assembly of Embedded Components (Sliders, etc) which does this.

A worksheet with such components can also be run in the free MaplePlayer. Perhaps you can convince your administrator to allow the free player to be installed on the computer connected to the classroom's overhead projector.

One convenient way to construct such Embedded Components in Maple 17, as in your simple case, is to use the Explore command with the invocation shown below.

The attached worksheet looks better in Maple (than it does with its picture inlined into this Answer). It has three Sliders in its bottom half.

 

Explore( plots:-display(plottools:-circle([cx,cy],radius,color=red),
                        view=[-10..10,-10..10]),
         parameters=[cx=-10.0..10.0,cy=-10.0..10.0,radius=0.0..10.0],
         initialvalues=[cx=0.0,cy=0.0,radius=5.0] );

cx:

cy:

radius:

 

 

``

 

Download simplecircle.mw

 

The worksheet that uses Explore for Maple 17 is at the link above.

You could also build such a simple assembly by hand. It's very similar to some introductory examples on Embedded Components in the Help system. Here is one version as another attachment, in the link below. It's assembly of components was constructed by hand. This should run, as is, in Maple 17, 16,.. ,13, 12.

manualcircle.mw

acer

I'm not completely sure how your data is meant to be interpreted. Perhaps I've understood your intention, for what I show below.

I don't show how to obtain an interpolatory bivariate polynomial in the explicit sense. Instead I show how to create a procedure `f` which can be used to interpolate at any (x,y) point. Hence you should be able to call `f` at points of your own choice. I show how it can be used to produce a 3D plot, for example.

Is there a typo in your list `c`? Did you mean for its second entry to be -0.87 say?

(For some reason only the first portion of my attached worksheet is being inlined into this answer. Let me know if you cannot load and see the whole thing.)

restart:

a := [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:

b := [ 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001,
       0.011, 0.011, 0.011, 0.011, 0.011, 0.011, 0.011, 0.011, 0.011, 0.011]:

c := [ -0.88, -0.87, -0.86, -0.82, -0.77, -0.71, -0.66, -0.62, -0.57, -0.54,
       -0.89, -0.88, -0.85, -0.81, -0.76, -0.71, -0.66, -0.61, -0.57, -0.53]:

# It's convenient to use a slightly different form of the data.

A:=Vector(a[1..10]):
B:=Vector([b[1],b[11]]):
C:=LinearAlgebra:-Transpose(Matrix(2,10,c)):

plots:-surfdata(C, 1..10, 0.001..0.011,
                orientation=[-111,83,-14], labels=[x,y,z]);

# Create a procedure `f` which can interpolate at a given (x,y) point.

f:=proc(x,y,K::identical(cubic,linear,spline):=spline)
   if not type(x,numeric) and type(y,numeric) then
      return 'procname'(args);
   end if;
   CurveFitting:-ArrayInterpolation([A,B],C,Array([[[x,y]]]),
                                    'method'=K)[1,1];
end proc:

# We can visually compare the effects of various interpolation schemes.
# Note how the first plot differs from the other two.

plots:-display(Array([
   plot3d('f(x,y,linear)',x=1..10,y=0.001..0.011),
   plot3d('f(x,y,cubic)',x=1..10,y=0.001..0.011),
   plot3d('f(x,y,spline)',x=1..10,y=0.001..0.011)
                      ]),
               glossiness=0.2, lightmodel=Light1,
               orientation=[-111,83,-14]);

 

Download inter3dexample.mw

acer

I'm not sure whether this is coursework, and whether you are supposed to be able to show it manually (ie. without using Maple). If so, then you may be able to do these steps by hand.

restart:

# For posint N, you could try showing this manually.
b := Product(5^(1/2^k)+1, k=1..N) = Sum(5^((i-1)/(2^N)),i=1..2^N):

XN := 4/Product(5^(1/2^k)+1, k= 1..N);

                                         4          
                         XN := ---------------------
                                   N     / /1 \    \
                               ,--------'| |--|    |
                                  |  |   | | k|    |
                                  |  |   | \2 /    |
                                  |  |   \5     + 1/
                                  |  |              
                                 k = 1  
            
subs(b,XN);

                                     4       
                               --------------
                                  N          
                                 2    /i - 1\
                               -----  |-----|
                                \     |  N  |
                                 )    \ 2   /
                                /    5       
                               -----         
                               i = 1 
        
# But now that's just a simple geometric sum.
# You should be able to get the following without Maple.
simplify(value(%)) assuming N::posint;

                                 / (-N)\    
                                 \2    /    
                                5        - 1

x := eval(%, N=4);
                                    (1/16)    
                              x := 5       - 1

(%+1)^48;
                                     125

acer

restart:
en:=Sum((sqrt(a*k^3+b*k^2+c*k+1)-sqrt(a*k^3+b*k^2+c*k))^(1/3),k=0..n-1):

# First, find a,b,c

value(eval(en-sqrt(n),n=2)):
s2:=solve(%):
e2:=simplify(eval(en,s2)):
value(eval(e2-sqrt(n),n=3)):
s3:=simplify(solve(%)):
e3:=simplify(eval(e2,s3)):
value(eval(e3-sqrt(n),n=4)):
s4:=simplify(solve({%})):
sol:=solve(s2 union s3 union s4);
                    {a = 16, b = 24, c = 9}
Z:=eval(en,sol):

# And now, by induction, show true for all n::posint

value( eval(Z-sqrt(n),n=1) );

                               0

value( combine( (Z=sqrt(n)) - eval(Z=sqrt(n),n=n-1) ) ):
lhs(%)^3 - rhs(%)^3:
simplify(%) assuming n::posint, n>1;

                               0

acer

Unprotecting system names is very rarely a sound approach. If one is not crystal clear about how to do it, what it entails, or what the consequences might be, then it's often a bad idea.

In Maple 17 one can declare a local version of a name... at the top level! Ie, outside of any procedure. This allows a name such as gamma to be used in a variety of common and useful ways (eg. assigned to) without the need to unprotect and overwrite the global of the same name.

In the following code the global name `:-gamma` retains its original meaning, which can be very important. eg. in cases where the special meaning is intended when it occurs in the return value of some computation by the system.

restart:

local gamma;

gamma := 4;

                                 gamma := 4

evalf(gamma);

                                     4.

evalf(:-gamma);

                                0.5772156649

kernelopts(version);

          Maple 17.01, X86 64 WINDOWS, Jun 25 2013, Build ID 849430

I expect that there are wrinkles to be ironed out. But this looks like a step forward.

Does your data form a grid in the x-y plane? Or do you have only an irregular collection of x-y point pairs?

You could look at the following (which covers the case of a grid), here. The constructred procedure `B` can be used to compute f(X,Y) for any given X,Y point. It does not return a bivariate picewise polynomial (formula). But it is possible that you might not actually need a formulaic result, if you have a procedure such as `B` which can be polled at any arbitrary point (X,Y).

There is also an Example worksheet in the Maple help system or recent versions, under the topic examples,Interpolation_and_Smoothing (using underscore for the two spaces between words).

acer

To create a system which is like SI except that the dimension of "action" is given in terms of MeV*s you could try,

Units:-AddSystem('Accelerator',Units:-GetSystem('SI'),'MeV*second'); 
Units:-UseSystem('Accelerator');

You could compare the output of, say, simplify( Unit('h_bar') ) both with and without the above.

nb. You could also use ScientificConstants:-Constant('hbar') and test with ScientificConstants:-GetUnit(...) etc.

Your original definition of system 'Accelerator' associated units with the (separate, simple) dimensions of energy, length, and time, but not with others dimensions. In the call to `AddSystem` that I have above the new system 'Accelerator' comprises all that Maple understands for the 'SI' system as well as a new override for the dimension of action=energy*time.

I don't understand what you've written about contexts, sorry.

acer

Try the GenerateMatrix command in the LinearAlgebra package.

makefill:=(z1,z2,a,b)->plottools:-transform(
(x,y)->[x,y+z1])(plot(z2-z1,x=a..b,filled=true,thickness=0,_rest)):

plots:-display(makefill(2,5,-3,3,color=blue),view=0..10,gridlines=true);

Another way is,

plots:-display(plottools:-rectangle([-3,2],[3,5],color=blue,
thickness=0,transparency=0.35),view=0..10,gridlines=true);

With your original approach I don't see how you can make the white layer opaque so as to mask the underlying blue while still being transparent so as to not mask the underlying gridlines.

acer

First 247 248 249 250 251 252 253 Last Page 249 of 336