pagan

5147 Reputation

23 Badges

17 years, 124 days

 

 

"A map that tried to pin down a sheep trail was just credible,

 but it was an optimistic map that tried to fix a the path made by the wind,

 or a path made across the grass by the shadow of flying birds."

                                                                 - _A Walk through H_, Peter Greenaway

 

MaplePrimes Activity


These are answers submitted by pagan

Use Pi not pi in the integrand as well as in the range.

Otherwise you'll get Pi/pi which is not 1 (since Maple doesn't know anything about lowercase pi).

Have you looked at ?define

Alternatives include defining "by hand" your procedure to examine its arguments and behave accordingly. The `define` facility is indended as a shortcut syntax for this. (You can also try option overload with such a construction.) This can help if you find that `define` is not up to your particular needs.

As an illustration, consider what `define` does in the following example.

restart;

define( f, 'linear');

# Now example `f`
interface(verboseproc=3):
eval(f);

Have a look at the surfdata command in the `plots` package.

Unlike `matrixplot`, the `surfdata` command has easy control (without resorting to manually specified tickmarks) of the axis values and view ranges.

I didn't understand whether you already have set numeric values for those unknowns, or want a "formula".

If you want a formula, then note that the unevaluated call to the `argument` routine is also useful.

expr:=(1-exp(-r/d)*exp(-I*w*r))*exp(I*w*t)*exp(-t/d);
sol1 := argument(expr) assuming real, r>0, d>0, t>0; # unevaluated return is still useful
eval(sol1,[w=-5,t=5/3,r=7/11,d=13/17]); evalf(%);
sol2:=arctan(Im(expr),Re(expr)) assuming real, r>0, d>0, t>0;
eval(sol2,[w=-5,t=5/3,r=7/11,d=13/17]); evalf(%);

Note the difference between arctan(a,b) and arctan(a/b), ie. try both with w=-5 and the data above, and compare with the correct value.

Take MM as your (symmetric) listlist which contains unknown z. Then Matrix(MM) is a 7x7 Matrix.

The characteristic polynomial of Matrix(MM) is a seventh degree polynomial in z.

That polynomial doesn't seem to have an explicit set of roots. So its roots can be had in implicit RootOf form, but not explicitly. If this is in fact true, then how would you get the eigenvalues explictly? And if the eigenvalues are not to be had explicltly, then how to get the eigenvectors explicitly?

MM:=[[200, -96, 5, -4.4, 4.7, -12.6, -6.2], [-96, 320, 33.1, 6.8, 4.5, 7.4, -.3],
[5, 33.1, z, -51.1, .8, -8.4, 7.6], [-4.4, 6.8, -51.1, 110, -76.6, -14.2, -67],
[4.7, 4.5, .8, -76.6, 270, 78.3, -.1], [-12.6, 7.4, -8.4, -14.2, 78.3, 420, 38.3],
[-6.2, -.3, 7.6, -67, -.1, 38.3, 230]]:

LinearAlgebra:-CharacteristicPolynomial(Matrix(MM),lambda);
13 12 5
-8.950780412 10 z + 7.93096068 10 lambda + 1550 z lambda

12 2 12
- 2.700616439 10 lambda + 3.393120176 10 z lambda

10 2 8 3
- 4.521945010 10 z lambda + 2.873617697 10 z lambda

5 4 10 3
- 9.4516802 10 z lambda + 4.243538104 10 lambda

8 4 5 5
- 2.820477172 10 lambda + 9.4130724 10 lambda

6 15 6 7
- 1550 lambda + 3.624330029 10 - z lambda + lambda

You can, however, obtain a procedure which given some numeric float input for z (ie. on demand) would calculate the purely numeric eigenvectors.

evecs:=Z->LinearAlgebra:-Eigenvectors(subs(z=Z,Matrix(MM,shape=symmetric)));

evecs(2.3);

Is that sufficient for your needs? If not, then what is it that you want to do with some explicit representation of the eigensolution involing unknown z? I mean, what would you want to do with something like the result of this?

linalg[eigenvects](convert(MM,rational),implicit);
Student:-Calculus1:-Roots(cos(t)=tan(t), t=0..2*Pi);

Student:-Calculus1:-Roots(cos(t)=tan(t), t=0..2*Pi, numeric);

plot(cos(t)-tan(t), t=0..2*Pi, discont=true, view=-1..1);

You can use the "Equation Manipulator" assistant to solve it (yourself) in an applet, and then have that applet return the "steps". I understand that this is not what you asked: to have Maple solve the thing. But I'll mention it anyway.

The returned steps represent how it could be done in Maple as basic step-by-step commands.

