Carl Love

Carl Love

28025 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Using a basic procedure as a Matrix initializer, it can be done by

M:= Matrix((N+1)$2, (i,j)-> `if`(j = i+1, i, 0))

It can also be done with the scan option of the Matrix command:

M:= Matrix((N+1)$2, [[0$(N+1)], [$1..N]], scan= band[0,1])

You can do

U:= Array(-x..x, -x..x);

then do the initialization. After that, if you want to use it as a mathematical matrix for LinearAlgebra commands, you can do

M:= convert(U, Matrix);

Now M will have indices 1..11. Note that your convert command above doesn't change itself to a matrix because you did not assign the output of the command.

If you intend to do this on a large scale, there's a better way to re-index using the command ArrayTools:-Alias.

When certain structures (such as procedures, modules, or tables) are assigned to a name (such as your T[1]), and you access that name, the name itself rather than the assigned value is shown. This process is called last name evaluation. To see the assigned value, use eval(T[1]). An arrow expression such as x-> x^2 is a type of procedure, so last name evaluation applies to it.

Acer's Answer is good, and you can learn much about working around Maple's numeric integration by studying it. But I don't know why he's pandering to your fantasy that those infinitesimal Bessel terms contribute anything to the result. The integral can be easily done by

CodeTools:-Usage(
   int(fnormal(F1), [theta= Pi/4..7*Pi/4, r= 0..1])
);
memory used=58.56MiB, alloc change=0 bytes, cpu time=500.00ms, real time=500.00ms, gc time=0ns
                                          12
                    -1.1160010071917965 10  

Indeed, after the integrand is fnormal'ed as above, the integral can be done by elementary symbolic methods as taught in third-semester calculus.

One should not infer from this Answer that such use of fnormal will always produce results of the same accuracy as those produced by not using it.

In order for the second animation to be properly considered to be a rescaling of the first, you need to rescale the t range also. So, try this,

animate(plot, [fourier(f(x,2^t),x,w)/2^t, w= 0..100], t= log[2](0.1)..log[2](1), frames= 100)

To get further help, you'll need to show the formula for f(x,t).

With the release of Maple 18, a new format for the internal storage of help files was introduced. This is transparent to the end user. Third-party help files (such as your OrthogonalExpansions) created in the old format need to be updated. This can be done with a single command, which finds all such help files and updates them:

HelpTools:-Database:-ConvertAll():

Let me know if you have any trouble with that.

