Carl Love

Carl Love

28070 Reputation

25 Badges

13 years, 29 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

You seem reluctant to simply enter the integral

int(c*g(c), c= a..b);

Why are you reluctant?

Yes, you can use Statistics:-ExpectedValue for an arbitrary distribution. But what's the point of doing it that way?

Suppose my distribution is g(x) = x/2 defined on [0,2]. I can do

Omega:= Statistics:-Distribution(PDF= (x-> x/2), Support= 0..2):
Statistics:-ExpectedValue(Omega);

or I can simply do

int(x*x/2, x= 0..2);

and get the same answer.

Is your problem that you have no closed form for the PDF? Then the Statistics package may be able to help because there are many alternative ways to specify a distribution. What information do you have about the distribution?

Your odetest result is {0, expression1, expression2}. Your input was four differential equations. In Maple a sequence of expressions surrounded by curly braces is a set. Sets don't have repeated elements. Two of your differential equations matched perfectly to their equations, producing 0. Those two zeroes are replaced by one zero because it's a set. To avoid this confusion, use lists instead of sets. Practically, that means replacing all your curly braces { } with square brackets [ ].

The expression1 and expression2 may well reduce to 0 also, but Maple was not able to prove it. Substitute numeric values for as many parameters as you can and see if you can reduce these to 0. I wanted you to post your FULL CODE so that I could try to reduce these to 0, or prove that they aren't 0. So, if you want more help, please post that.

Presumably, you intended for your procedure to be like this:

Naief:= proc(A::integer, B::integer, p::posint)
local x, a:= A mod p, b:= B mod p;
     for x to p-1 do
          if a^x mod p = b then return x end if
     end do;
     print("No solution.")
end proc:


Naief(3,7,11);

     "No solution."

Naief(7,3,11);

     4

Here is some Maple coding advice for you:

There is no disp; what made you think that there is? It's either print or return. In the vast majority of cases, you'll want return instead of print, which is mostly for auxiliary information. See also userinfo. Of course, return forces an exit from the procedure, and print does not.

If you want a null operation, the syntax allows you to leave the space blank; there's no need for something like x=x. In other words, the syntax allows then elif with nothing between them. If you want to immediately go to the next value of x, use next.

Don't check both a condition and its opposite; it is wasteful. A thing either is or isn't equal to 0. So, you should use else instead of elif.

Did you have any trouble reverting the substitution? A simple