It'd return something like this:

ContextMenu:-Interactive:-Equation(x+y+sqrt(x^2+y^2)=24);

              "E := x+y+(x^2+y^2)^(1/2) = 24;

                E0 := (E) + (-24);

                E1 := (E0) + (-(x^2+y^2)^(1/2));

                E2 := lhs(E1)^2 = rhs(E1)^2;

                E3 := (expand)(lhs(E2)) = rhs(E2);

                E4 := (E3) + (-x^2);

                E5 := (E4) + (48*y);

                E6 := (E5) + (-576);

                E7 := (E6) + (-y^2);

                E0 := (E7) * (1/x);

                E1 := (expand)(lhs(E0)) = rhs(E0);

                E2 := (E1) * (1/(2*y-48));

                E3 := (E2) * (x);"

When satisfied with the final state of the equation, you can click the button on the appet marked "Return Steps". You can cut and paste what's inside those quotes (excepting the quote marks).

The assistant is also available from Tools->Assistants on the main menubar.

As you can see, it's a little crude. Normally I would have collected w.r.t `x`, near the end. But it gets slightly messier in the applet with commands like collect(...,x) which require two arguments. So I did that divide-by-x and then later the multiply-by-x. The command that the assistant would have accepted would look something like (t -> collect(t,x)) which would result in a step like this (but with different Exx equation numbers)

E130 := (t -> collect(t,x))(lhs(E21)) = rhs(E21);

The routine `genmatrix` is an export of the `linalg` package. You have to let Maple know that you want the `genmatrix` from `linalg` (and not a routine from some other package, or one that you created yourself, etc).

By the way, `linalg` is deprecated. The newer LinearAlgebra package is recommended.

> eqnlist := [x+2*y+3*z=4, x+k*y+4*z=6, x+2*y+(k+2)*z=6];

      eqnlist := [x + 2 y + 3 z = 4, x + k y + 4 z = 6, x + 2 y + (k + 2) z = 6]

> varlist := [x, y, z];

                            varlist := [x, y, z]

> LinearAlgebra[GenerateMatrix](eqnlist,varlist,augmented);

                              [1  2    3    4]
                              [              ]
                              [1  k    4    6]
                              [              ]
                              [1  2  k + 2  6]

> linalg[genmatrix](eqnlist,varlist,flag);

                              [1  2    3    4]
                              [              ]
                              [1  k    4    6]
                              [              ]
                              [1  2  k + 2  6]

