Carl Love

Carl Love

28065 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

The command that you're trying to use, ExpandSteps, is only for polynomial expansion, not for matrix arithmetic. The command that applies to your situation is Student:-LinearAlgebra:-GaussJordanEliminationTutor; however, its use is limited to matrices at most 5 x 5.

I see that your matrix has 9-digit exact integers and exact imaginary values. So what's the point of seeing the steps? Do you suspect an error in Maple's computation?

Maple handles regular expressions. See these help pages:

  • ?StringTools,Regular_Expressions
  • ?StringTools,RegMatch
  • ?StringTools,RegSplit
  • ?StringTools,RegSub
  • ?StringTools,RegSubs

All that VV said is true. I'd just like to add that if you want symbolic variables to be treated like would-be integers until they have values assigned, then use irem instead of mod.

@tomleslie Thanks for testing. The results are not surprising given that I used an array half the size of yours but a more complicated indexing scheme, and otherwise our codes are remarkably similar. Here's an update---much terser but not significantly faster---that probably satisfies the OP's titular no-loop request (thus I made this an Answer):

EratosthenesSieve:= proc(N::posint)
description "Returns list of primes <= N";
local p, k, P:= rtable(1..iquo(N-1,2), k-> 2*k+1);
   if N < 5 then return remove(`>`, [2, 3], N) fi;
   P[[seq(seq(iquo(k-1, 2), k= p^2..N, 2*p), p= thisproc(isqrt(N))[2..])]]:= ();
   [2, seq(P)]
end proc:

 

It is useful---and often essential---to avoid repetition when generating combinatorial objects. It can, for example, reduce the time complexity from O(n^2) to O(n), which can be the difference between doability and nondoability.

Here is a generalization of your problem: Let B be the base set from which the integers are drawn, e the exponent, and n the number of integers to draw (with replacement, but regardless of order). Then your problem can be done by:

B:= [$0..5]:  e:= 2:  n:= 2:
[seq(add(B[[seq(C)]]^~e), C= Iterator:-MultiCombination([n$nops(B)], n))];

Note that I used no sets, only lists, yet there are no repetitions. Thus, each desired object was generated only once. The Iterator package is generally very good about that.

Just change the last line to

Maximize(simplify(S), {a^2+b^2+c^2 = 1}) assuming real;

This is needed to get rid of the absolute-value / complex-modulus operators, which are messing up the differentiability of the objective function.

I can confirm using your worksheet that I get the same syntax error as you do. I don't know why. But you can do this:

q1:= (n1, n2)-> `if`(n1 < 0 or n2 < 0 or abs(n1-n2) <> 1, 0, sqrt(max(n1,n2)/2));

That gives me no syntax error.

The Maple equivalent of the Matlab syntax Q(:, 1), where Q is a Matrix, is Q[.., 1].

To answer your overall question---to wit:

  • I would like to ask if there is any command in Maple while solving the equations that are responsible for possible approximations when solving equations

If you use the command solve or any command in its "family", which include the package SolveTools and numerous other commands and packages, and your input does not include any decimal numbers, then there are no approximations used. If the command cannot find an exact solution, then it returns nothing.

What makes you think that the solution that you got is wrong?

In the worksheet attached to your original Question, you give the following formula, which you attribute to VV:

  • The total number of set partitions of n distinct items into e sets of length L, with n = e*L, is n!/e!/(L!)^e.

To be more precise, that is the number of ways of doing it if the subsets are unlabeled. If they are labeled (as in red team, green team, orange team), then the formula is n!/L!^e. Both of these formulas can be easily generalized to the situation where the subsets aren't necessarily equally sized.

Let be a list of positive integers representing the sizes of the blocks of the partition. If the blocks are labeled, then the number of partitions is add(B)!/mul(B!~). This can also be computed in Maple as combinat:-multinomial(add(B), B[]). If the blocks are unlabeled, then the number of partitions is add(B)!/mul(B!~)/mul(rhs~(Statistics:-Tally(B))!~). This can also be computed in Maple as Number(Iterator:-SetPartitionFixedSize(B)).

For B = [5,5,5], the labeled-block formula gives 756756 and the unlabeled 126126. The former leads to the probability 1/1001 and the latter 6/1001. The denominator from my original Answer is binomial(15,5)*binomial(10,5)/3!, which also equals 126126.

 