LinearAlgebra:-Generic works fine with GF (in Maple 2019). (VV, can you say more about why you think that  it doesn't? Perhaps it doesn't work in the OP's Maple 2015.)

Magma: The only mistake that you made was asking for the determinant. Of course, you can't ask for the determinant of a nonsquare matrix. So, just ask for the rank. Below, I changed the order of the columns from the matrix in your worksheet because your matrix A was already in reduced row-echelon form, making it not such a good example for testing the code.

restart:
G:= GF(2,4):
A:= G:-input~(<
   5, 0, 4, 1, 0, 0;
   8, 7, 2, 0, 1, 0;
   3, 0, 1, 0, 0, 1
>):
G:-output~(LinearAlgebra:-Generic:-ReducedRowEchelonForm[G](A, 'r'));
                             [1  0  0  2  0  8 ]
                             [                 ]
                             [0  1  0  4  6  15]
                             [                 ]
                             [0  0  1  6  0  10]
r;
                                      3

 

 

Some points to consider:

Intregration, even numeric integration, via Maple's intInt, or `evalf/Int` is not threadsafe---it may not consistently give correct results when used in the shared-global-memory environment of the Threads package (see ?index,threadsafe). This is likely due to those procedures using global variables which are not protected from being overwritten by the same global variables in the sibling tasks. The Grid package does parallel processing in a non-shared-memory environment. Of course, this incurs substantial overhead (to copy the memory), and, of course, more memory. So, Grid is more appropriate for most parallel processing.

Nonetheless, your code does give accurate results in every test that I've tried. So, numeric intregration via _cuhre may in reality be threadsafe; it just hasn't been documented to be so.

The number of terms that you're adding,15, is much, much too small to be a meaningful speed test of Threads. Below, I do 10000 iterations of your integral, and the real time is cut in half by using Threads (or, as Joe said, the speed up is 2x).

If you're just adding terms, use Threads:-Add rather than the more-complicated Threads:-Task.

restart:
L1:= 10:  N:= 10000:
randomize(37): #Arbitrary number
xx:= Statistics:-Sample(Uniform(0,100), N): 
                            
CodeTools:-Usage(
   Threads:-Add(
      int(
         sin(beta)/(100 + ZZ*sin(beta) - xx[i]*cos(beta))^(5/2), 
         beta= 0..1, ZZ= 0..L1, 
         'numeric', 'epsilon'= 0.01, method= _cuhre
      ),
      i= 1..N
   )
);
memory used=384.35MiB, alloc change=464.00MiB, cpu time=14.33s, real time=2.81s, gc time=828.12ms
                          107.8763089
restart:
L1:= 10:  N:= 10000:
randomize(37): #Same arbitrary number
xx:= Statistics:-Sample(Uniform(0,100), N): 
                               
CodeTools:-Usage(
   add( #without Threads
      int(
         sin(beta)/(100 + ZZ*sin(beta) - xx[i]*cos(beta))^(5/2), 
         beta= 0..1, ZZ= 0..L1, 
         'numeric', 'epsilon'= 0.01, method= _cuhre
      ),
      i= 1..N
   )
);
memory used=357.54MiB, alloc change=-4.00MiB, cpu time=6.42s, real time=5.67s, gc time=1.31s
                          107.8763089
(1 - 2.81/5.67)*100; #Percent time reduction
                          50.44091711

 

All that you need to do is

collect(vel_qD, diff(s1(t), t))

Since the equations are linear in diff(s1(t), t), you can also use any of the equations that contain diff(s1(t),t) to eliminate it from the other equations. This is easy to do know; so, if you want that, let me know.

Here are your equations in a formatted plaintext form, which is easier to work with (easier for the human; it makes no difference to Maple).

vel_qD := <
   diff(theta1(t), t) = -(diff(s1(t), t))*cos(theta3(t))/(LAD*sin(theta1(t)+theta3(t))), 
   diff(theta2(t), t) = 
     (
        L1*sin(theta1(t)+theta3(t))*diff(s1(t), t) +
        L1*sin(theta1(t)-theta3(t))*diff(s1(t), t) -
        2*LAD*sin(theta1(t)+theta3(t))*diff(s1(t), t)
     ) / 
    (LAD*LBC*cos(theta1(t)+theta3(t)-theta2(t))-LAD*LBC*cos(theta1(t)+theta3(t)+theta2(t))), 
    diff(theta3(t), t) = diff(s1(t), t)*cos(theta1(t))/(L3*sin(theta1(t)+theta3(t))), 
    diff(s2(t), t) = 
       (
           L1*sin(theta1(t)+theta3(t)-theta2(t))*diff(s1(t), t) + 
           L1*sin(-theta3(t)-theta2(t)+theta1(t))*diff(s1(t), t) -
           LAD*sin(theta1(t)+theta3(t)-theta2(t))*diff(s1(t), t) - 
           LAD*sin(theta1(t)+theta3(t)+theta2(t))*diff(s1(t), t)
       ) / (LAD*cos(theta1(t)+theta3(t)-theta2(t))-LAD*cos(theta1(t)+theta3(t)+theta2(t)))
>;

 

Any member whose reputation is greater than 500 is a moderator. According to https://www.mapleprimes.com/users/mmcdara/reputation, you reached 500 about a month ago, so you've being seeing the red spam icons for about a month, which is why they seem "more and more common" to you.

The red spam icon appears on any unresponded content or any top-level post from any user whose reputation is less than or equal to[*1] 10. The age of the user's account and their history of prior posting is irrelevant. The purpose of the icon is not to alert the reader that the post is spam; rather, its purpose is to allow you, as a moderator, to decide whether it is spam, which immediately deletes the content and de-activates the user's account[*2].

As a moderator, you have the power to edit or delete any content whatsoever[*3]; of course, you're honor-bound to use this power with "moderation" and discretion[*4]. But there's a distinction between simply deleting a post and deleting it as spam---the latter deletion de-activates the user's account as well.

Spam, as a noun in it's original Internet-related usage, refers to content that is totally irrelevant to the forum where it's posted, not content that is merely and unintentionally irrelevant to the thread in which it's posted. Usually, it's advertising. On MaplePrimes, I've deleted everything from ads for plumbers in Toronto to whores in Mumbai. There's also a newer usage of spam as a verb to refer to the frequent posting of low-quality annoying content (which is nonetheless still marginally relevant content). I'm not a fan of this new usage, but unfortunately it seems well established. The moral gulf between the two activities is too wide to risk conflating them ("to tar them with the same brush" as the English saying goes): The former is highly unethical and always intentional, whereas the latter is merely rude and often unintentionally so.
 

[*1]The MaplePrimes documentation implies that the criterion is (reputation < 10). This is incorrect! In reality, it's (reputation <= 10). I suspect that this was a programming error and that the lower criterion was the intention.

[*2]We're discovered over the years that it's essential that a spammer's account be de-activated. If this is not done, they post it faster than it can be deleted. In the rare case that something/someone gets deleted inappropriately, the adminstrators can restore it. So, don't worry about that. The important thing is that you delete spam as soon as you see it. This site used to be inundated with spam back in the days when moderators could merely delete it.

[*3]If content has been responded to, it may be necessary to first delete the responses.

[*4]I believe that moderators should keep in mind at least a vague notion of some ethically based principles of editorship such as we all should have learned in our formal educations.

The computations (of the level curves) for a contour plot are essentially three-dimensional, even if the final result happens to be displayed as a two-dimensional projection, so a two-dimensional coordinate transformation (such as polar) does not apply. You must use a three-dimensional transformation. The rest of what I would say has already been said by Thomas Richard.

Regardless of whether the range is numeric, a command to do it is

subsindets(eqn, specfunc({sum,Sum}), S-> op(1,S))

where eqn is the equation that you refer to. This works because the summand is operand of each sum or Sum

You should never copy-and-paste the output of one command to the input of another. That way madness lies. 

The command codegen:-GRADIENT does what you want:

codegen:-GRADIENT((x,y)-> (x^2-y^2));

See also codegen:-JACOBIAN and codegen:-HESSIAN.

General advice:

Don't use the with command if you don't need to. Instead, use package prefixes (A:-B is command B from package A). Almost everything that can be done with with can be done this way instead. In particular, with(VectorCalculus)literally changes the definitions of numerous (about a dozen) fundamental Maple commands, including Ddiff, and even and *.

Don't use assume if you don't need to. Instead, use assuming.

Since you're using an integral transform, and integration doesn't care about removable discontinuities, why use piecewise? Doesn't this do what you want?

with(inttrans):
sinc:= x-> sin(Pi*x)/x/Pi:
SE := x->sinc(x)*exp(-x^2):
plot(abs(fourier(SE(x),x,s)),s=0..5)

 

One problem with your most-recent variation is that you've made the coefficients of the integrals 5/Pi. The coefficient does not depend on the number of term. It's always 2/P, where is the period of the overall function.

Here's a little procedure that returns the coefficients, the sum, and/or the plot, depending on the output options that you choose.

FourierSum:= proc(
   f, Per::range, n::nonnegint, 
   {output::{identical(sum,coeffs,plot), list(identical(sum,coeffs,plot))}:= sum}
)
local 
   k, P:= (rhs-lhs)(Per), CS:= [cos,sin], cs, x, X:= 2*Pi*x/P,
   Out:= table(), Output:= `if`(output::list, x-> x, `[]`)(output)
; 
   Out[coeffs]:= [seq(<seq(2/P*int(f(x)*cs(X*k), x= Per), cs= CS)>, k= 0..n)];
   if ormap(`in`, {sum, plot}, Output) then
      Out[sum]:= unapply(add(Out[coeffs] .~ [<1/2,0>, seq(<CS(X*k)[]>, k= 1..n)]), x);
      if plot in Output then 
         Out[plot]:= plot([f,Out[sum]], Per, _rest);
         if nops(Output) > 1 then userinfo(1, FourierSum, NoName, print(Out[plot])) fi
      fi
   fi;
   eval(`if`(nops(Output)=1, op, `<,>`@op)(Output), op(eval(Out)))  
end proc:

Usage:
 
infolevel[FourierSum]:= 1:
f:= t-> t^2:
FourierSum(f, 0..2*Pi, 5, output= [coeffs, sum, plot]);

 

First 144 145 146 147 148 149 150 Last Page 146 of 395