An alternative method is to "load" the package (which you'd typically do just the once). This rebinds the routines names to their short forms, so that you can use a shorter syntax.

> with(LinearAlgebra):

> GenerateMatrix(eqnlist,varlist,augmented);

                              [1  2    3    4]
                              [              ]
                              [1  k    4    6]
                              [              ]
                              [1  2  k + 2  6]

See also ?UsingPackages

@tnmnhnguyen How about this

Maplets:-Elements:-Evaluate('ML'='eval(TF2,x=TF1)')

The idea is to delay, and prevent the `eval` action from occuring when the Maplet's pieces are created. Instead, you want it to occur only when that `Evaluate` call runs (and by which time TF1 and TF2 may have their values, etc...).

I couldn't see what you wanted to happen at the [m+1,m] entry, ie, to have it be either 0 or a(m+1).

G := m -> Matrix(m+1,scan=band[1,1],
                 [[seq(a(i),i=1..m-1),0],
                  [1,seq(b(i),i=1..m-1),1],
                  [0,seq(c(i),i=1..m-1)]]
                 ):

G(4);
                       [ 1     0     0     0     0  ]
                       [                            ]
                       [a(1)  b(1)  c(1)   0     0  ]
                       [                            ]
                       [ 0    a(2)  b(2)  c(2)   0  ]
                       [                            ]
                       [ 0     0    a(3)  b(3)  c(3)]
                       [                            ]
                       [ 0     0     0     0     1  ]

H := m-> Matrix(m+1,
       (i,j)->`if`(i=j,`if`(i=1 or i=m+1,1,b(i-1)),
                       `if`(i=j+1,`if`(i=m+1,0,a(i-1)),
                                  `if`(i=j-1,`if`(i=1,0,c(i-1)),0)))):

H(4);
                       [ 1     0     0     0     0  ]
                       [                            ]
                       [a(1)  b(1)  c(1)   0     0  ]
                       [                            ]
                       [ 0    a(2)  b(2)  c(2)   0  ]
                       [                            ]
                       [ 0     0    a(3)  b(3)  c(3)]
                       [                            ]
                       [ 0     0     0     0     1  ]

There are other variations, including using `piecewise`.

Put explicit multiplication signs between the `a` and the `(`, in two instances.

For example,

   {r1 = a*(1-e^2)/(1+e*cos(v1)), r2 = a*(1-e^2)/(1+e*cos(v2))}

The Student:-Calculus1:-Roots command with its 'numeric' option is (at present, mostly just) a fancy front end to repeated fsolve calls with its 'avoid' option.

> expr:=arctan(x)-4*x/(1+x^2):

> Student:-Calculus1:-Roots(expr, x=-10..10, numeric);

                [-2.886426944, 0., 2.886426944]

As for the 4*arctan(x)-4*x/(1+x^2)

Student:-Calculus1:-Roots(4*arctan(x)-4*x/(1+x^2), x=-10..10, numeric);

                              [0.]

> fsolve(4*arctan(x)-4*x/(1+x^2),x=-13..17);

                               0.

Sure, convergence of some methods may be less than usual for higher order roots. (Some methods may even get stuck.)

This question comes up a lot.

The plot only gets actually pushed to the plot driver if the system is supposed to print it out somehow. But only the return value of a proc is usually printed, and in your case that means the final line of the proc. When the plots:-display() call is not the the return value, then the generated plot structure is not printed and goes to the bit bucket.

You can have both effects, if you put a print() call around that display() call. That way, it gets printed even if it's not the return value of the proc (including as the last line). If you do that then you should be able to retain your last line which reinstates the old plotsetup.

ps. You seem to have issued with(plots): beforehand, outside the proc body. Better is to have the long form names such as plots:-display(...) inside your proc, or uses plots; at the top of the proc body.

The meaning of "limiting number of function evaluations reached" is that the solver has reached the number of evaluations of the obective function that it is allowed to do. You can try and remedy that situation by raising the evaluation limit. By lowering the limit of the number of objective functional evaluations to a trivially small number like 10, you yourself prevent the solver from having a practical chance of succeeding.

Why would you want to limit the solver to only 10 functional evaluations? Such a small limiting number would usually really hamper that method from attaining a decent estimate of the extremum. Did you say that each individual functional evaluation takes 30 seconds? (Why is that? Could you upload it, so other may try to speed it up?) What's wrong with waiting for 50 evaluations (the nonlinearsimplex method's default) which would total about 1500s? Do you need to repeat this whole process many times, and have it be fast?

How can optimization be much faster, for an objective that might take 30sec for each point? Nelder-Mead 'nonlinearsimplex" is not a specially fast method. Another method might be faster, if the numerical derivatives could be calculated more quickly than at present.

If the objective is thread-safe then it might be possible to compute the numerical derivatives faster. Derivatives may be estimated numerically using finite differences. But a finite difference scheme simply involves evaluation at a collection of different prescribed points. If the objective is thread-safe then the individual objective functional evaluation at points used for the finite difference scheme may be computed in parallel. So, instead of using fdiff or evalf(D(...)) to compute derivatives numerically, you could use a customized procedure which used the Threads package.

I'd consider trying to speed up the objective or parallelize the numerical derivative computation (if thread-safe).

> restart:

> sum(piecewise((n/p)::odd, 1, 0), n=1..nn);
Error, (in type/polynom) too many levels of recursion

Is `nn` known? Do you hope for the symbolic summation involving `sum` to succeed? Or would you be satisfied with an inert Sum expression which you could subsequently evaluate at known nn and p? And how about resolving what p is, so that (n/p)::odd doesn't fail and incur a division by zero when the (1-n^2) term in the denominator evaluates at n=1?

I don't understand why you use operators, if you're just going to invoke it as a function call like u1(r,theta) and then call `diff`. I may misunderstand your purpose, but why not use expressions? And could you not roll these particular nested piecewises together? I mean something like this, perhaps

restart:
M:=((4*Br)/(mu0*Pi*(n/p)))*sin((Pi/2)*(n/p)):
W:=piecewise(And(n::integer,(n/p)::odd),(M*r)/(mu1*(1-n^2)),0):
Sum((r^n*AI[n]+r^(-n)*BI[n]+W*sin(n*theta0))*sin(n*theta)+(r^n*CI[n]+r^(-n)*DI[n]
    +W*cos(n*theta0)*cos(n*theta)),n = 1 .. nn):
Q:=diff(%,r);
value(subs(p=2,Q)); # not much hope?
eval(subs(Sum=add,nn=3,p=2,Q));

Let us know, if that's altogether inadequate. It's not clear what you intend to do with the result, or whether you hope for a closed form from the symbolic sum.

First 18 19 20 21 22 23 24 Last Page 20 of 48