acer

32313 Reputation

29 Badges

19 years, 314 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Don't use square-brackets or curly braces as delimiters. They are for other things (creating lists and sets, respectively).

You have an expression, not an equation. Perhaps you implicitly consider it to be equal to zero.

The_equation := -(u+delta)*(1-c)*(c-c2h-t)+(1-u)/(1-q^2)/(4-q^2)^2*((2-q^2)*(theta-c2l-t)
                -q*(1-c))^2-(1-u)*(1-q^2)*(1/(4-q^2)/(1-q^2)*(2-q^2)*(theta-c2h-t)-q*(1-c))^2;

new_eq := eval(The_equation,[c2l=1/2,delta=1/2,q=1/2,theta=1/2,u=1/2]);

plots:-implicitplot3d(new_eq,t=0..10,c=0..1,c2h=0..1,axes=boxed);

Alternatively, you could try to isolate new_eq (using solve or isolate) for one of c, c2h, or t in terms of the other two and then use simply plot3d.

acer

Note the full colon in the end do:

for i from 1 to 3 do
   something:=19;
   print(plot(sin(i*x)));
   somethingelse:=13;
end do:

acer

You might consider using a Worksheet rather than a Document for prototyping longer  or more involved bits of code. (I mean, purely computational parts.) Then you can see it all explicitly. You might even consider using 1D input rather than typset 2D Math for any such algorithmic development work. Once working to your satisfaction you might then copy into code-edit or start-up regions of another Document. (And if you plan on re-using such code in multiple Documents, you might consider looking at saving some of your routines to Library archives.)

One thing to be wary of, in either Worksheet or Document, is executing sections or lines out of order. Just because the GUI allows one to go back to an earlier line, to tweak a formula, etc, doesn't mean that doing so is always prudent. Other lines which depend on the given line can get "out of sync" by such actions. (It's not so obvious, but this is another reason why using customized procedures is often much better than laying out lots of "top-level" code.)

acer

If only one feasible point is wanted, then the following can be quick,

> eqs:={20<=a,a<=60, 20<=b,b<=60, 20<=c, c<=60,
>       20<=d,d<=60, a+b+c+d=160, 4*a+6*b+8*c+12*d=1200}:

> Optimization:-Minimize(1,eqs,assume=integer);
                     [1, [a = 40, b = 40, c = 40, d = 40]]
 
> eval(eqs,%[2]);
                 {160 = 160, 1200 = 1200, 20 <= 40, 40 <= 60}

If you want to characterize all the solution space, and can wait, then the following might do,

SolveTools:-Inequality:-LinearMultivariateSystem(eqs,[a,b,c,d]);

acer

Note, when you say "simplify units in 2D math" it appears that you actually mean simplify units using the context-menus.

1) After executing the assignment to m1, and right-clicking, I did get the Units submenu in the pop-up context-menus. (Unfortunately in Maple 13 applying the Units->Simplify menu-item produces new 2D Math output 2*Unit(kg) instead of the properly typeset 2*[[kg]] as it did in Maple 12. A bug.)

2) For the equation F=m1*a the context-menu system is not providing Units->Simplify. I suspect that this is because it is only coded to detect an algebraic object (with units). It would indeed be an improvement, if it also detected an equation where either rhs or lhs had units attached.

3) If you have assigned to symbol m then you can indeed unassign by issuing either of these commands (as you tried, and where in fact that unassignment succeeded).

> m := 'm':

> unassign('m');

The 1D Math input command Unit('m') should work even when symbol m has been assigned a value. One combination that does not seem to work is using the [[m]] palette entry in a Document following assignment to the global name m.

But one can still get the nicely typeset [['m']] as 2D Math with the quoted name 'm' in the input by using command-completion. That will display as [[m]] in the output, without quotes. Suppose that I type in 45*Unit<Ctl-shift-spacebar> to get command completion suggestions in a pop-up. I choose "unit" which is the top suggestion. Then for the highlighted x I type in 'm'.

Note. The exact keystrokes to get command-completion suggestions may vary with platform. On Linux, I used Ctl-shift-spacebar.

You tried to use Units:-Natural at one point. I strongly advise against this. That subpackage's environment makes all these namespace issues much worse. Also, another reason it didn't work for you because your Document restarts after loading that package. The restart clears whatever packages are loaded.

4a) I don't understand what you mean about "a value included in the numerator", sorry.

4b) To separate an expression and its units, one can use the command convert,unit_free. It may be appropriate to first apply combine,units. For example,

> restart:
> F := 45*Unit(kg)*Unit(m)/Unit(s^2);
                                    45 [m]
                               F := ------ [kg]
                                     [ 2]
                                     [s ]
 
> F_value := convert(combine(F,units),unit_free,F_units);
                                 F_value := 45
 
> F_units;
                                      [N]

Note. You might consider loading the Units:-Standard package, which would bring about some automatic combining & simplification of units for arithmetic done at the top-level. Even if you choose not to load that package, there are commands to manipulate several aspects of the units in expression, which might serve even when the smaller subset of functionality in the right-click context-menus isn't working out for you.

acer

You'll need to compile and link as .dll (or .so on Linux, etc).

See define_external and related help.

acer

with(Statistics):
oldpb:=kernelopts(printbytes=false):
to 4 do
  r:=evalf(Sample(RandomVariable(Normal(0,1)),1)[1],1);
  print(r); # or DocumentTools:-Do
  st:=time[real]();
  while time[real]()-st < 2 do end do;
  end do:
kernelopts(printbytes=oldpb):

acer

Do you mean this sort of forced rearrangement, of a set of equations? 

> problematic_set:={qk2=5,qk1=17,qk3=13};
               problematic_set := {qk1 = 17, qk2 = 5, qk3 = 13}

> my_forced_order:=eval([qk3,qk2,qk1],problematic_set);
                        my_forced_order := [13, 5, 17]

> my_forced_order:=[seq(eval(qk||(4-i),problematic_set),i=1..3)];
                        my_forced_order := [13, 5, 17]

> my_forced_order:=[seq(qk||(4-i)=eval(qk||(4-i),problematic_set),i=1..3)];
               my_forced_order := [qk3 = 13, qk2 = 5, qk1 = 17]

acer

Maybe something like this?

> f := (x,y) -> cos(x+y): # or more complicated

> g:=(a,b)->a^2+b^2: # or more complicated

> F := y->(fsolve(f(x,y),x=0..1/2),y): # returns x,y pair

> F(1.4);
                               0.1707963268, 1.4

> f(%); # should show that last was a zero of f
                                              -9
                              -0.2051033808 10

> plot(g@F, 1.1..1.6);

You might also check out transforming the implicit plot of f.

> k:=plottools:-transform((a,b)->[b,g(a,b)]):
> P1:=plots:-implicitplot(f,0..1/2,1.1..1.6):
> plots:-display(k(P1));

> # ...or, as function of first value (as you asked, I think)

> k:=plottools:-transform((a,b)->[a,g(a,b)]):
> plots:-display(k(P1));

> FF := x->(x,fsolve(f(x,y),y=0..3)): # returns x,y pair
> FF(0.2);
                               0.2, 1.370796327

> f(%);
                                              -9
                              -0.2051033808 10

> plot(g@FF, 0..0.5);

acer

Change the lowercase int() calls to Int(). That should be enough to allow plot to use numerical quadrature instead of churning away on symbolic integration at each x-y pair.

You said that you had a function f(x,y), but it looks like an expression. Hopefully, any such discrepency will be sorted by you.

acer

It's difficult to answer this well, without knowing what your code does. You may need to paste or upload an example of it going wrong for you.

Some advice can still be given:

  • Vector() is different from vector().
  • evalm() is not appropriate for uppercase Vector or Matrix.
  • A+B should work directly for Vectors A and B. (It's a shortcut to LinearAlgebra:-VectorAdd.)
  • row Vectors are different from column Vectors.

The error message "invalid arguments" from rtable/Sum arises when one attempts to add mismatched objects. For example,

> V1:=Vector(2):
> V2:=Vector(5):
> V3:=Vector[row](2):
> M:=Matrix(1..2,1):

> V1+V2: # size mismatch
Error, (in rtable/Sum) invalid arguments
> V1+V2[1..2]:  # ok

> V1+V3: # orientation mismatch
Error, (in rtable/Sum) invalid arguments
> V1+V3^%T:  # ok

> V1+M: # object mismatch
Error, (in rtable/Sum) invalid arguments
> V1+convert(M,Vector): # ok

Did I see you using Statistics in another post? It produces row Vectors, while the default for the Vector() constructor is column vectors. Perhaps that is your issue.

> with(Statistics):
> V := Sample(Normal(0,1),2);
              V := [-0.479341933636560025, 0.784173699733298979]
 
> op(0,V);
                                  Vector[row]
 
> type(V,'Vector[column]');
                                     false
 
> type(V,'Vector[row]');
                                     true
 
> type(V,'Vector');
                                     true
 
> V + Vector(2,[a,b]);  # orientation mismatch
Error, (in rtable/Sum) invalid arguments

> V + Vector(2)^%T;  # transpose either, to match
                 [-0.479341933636560025, 0.784173699733298979]
 
> with(LinearAlgebra):
> V + Transpose(Vector(2));  # transpose either, to match
                 [-0.479341933636560025, 0.784173699733298979]

acer

> E := t* (1-exp(-(1-t)^2/(2*o^2))):

> f := oo -> Optimization:-Maximize(eval(E,o=oo),t=0..1)[1]:

> # test it first
> f(0.5);
                             0.205693857126463153
 
> eval(E,o=1/2);
                                                2
                           t (1 - exp(-2 (1 - t) ))
 
> Optimization:-Maximize(%,t=0..1);
              [0.205693857126463153, [t = 0.417189146242829434]]

> # now plot it
> plot(f,0..1);

> # alternate way
> plot('Optimization:-Maximize'(E,t=0..1)[1], o=0..1);

acer

On 64bit Maple, 2^(2^65536) will produce a numeric exception (overflow). And B(4,1,4) is already on the order of 2^(2^(2^65536)). So what were you planning on doing with B(5,2,5)?

acer

This might be a reference to some of the Tutors in the Student[Calculus1] package. See the SingleStepOverview help-page.

For less structured but more verbose ways to see what Maple is doing, look at the help-pages for infolevel, trace, and printlevel.

acer

Are you just asking for a way to store a large Vector whose entries are precomputed points on the n-dimensional hypersphere? Would a point generator suffice, if it were fast enough? Do you want a completely even set of points, or a (statistical) uniform distribution? Can you go from here?

acer

First 296 297 298 299 300 301 302 Last Page 298 of 336