Carl Love

Carl Love

28025 Reputation

25 Badges

12 years, 311 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

You do it by using the identical type specifier, like this:

MyPlot:= proc(f::algebraic, {color::identical(yellow,organe,red,green):= red})
     print(color)
end proc;

In the above, I made red the default. If you don't want a default, then replace the red after the := with NULL. Note that Maple's procedure ProcessOptions is now largely obsolete. Most of what it handled can now be handled in the procedure header. See chapter 6 of the Programming Guide or the help page ?parameter_classes .

How about this?

F:= [sin(x), sin(x)-x+x^2, cos(x)-sin(x), exp(x)-x, sin(x)+exp(x)]:
plot(F, x= -Pi..Pi, linestyle= [1,2,3,4,5], legend= F);

Use a try...catch statement, like this:

V:= [a,b,c]:
for k to 6 do
     try
          print(V[k/2])
     catch "invalid subscript":
          print("There was an error, but the loop continues.")
     end try
end do;

@nm Use 1 instead of NULL. Being the identity, it won't change the product.

Addressing your original problem, your evalb was subject to premature evaluation. Note:

restart:
f:= i-> evalb(i<>j):
f(3);
          true

(of course). Since product has normal evaluation rules, the evalb being inside product will not change its evaluation. But mul has special evaluation rules, the same as add and seq. Those rules delay the evaluation of i<>j until after has numeric values.

A:= 2^(k+2)*m:
for r from 2 to M+1 do
     for s to r-1 do
          F[r,s]:= `if`((r+s)::odd, A*sqrt(c[r-1]/c[s-1]), 0)
     end do
end do:


restart:

h:= r-> 2*sqrt(100-r^2):

V:= r-> Pi*r^2*h(r):

Sol:= select(r-> is(r>0 and r<10), [solve(D(V)(r), r)]);

[(10/3)*6^(1/2)]

r:= Sol[]:

Second derivative test:

evalf((D@@2)(V)(r));

-435.311847416212

It's negative, so r is a maximum. The dimensions are

[radius= r, height= h(r)];

[radius = (10/3)*6^(1/2), height = (20/3)*3^(1/2)]

evalf(%);

[radius = 8.16496580927726, height = 11.5470053837925]

P1:= plot3d([10, theta, phi], theta= 0..2*Pi, phi= 0..Pi, coords= spherical, transparency= 0.5):

P2:= plot3d([r, theta, z], theta= 0..2*Pi, z= -h(r)/2..h(r)/2, coords= cylindrical, color= yellow, style= patchnogrid):

plots:-display([P1,P2]);

 


Download cylinder_in_sphere.mw

No, ShowSolution does not make much progress with this integral. The trick for this integral is to apply a trigonometric identity for sin(a)*sin(b). The command combine applies this automatically.

J:= Int(sin(k*(t-tau))*sin(k*tau), tau= 0..t);

State the identity, for the record:

sin(a)*sin(b):  % = combine(%);

Apply it to the integral:

combine(J);

I'll assume that you know the steps to finish the integral from there. If not, let me know.

Int is the inert form of Maple's integration command. The active form is int.

expr2 := sin(k*(t-tau))*sin(k*tau);
int(simplify(expr2, symbolic), tau = 0 .. t);

If A and B are the two matrices, then do LinearAlgebra:-Equal(A,B).

Multiple plots can be made by making the first argument to plot a sequence of functions. I find this easier than using plots:-multiple.

N:= 10: #Number of plots.
plot(
     [seq(s(i), i= 0..N-1)], x= -10..10, y= -1..1,
     color= [seq(COLOR(HUE, .85*i/N), i= 0..N-1)]
);

The colors are set to proceed through the standard color spectrum, from red to violet. (The horrible staggered rendering in the plot below is the fault of MaplePrimes (this forum); the plot appears much smoother in Maple itself.)

There are two ways to handle this. The first way involves checking mathematically whether the modular inverse exists before trying to compute it. The second way is to trap the error.

The mathematical way: For integers a, b with b > 1, the modular inverse 1/a mod b exists iff a and b are relatively prime. In Maple, we check that igcd(a,b) = 1. I'll assume that you never have a ridiculous situation such as b=0 or b=1; so I won't check for those.

for i to s1 do
     for c2 to 15 do
          if
               igcd(H+1, A[i]) = 1 and
               `mod`(c2+(J+H)*(`mod`(1/(H+1), A[i])), A[i]) = 0
          then
               d[c2]:= d[c2]+l(A[i])
          end if
     end do
end do;

If the first part of an and clause evaluates to false, then the second part is never evaluated or executed. That's why the above code is safe.

The lazy error-trapping way: This requires using the Maple statement try/catch.

for i to s1 do
     for c2 to 15 do
          try
               if `mod`(c2+(J+H)*(`mod`(1/(H+1), A[i])), A[i]) = 0 then
                    d[c2]:= d[c2]+l(A[i])
               end if
          catch "the modular inverse":
               #Ignore the error; don't change d[c2].
          end try
     end do
end do;

In both cases I've assumed that you intended l(A[i]) to represent a function (or procedure) call to a function named l. If you actually intended multiplication then you need to make that l*A[i].

Note that p/q mod b may exist even though 1/q mod a does not. In light of this you may wish to extend the domain of your computation (and simplify the code) thus:

for i to s1 do
     for c2 to 15 do
          try
               if c2+(J+H)/(H+1) mod A[i] = 0 then
                    d[c2]:= d[c2]+l(A[i])
               end if
          catch "the modular inverse":
               #Ignore the error; don't change d[c2].
          end try
     end do
end do;

 

This is an oft-reported bug with curves in 3d plots that only affects some users. A workaround is to include linestyle= solid in the plot command.

plots:-contourplot3d(-5*x/(x^2+y^2+1), x= -3..3, y= -3..3, filledregions, linestyle= solid);

plot3d(-5*x/(x^2+y^2+1), x= -3..3, y= -3..3, style= contour, contours= 6, linestyle= solid);

assign(seq(seq(psi[4*(i-1)+j+1]= psi[i,j], i= 1..2), j= 0..3));

type(z1, specfunc(anything, `.`));

                               true

or

type(z1, ('`.`')(anything, anything));

                               true

You should clearly state the question. Is it to maximize the profit (or minimize the loss)? Is it to find the break-even point?

I think that there's missing information from your problem, or that you are mixing units incorrectly (such as dollars and cents). I think that because, as stated, the problem does not have a positive real solution.

price:= x-> 50-x:
Cost:= x-> 120+30*x:
Profit:= x-> x*price(x) - Cost(x):
maximize(Profit(x), location);

So the minimal loss is $20 at a production of 10 units and a price of 50 - 10 = $40.

First 285 286 287 288 289 290 291 Last Page 287 of 395