5127 Reputation

23 Badges

16 years, 59 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

You might also be interested in the syntax for producing an instance of the original Array in which some particular column or row has been replaced.

Using Markiyan's data,

B := Array(1..2,1..3,[[1, 2, 3],[4., 5., 6.4]]);

                                  [ 1   2    3]
                             B := [           ]
                                  [4.  5.  6.4]


                             [16., 25., 40.96]

B; # notice: unchanged

                                [ 1   2    3]
                                [           ]
                                [4.  5.  6.4]

BB:=copy(B): # or, use B itself if you want it changed in-place

                              [  1    2      3]
                              [               ]
                              [16.  25.  40.96]

As far as I can tell, using ArrayTools:-Alias does not give any easier way in which to map along a row of a Fortran_order 2D Array or Matrix (or, similarly, along a column of a C_order 2D Array or Matrix)

It might be nice if the RowOperation and ColumnOperation commands (or some new commands) could provide the functionality to easily update rows or columns of 2D rtables. For example it might be adjusted so that the current parameter `s`, now taken only as an expression, could be accepted as a procedure to apply to the relevent entries. Such rtable "iterators" could also be allowed for updating bands or diagonals.

Since in the end you're just evaluating numerically, using r=0.2, then there is not so much of a need to produce F(r) for a nonnumeric, symbolic `r` and then only afterwards evaluating at r=0.2. Also, your call to lowercase `int` with an integration range of x=0..`rob` for floating-point `rob` is going to eventually involve a numerical integration.

With that in mind, perhaps one easy way is to try doing it purely numerically. D(IN) will return unevaluated here, and evalf(D(IN)(value)) will call fdiff the numerical differentiator.

> ING := D(IN):

> evalf(ING(.2));

                    -0.6067953678 + 3.272366947 10    I

> # that small imaginary component is just due to numeric roundoff.
> # evaluating at higher working precision makes it more negligible.

> evalf[20](ING(.2));

            -0.60679536790134102510 - 5.3295064630932992395 10    I

> # we can remove the imaginary term (safely, ie. only if "small" enough)

> simplify(fnormal(evalf(ING(0.2))));


If you don't want to see tha small imaginary artefact, at all, then you could try changing your definition of IN.

> IN:=r->abs(F(r))^2/N;

                      r -> -------

> ING := D(IN):

> evalf(ING(.2));

Another reason for using that modified version of IN is that it only computes F(r) once, but your version computed it twice (not an actual problem here, as evalf/Int may store the first result in its remember table, but maybe good to realize and be aware of for some future example).

There are other ways to get the result, but you'd have to be careful if you use `diff`, including avoiding the error of having it try to differentiate w.r.t a number.

Part of the confusion here is the way in which you form `h`, `H`, `F`, and `IN` all as operators which call the previous one. And preassigning all those parameters with floating-point values, at the top of the sheet, does not help with that approach. Those two aspects of writing worksheets are extremely popular amongst new users, but in my opinion they both make it harder to use Maple effectively.