If you're expecting the result 2, as if differentiating with respect to x(t), do like this:

f:= 2*x(t)+5;
Physics:-diff(f, x(t));

I never use 2D input, so I can't help with that aspect of doing it.

It's not a bug (although it's very often majorly inconvenient), and it's not anything specific to IntegrationTools:-Change. Changing assumptions makes new copies of variables which are not automatically substituted into the expressions containing the old copies. The way to get that substitution to happen (temporarily) is to use assuming instead of the second assume and assuming additionally instead of additionally, like this:

restart;
assume(a>0,b>a,c>0,t>0);
F := Int(sqrt(d-a*c^2*t),d=0...infinity);
IntegrationTools[Change](F,-a*t*c^2+d=-y,y) assuming b > a;

or

restart;
assume(a>0,b>a,c>0,t>0);
F := Int(sqrt(d-a*c^2*t),d=0...infinity);
IntegrationTools[Change](F,-a*t*c^2+d=-y,y) assuming additionally, b > a;

 

As you probably know, there is a one-to-one correspondence between partitions of n of length k and partitions of n whose maximum element is k. Using that principle, here's a procedure that's much more efficient than my prior Answer:

PartitionFixedSize:= proc(n::posint, k::depends(integer[1..n]))
local p, P;
   [seq(1 +~ `+`(seq([0$(k-p), 1$p], p= P)), P= combinat:-partition(n-k, min(n-k, k)))]
end proc:

 

When you want to use an index on a function's name as if it were a function parameter, the index must be extracted inside the procedure using op(procname). Unfortunately, this makes the syntax a bit awkward, but there's no need to use a for loop for this. Thus, this entire section of your code:

g[1](r);
ux[1] := (x, r) -> epsilon[1][1]*x + g[1](r);
ur[1] := r -> A[1]*r + B[1]*1/r;
varepsilon[1][1] := epsilon11c;
varepsilon[1][2] := r -> (A[1]*r + B[1]*1/r)*1/r;
varepsilon[1][3] := r -> diff(ur[1](r), r);
varepsilon[1][3](R[2]);

for i from 2 to N - 1 do 
g[i](r); 
ux[i] := (x, r) -> epsilon[i][1]*x + g[i](r); 
ur[i] := r -> A[i]*r + B[i]*1/r; 
varepsilon[i][1] := epsilon11c; 
varepsilon[i][2] := r -> (A[i]*r + B[i]*1/r)*1/r; 
varepsilon[i][3] := r -> diff(ur[i](r), r); 
varepsilon[i][2](r); i;
end do;

should be replaced by

ux:= (x,r)-> epsilon[(local i:= op(procname))][1]*x + g[i](r):
ur:= r-> A[(local i:= op(procname))]*r + B[i]/r:
varepsilon:= proc(r) 
local k:= op(procname), i:= op([0,1], procname);
   if k=1 then epsilon11c
   elif k=2 then ur[i](r)/r
   elif k=3 then diff(ur[i](r), r)
   fi
end proc:   

And you would invoke it, for example, like this:

varepsilon[2][1](); varepsilon[2][2](r); varepsilon[2][3](r);

So, note that that's a slight change in the calling syntax for varepsilon[i][1](), because the parentheses are needed.

Here's one way to do it:

PartitionFixedSize:= (n::posint, k::depends(integer[1..n]))-> 
  subsindets(Statistics:-Tally~(combinat:-composition(n,k)), `=`, `$`@op)
:
PartitionFixedSize(10,2);
            {[1, 9], [2, 8], [3, 7], [4, 6], [5, 5]}

This is not the most computationally efficient way to do it, because I start with the compositions and discard the duplicates. Of course, it'd be more efficient to not generate duplicates in the first place. But my procedure has the benefit of brevity.

There's a command that's supposed to do it efficiently, but it seems completely broken. It's called Iterator:-PartitionFizedSize. The command 

{seq([seq(p)], p= Iterator:-PartitionFixedSize(10,2))}

should return the same thing, but all that it actually returns is {[9,1]}. Hopefully @Joe Riel will fix this bug soon.

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