eval(expr, Sw= Sum(w[k], k= 1..n);

should do it.

If the sum cannot be simplified or be put into closed form, then you should use Sum instead of sum. If you use sum, then Maple wastes time trying to put the sum into closed form everytime the expression is evaluated.

This is an Answer to the amended question in your Reply to your original Question, which is a much more complicated problem than your original Question.

evalindets(B, And(`*`, satisfies(P-> {1/T[1],1/V[2]} subset {op(P)})), P-> P*T[1]*V[2]);

(It looks a lot better in a worksheet than posted here.)

Use the Select Execution Group keyboard shortcut Ctrl-Alt-Shift-E. It's true that that will only select one execution group at a time, but, c'mon, how many execution groups are we talking about moving here? If you have a huge number of execution groups, maybe you should merge them using Join Execution Groups F4.

Note how Maple represents the derivative of tan(x):

diff(tan(x), x);

Based on this, I guessed that your integral might work better if I replaced sec(x)^2 with the above.

int(tan(x)^(n-2)*(1+tan(x)^2), x);

The above answer is returned nearly instantaneously.

I was quite surprised that the following not-quite-simplified answer was also returned nearly instantaneously. I had expected that the integration would be distributed over the sum, leading to an unevaluated answer for powers of tangent.

int(tan(x)^(n-2)+tan(x)^n, x);

Based on the result of my first integral above, I guessed that if I redefined the derivative of tangent, then your integral would evaluate easily. That guess was correct.

eval(`diff/tan`);

restart: #Need to clear diff's remember table.
unprotect(`diff/tan`);
`diff/tan`:= proc(z,t,$) `tools/df_dt`('tan(z)', z-> sec(z)^2, t) end proc:
diff(tan(x), x);

int(tan(x)^(n-2)*sec(x)^2, x);

So this explains why the derivative-divides rule (see Alejandro's Answer) failed to be applied to your original integral.

Maple is interpretting your quoted expressions as mathematical expressions (with division and implied multiplications) because you have used the wrong type of quotation marks. Use either double quotes

"Extracelular urea concentration (mg/dL)"

or back quotes

`Extracelular urea concentration (mg/dL)`

In the future, PLEASE PROVIDE THE COMPLETE CODE needed to generate your solution. I DID NOT ENJOY having to recreate your differential equations so that I could execute your code given above. Maybe that's why it took four days for you to get an Answer.

By the way, cellular is spelled thus, with a double L.

If A is a (1-dimensional) Array, the appropriate subarrays can be extracted by the following intuitive indexing:

A[[1..4,5,8,9]], A[[6,7]], A[[10]];

Note the extra square brackets, which are required for the first two, and are needed to make the last one an Array rather than just a single entry.

In order to map an indexing operation over a list of index specifications, we need an indexing operator in prefix form. Maple provides `?[]` for this purpose. So, `?[]`(A, [Ind]) is the same as A[Ind]. (Note carefully the extra square brackets that are required around the index specifications in the prefix form!)

To add the extra square brackets en masse (by mapping), we need the prefix form of the add-square-brackets operator. That's `[]`. So `[]`~ ([A,B,C]) is the same as [[A],[B],[C]].

The first argument to plot needs to be a list, not an Array, so I use convert(..., list).

Here's an example of the three plots (one color for each group of indices) put together with plots:-display. If you want three separate plots, simply replace plots:-display with print~.

A:= Array(1..10, n-> t-> t^(n-5)):

Inds:= [[1..4,5,8,9], [6,7], [10]]:
plots:-display(
   zip(
        (A,C)-> plot(convert(A, list), -2..2, -32..32, discont, color= C),  
        map2(`?[]`, A, `[]`~(Inds)),
        [red,green,blue]
   )
);

[Edit: It turns out that the first two of the three solution techniques presented in this Answer are irrelevant because the true cause of the problem was the OP's high setting of Digits (which was not revealed until much later in the discussion below). I just leave them here so that the rest of the thread makes sense.]

Here are three completely different techniques to solve this.

 Procedural form of input to Int and plot

Use the procedural form of input to Int and plot, which does not use an independent variable.

Also, your way of extracting the procedure from the dsolve solution is convoluted: There is no need to mention the independent variable. Ordinarily, what you did with the independent variables would make sense to Maple, although it is not necessary to do it. However, the procedures returned by dsolve(..., numeric, output= listprocedure) treat a symbolic independent variable in a slightly strange way: Instead of returning y(x), they return `y(x)`(x). This would be fine if the numeric procedure was named `y(x)`, but you've changed the name to u.

So, to correct the problem, do this:

# No change needed to dsolve.
So:= dsolve(
     [-1.2*diff(y(x), x$2)+0.8*y(x) = 2, y(0)=1, y(1)=0], y(x),
     'numeric', 'output' = listprocedure
):

# Simple extraction; no unapply needed.
u:= rhs(So[2]):

# No independent variables on the procedures or the range.
plot([u, u^2], 0..1);

# No independent variables, and note the capital I
evalf(Int(u, 0..1));

evalf(Int(u^2, 0..1));

 Or... Name the numeric procedure appropriately

You could just use `y(x)` instead of u as the target for the unapply, then make the next line u:= `y(x)`, and keep the rest of your code exactly as it was before:

`y(x)`:= unapply(rhs(So[2])(t), t):
u:= `y(x)`:

 Or... Make the integrals part of dsolve's output

You could simply include the appropriate functions in the original system passed to dsolve. It has often been argued here at MaplePrimes that this is the most numerically robust way to do it, due to dsolve's sophisticated error control. (However, I suspect that it is more computationally intensive because it requires the computation of the integrals at all the intermediary points.) This way involves a little bit of thought to rearrange the integrals into derivative form.

So:= dsolve([
     -1.2*diff(y(x), x$2)+0.8*y(x) = 2, y(0)=1, y(1)=0,

     diff(u(x),x) = y(x), u(0)=0,
     # So u(x) = int(y(t), t= 0..x).

     diff(u2(x),x) = y(x)^2, u2(0)=0
     # So u2(x) = int(y(t)^2, t= 0..x).

     ], [y(x), u(x), u2(x)],
     'numeric', 'output' = listprocedure
):

So(1);


The required integrals are the last two entries in the above list.

 

Do you mean that you want the display of the function to be J_0(k), i.e., a more standard notation than BesselJ? Then set

interface(typesetting= extended);

Then,

inttrans[fourier](piecewise(abs(x)<1,1/sqrt(1-x^2),0),x,k);

The typesetting level can also be changed from the Tools -> Options -> Display menu.

This is a bug. I'm amazed that it hasn't surfaced before now. Looking at the simple code for IntegrationTools:-Combine shows both the source of the bug and the workaround.

showstat(IntegrationTools:-Combine);

IntegrationTools:-Combine := proc(v)
local ints, x, X, input, output;
   1   ints := indets(v,'And(DefiniteIntegral,Not(MultipleIntegral))');
   2   x := IntegrationTools:-GetVariable(ints[1]);
   3   input := subsindets[':-flat'](v,'And(DefiniteIntegral,Not(MultipleIntegral))',t -> Change(t,GetVariable(t) = X));
   4   output := combine(input,'int');
   5   return subs(X = x,Change(output,X = x))
end proc

So, it is clear from lines 1 and 2 that the command can only work on definite integrals! For indefinite integrals, just use combine(..., int).

combine(Int(sin(x),x)+Int(cos(x),x), int);

plots:-polarplot([r, Pi/6, r=0..2]);

The upper limit for r is arbitrary; I chose 2 for no particular reason. Note that Pi is with a capital P.

This technique is akin to how one would plot a vertical line in rectangular (Cartesian) coordinates:

plot([3, y, y= -2..2]);

I'm not sure if command polarplot is available in Maple 13. If it isn't, I'll come up with something else for you.

Perhaps they meant semicolons, which are used to separate rows:

< 6,8 ; -3,9 ; 4,14 >;

But that's row-major order.

By the way, using the angle-bracket operators uses significantly less processor time than using Matrix or Vector, so I'd recommend using them (or the built-in rtable) in programs whenever possible. Often, it is useful or necessary to use the prefix forms `<,>` and `<|>`. (There is no `<;>`.) For example, to convert a row-major listlist LL into a Matrix, you could do

<`<|>`~(LL)[]>;

But that example is just to illustrate the power of the prefix notation, because instead I'd probably use

rtable(LL, subtype= Matrix);

If your answer to the first question in my Reply above is yes, then this routine will do it:

SeparateLastTerms:= E->
     evalindets(
          E, specfunc(anything,{Sum,sum}),
          S-> eval(op(1,S), op([2,1],S)= op([2,2,2],S)) + subsop([2,2,2]= op([2,2,2],S) - 1, S)
     )
;

Example of use:

E:= Sum(A[k], k= 2..n+1) + sum(f(j), j= 3..m):
SeparateLastTerms(E);

First 280 281 282 283 284 285 286 Last Page 282 of 395