If you really wanted to compute IN(r) for symbolic `r` then you might have an easir time with it by using expressions instead of those unnecessary operators. (That's just my opinion.) On the other hand, if you only ever want to evaluate `IN` or its derivative at some actual floating-point numbers then using operators is OK, but in that case don't do things like eval(IN(r),r=0.2) which first calls IN at unassigned symbolic `r`.

Replace all the square brackets in equn1 with round brackets. Square brackets are for list construction. Round brackets are expression delimiters.



You are missing a multiplication sign between the bracketed terms (x+2) and (x-2)

You can still force the axis labels. Using your defn of x,

plot(x, t = -10*Unit(s) ..10*Unit(s),view=-10..50,labels=[t*Unit(s),'x'*Unit(m)]);

It opens ok using maple 15's Standard GUI (maplew.exe).

It looks like it might be a .mw worksheet which has been saved or uploaded with the wrong (.mws) filename extension.

So, your Windows thinks it should open it with the Classic GUI, but the Classic GUI doesn't understand it (because it is not actually.mws).

So you could just rename it, or open with the standard gui and save as .mw file.

fsolve may not have been satisfied that at the working precision it was not able to attain some tolerance. It's a flaw, that precision and tolerance are not separate for fsolve.

Using operators instead of expressions seems to use a weaker tolerance

ans:=fsolve({(lu,lv)->FDerivative2YYMain(lu,lv, 12.5)/(lv+12.5),
             (lu,lv)->FDerivative3YYYMain(lu,lv, 12.5)/(lv+12.5)},



                          -7.287 10  

                         5.34464 10   

That error message often means that the code has referenced a Matrix with indices which are names which do not evaluate to integer values. For example



Error, bad index into Matrix

The problem is that `i` was not an integer value (within the valid bounds range of just 1 to 1).

This can happen in a few ways. You might have a line of code where you intended `i` to have a value, but it actually didn't.

One common scenario is that the code calls `sum` and the first argument to the `sum` call is a formula containing things like u[i,j] say. Since `sum` does not have special evaluation rules Maple will try and evaluate u[i,j] before `i` and/or `j` the indices of summation get assigned any numeric values. And then bang. If that is your situation then try replacing calls to `sum`, for summing finitely many terms, by calls to `add` instead.

Now here is the best bit: in the Maple Standard GUI that error message is a hyperlink. If you follow its URL in a web browser then you will get to an Online help page which gives pretty much the same explanation.

The Compiler demands that local variables cannot have Array types, but your procedure references the entries of the locals E, V, and s as if they were 1-dimensional Arrays. Hence the procedure is doing something that the Compiler does not support.

Another way to say it is that local variables cannot be Arrays or Vector or Matrices, for the Compiler to accept the procedure. (And lists and sets and tables are not allowed, since Arrays, Vectors, and Matrices of hardware datatype are the indexable structures that the Compiler admits.)

If you read the help page Compiler you can see early on where it says, "Procedures that return arrays or allocate new arrays cannot be translated." That means that local variables cannot get new Array/Vector/Matrix assigned to them, inside the procedure.

The correct way to do what you are trying is to create all the Arrays outside of the procedure, and then to pass them in as arguments. This means locals V, E, s, and also your current global u.

It's then your choice whether to have the procedure continue to return s[Nr-1], or to just return NULL (since outside of procedure X you have access to the Array you pass in for argument s, and it gets updated in-place).

You should consider making the other globals into arguments too. Using globals when not necessary just leads to sloppy code with problems, IMNSHO. But also, for the Compiler it means callbacks to main Maple and conversions from software to hardware scalar types, and if that occurs inside a loop (not your situation here...) that can be costly (relative to compiled operations).

Also, if you are going to use the Compiler than give your procedure's arguments and locals the type information (using :: double-colon) the makes things unambiguous. Don't rely on the Compiler to magically guess that you intend on using this as a float and that as an integer, etc, because if deduced wrongly the code may compute wrongly through no fault of its own.

You'll have to choose appropriate ranges, eg, alpha=0.0 .. 1.0, and n=1.., etc, in the Explore pop-up window


K := proc (alpha, theta1, theta2, sigma, n::posint)
local t,beta,W;
uses Statistics;
t[alpha] := fsolve(CDF(RandomVariable(NormalDistribution(0, 1)), -t) = alpha, t);
beta := evalf(CDF(RandomVariable(NormalDistribution(0, 1)),
W := evalf(CDF(RandomVariable(NormalDistribution(0, 1)),
sprintf("alpha is %a, beta is %a, and W is %a", alpha,beta,W);
end proc:

K(0.5e-1, 0, .6, 1, 5);

  "alpha is .5e-1, beta is .6191361682, and W is .3808638318"


The methodology within K might be improved slightly. But that is incidental.

It looks like a regression bug.

Maple 12.02, 13.02, and 14.01 (32bit and 64bit) for Windows produces all three of these plots below correctly. But in Maple 15.01 (32bit and 64bit), the first two are produced incorrectly with either all x- or all y-values as zero. (The plot data structures contain the wrong zero-values. It's not just a GUI rendering thing.)







The notation of c'x for the objective is just shorthand for a Vector dot product. It's a scalar, the result of the dot product of the row Vector c' (ie. the transpose of column Vector c) and the column Vector x. The entries of Vector c are the numeric coefficients, and the Vector x are the as-yet-unknown variables. Hence c'x is a linear combination -- not surprising as we are talking about Linear Programming problems.

So, in Matrix form, the Vector x for you example will have as it entries all the w[i] as well as dr and ur. But since for your example the objective c'x is just the linear combination ur + dr = 0*w[1]+0*w[2]+...+0*w[50]+1.0*ur+1.0*dr then it is easy to see how to construct both c and x as Vectors.

The Vector c might be taken as Vector(52,i->`if`(i=51 or i=52, 1.0, 0.0))

The Vector x would then be taken as Vector(52,i->`if`(i=51,dr,`if`(i=52,ur,w[i])))

c:=Vector(52,i->`if`(i=51 or i=52, 1.0, 0.0)):

c^%T . x;
                        1.0 dr + 1.0 ur

It is trivial to adjust, for a maximation problem.

And now that you know what are the entries of the Vector x of unknowns, you can see the LPSolve Matrix form help page for how to set up the linear constraints and simple bounds.

If you are interested in efficiency, then use the syntax z[i,1] to access the entries of Matrix z, as the syntax z[i][1] is quite an inefficient way to get the same thing. When you invoke z[i][1] you force Maple to waste resources extracting z[i] (which is the i'th row of z) as a new Vector object whose transient existence serves only to have its first entry extracted. But the syntax z[i,1] extracts the first entry in the i'th row directly, as a mere scalar. So, one way forms a new Vector (which takes resources to form as well as to collect and dispose of as garbage) just to extract a single scalar entry, while the other method simply extracts that same desired scalar entry directly with no such addtional overhead.

Take notice that you cannot use `I` in that manner, unless you first switch the imaginaryunit. So I use II instead.


                   /         1 \             
                   |Ls + R + --| II(s) = V(s)
                   \         Cs/             

First, one of the simpler ways,


                      II(s) = -----------
                              Ls + R + --


                      II(s)        1     
                      ----- = -----------
                      V(s)             1 
                              Ls + R + --

which together are


                      II(s)        1     
                      ----- = -----------
                      V(s)             1 
                              Ls + R + --

Also possible here is


                               1    V(s) 
                      Ls + R + -- = -----
                               Cs   II(s)


                      II(s)        1     
                      ----- = -----------
                      V(s)             1 
                              Ls + R + --

And, if you like typing


                         II(s) = V(s) T


                  /         1 \              
                  |Ls + R + --| V(s) T = V(s)
                  \         Cs/              


                        T = -----------
                            Ls + R + --


                      II(s)        1     
                      ----- = -----------
                      V(s)             1 
                              Ls + R + --

which together are


                      II(s)        1     
                      ----- = -----------
                      V(s)             1 
                              Ls + R + --

               /                        (1/2)         \
               |    / 3  2  2         2\              |
         2     |    |m  G  M  + 2 En l |              |
        m  M G |1 + |------------------|      cos(phi)|
               |    |      3  2  2     |              |
               \    \     m  G  M      /              /


         /                                 (1/2)          \
         |         /  / 3  2  2         2\\               |
       2 |     2   |m \m  G  M  + 2 En l /|              2|
      l  |M G m  - |----------------------|      cos(phi) |
         |         |              2       |               |
         \         \      cos(phi)        /               /
    - -----------------------------------------------------
        /      2         2    3  2  2    3  2  2         2\
      m \2 En l  cos(phi)  - m  G  M  + m  G  M  cos(phi) /

simplify(f-g) assuming phi>0, Pi/2>phi, m>0, G>0, M>0;


# trying to get f from g
(1/simplify(rationalize(denom(g)/numer(g)))) assuming phi>0, Pi/2>phi, m>0, G>0, M>0;

               /                                 (1/2)\
               |             / 3  2  2         2\     |
             2 |    cos(phi) \m  G  M  + 2 En l /     |
        M G m  |1 + ----------------------------------|
               |                     (3/2)            |
               \                M G m                 /

# trying to get g from f
(rationalize(f)) assuming m>0, G>0, M>0;

       /                               (1/2)         \     
       |           / 3  2  2         2\              |     
       |     2     |m  G  M  + 2 En l |              |  2  
       |M G m  - m |------------------|      cos(phi)| l   
       \           \         m        /              /     
    - -----------------------------------------------------
        /      2         2    3  2  2    3  2  2         2\
      m \2 En l  cos(phi)  - m  G  M  + m  G  M  cos(phi) /
First 7 8 9 10 11 12 13 Last Page 9 of 48