Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Use partial fractions:

e1:= convert(cot(x), confrac, x, 6):
convert(e1, parfrac, x);

By the way, your original form is called a continuED fraction, not a continuOUS fraction. I edited this in your Question.

You asked:

And how do I find the values of m1, s1, m2, s2 and a?

Instead of Fit(...) use Fit(..., output= parametervalues).

As far as I can tell, there is no predefined command for this in the ListTools package, although it is closely related to ListTools:-Split. That command can't look at both a list element and its next element at the same time, which is what your application requires. So, here's a procedure for it:

SplitScan:= proc(f, L::list)
local R:= Vector(), k:= 0, j, last:= 1;
     for j from 2 to nops(L) do
          if f(L[j-1], L[j], _rest) then
               k:= k+1;
               R(k):= L[last..j-1];
               last:= j
          end if
     end do;
     [seq(k, k= R), L[last..]]
end proc:

Its use:

SplitScan(`<>`, ca); #Split where element <> previous element.

For example,

y[0]:= -38:
for k to 9 do  y[k]:= evalf([solve(x^2 = y[k-1])][1]) end do;

I wasn't aware that the word "to" as you use it above was valid Matlab syntax. I thought it should be a colon. Regardless, your intended meaning is clear.  In Maple:

Hy:= Vector(M);
Ex:= Vector(M+1);
for t from 1 to T do
    Ex[1]:= evalf(exp(-t));  #Don't you mean Ex[t]???
     for k from 1 to M do
          Hy[k]:= Hy[k] - (Ex[k+1] - Ex[k])
     end do;
     for k from 2 to M do
          Ex[k]:= Ex[k] - (Hy[k] - Hy[k-1])
     end do
end do;

I've translated exactly what you wrote. I haven't tried to correct any logic errors.

Most of the information that you need to understand this can be found at ?rtable_eval. You may need to read that page slowly and carefully 10 to 20 times (like I did) to understand it. Also read the seventh and twelfth paragraphs of Description at ?eval. What you also need to know to understand this:

  • Most expressions fully evaluate when used at the command line (in any GUI).
  • Most expressions evaluate to only one level (equivalent to eval(..., 1)) when they're used in a procedure.
  • rtables never evaluate unless that's forced with a specific evaluation command.

To avoid obfuscation, first understand what is happening without the list conversion. To answer your Question about intention: yes, this behavior (before list conversion) is certainly intended. Whether the behavior after the list conversion is intended or correct or should be considered a bug: I don't know---it's a very fine judgement call. Certainly that behavior can be removed by adding an eval to `convert/list`.

A few examples:

 

restart:

A:= <a>:
a:= 1:

A;

Vector(1, {(1) = a})

rtable_eval(A);

Vector(1, {(1) = 1})

A;

Vector(1, {(1) = a})

rtable_eval(A, inplace);

Vector(1, {(1) = 1})

A;

Vector(1, {(1) = 1})

Procedure CL1 is an abbreviated version of how convert(..., list) actually works when applied to a Vector (see line 15 of showstat(`convert/list`)). Procedure CL2 is an alternative version that unintentionally applies another level of evaluation. I really can't say which is better. Procedure CL3 is a very slight variation of CL2 that shows that round-bracket indexing doesn't evaluate the entry whereas square-bracket indexing does. Procedures CL4 and CL5 show that the results of CL3 and CL2 (respectively) remain the same if the indexing type (round bracket or square bracket) is expressed in prefix form.

CL1:= proc(A) local i; [seq(i, i= A)] end proc:

CL2:= proc(A) local i; [seq(A[i], i= 1..numelems(A))] end proc:

CL3:= proc(A) local i; [seq(A(i), i= 1..numelems(A))] end proc:

CL4:= proc(A) local i; [seq(`?()`(A, [i]), i= 1..numelems(A))] end proc:

CL5:= proc(A) local i; [seq(`?[]`(A, [i]), i= 1..numelems(A))] end proc:

B:= <b>:
b:= 2:

CL1(B);

[b]

CL2(B);

[2]

CL3(B);

[b]

CL4(B);

[b]

CL5(B);

[2]

``

 

Download rtable_eval.mw

But I still don't understand this: What is the difference between rtable_eval(A, inplace) and map[inplace](eval, A)?

 

You're probabaly better off using LinearAlgebra:-LinearSolve as in Preben's Answer, but this is possible using solve as in your Question. But your multiply is meaningless, and solve deals with sets or lists of algebraic expressions or equations but not with matrices. However, converting between the forms is straightforward. Additionally, your construction of the matrices could be simplified. This works:

restart:
A1:= Matrix((3,3), symbol= a);
A2:= <A, B, C>;
A3:= <15, 0, 0>;
solve(convert(A1.A2 - A3, set), {A,B,C});

(Of course, this solution is only valid when the determinant is nonzero.)

You don't show the results of your second attempt. When I do it (in Maple 18), I get your desired result:

restart:
sol:= solve(combine(sin(x)^2)=1/4, x, AllSolutions);

     sol := -(1/3)*Pi*_B1+(1/6)*Pi+Pi*_Z1

This procedure will expand any positive integer power of any Sum.

 

Raising arbitrary Sums to positive integer powers

Carl Love 2015-Aug-7

 

restart:

The procedure NestedSum is to allow nested Sums to be specified as a single function call with the indices in a list, just as can be done with Int.

NestedSum:= proc(E, Ind::list(name = range))
local r:= E, ind;
     for ind in Ind do r:= Sum(r,ind) end do
end proc:

For example,

NestedSum(sin(m*x)*cos(n*x), [m= 1..n, n= 1..4]);

Sum(Sum(sin(m*x)*cos(n*x), m = 1 .. n), n = 1 .. 4)

The main procedure:


SumPower:= proc(S::Sum(anything, name= range), power::posint, {prefix::symbol:= _k})
uses C= combinat;
local
     p, part, perm,
     K, Ks:= [seq(cat(prefix,p), p= 1..power)],
     Es:= [seq(subs(op([2,1],S)= K, op(1,S)), K= Ks)],
     Inds:= [seq(Ks[p]= op([2,2,1],S)..Ks[p-1]-1, p= power..2, -1), Ks[1]= op([2,2],S)]
;
     add(
          C:-multinomial(power,part[])*
               NestedSum(
                    add(`*`((Es[..nops(part)]^~perm)[]), perm= C:-permute(part)),
                    Inds[power-nops(part)+1..]
               )
         ,part in C:-partition(power)
     )
end proc:

Example of use:

S:= Sum(E[n], n= 1..N):
S^5 = SumPower(S, 5, prefix= k);

(Sum(E[n], n = 1 .. N))^5 = 120*(Sum(Sum(Sum(Sum(Sum(E[k1]*E[k2]*E[k3]*E[k4]*E[k5], k5 = 1 .. k4-1), k4 = 1 .. k3-1), k3 = 1 .. k2-1), k2 = 1 .. k1-1), k1 = 1 .. N))+60*(Sum(Sum(Sum(Sum(E[k1]^2*E[k2]*E[k3]*E[k4]+E[k1]*E[k2]^2*E[k3]*E[k4]+E[k1]*E[k2]*E[k3]^2*E[k4]+E[k1]*E[k2]*E[k3]*E[k4]^2, k4 = 1 .. k3-1), k3 = 1 .. k2-1), k2 = 1 .. k1-1), k1 = 1 .. N))+30*(Sum(Sum(Sum(E[k1]^2*E[k2]^2*E[k3]+E[k1]^2*E[k2]*E[k3]^2+E[k1]*E[k2]^2*E[k3]^2, k3 = 1 .. k2-1), k2 = 1 .. k1-1), k1 = 1 .. N))+20*(Sum(Sum(Sum(E[k1]^3*E[k2]*E[k3]+E[k1]*E[k2]^3*E[k3]+E[k1]*E[k2]*E[k3]^3, k3 = 1 .. k2-1), k2 = 1 .. k1-1), k1 = 1 .. N))+10*(Sum(Sum(E[k1]^3*E[k2]^2+E[k1]^2*E[k2]^3, k2 = 1 .. k1-1), k1 = 1 .. N))+5*(Sum(Sum(E[k1]^4*E[k2]+E[k1]*E[k2]^4, k2 = 1 .. k1-1), k1 = 1 .. N))+Sum(E[k1]^5, k1 = 1 .. N)

Verify that that's correct.

is(value(eval(%, N= 3)));

true

The sum doesn't need to start at 1. Indeed, it could start at a variable.

 

 

Download SumPower.mw

You simply need to include the option maxfun= 0 in the dsolve call. This actually sets the maximum allowed number of function evaluations to infinity.

The command is member(c, A), which is built-in and returns type truefalse.

The problem with Kitonum's Answer is that the solve is executed for each iteration. The (potential) problem with Tom Leslie's Answer is that it isn't a single statement. The solution to both problems is the oft-neglected sequencing operator. It works very much like seq except that, like most Maple commands (but unlike seq), its arguments are evaluated before being passed.

{b=j, eval(solve({x+b*y=0, b*x-y=10}, {x,y}), b= j)[]} $ j= 10..20;

     {b = 10, x = 100/101, y = -10/101}, {b = 11, x = 55/61, y = -5/61}, {b = 12, x = 24/29, y = -2/29},
     {b = 13, x = 13/17, y = -1/17}, {b = 14, x = 140/197, y = -10/197}, {b = 15, x = 75/113, y = -5/113},
     {b = 16, x = 160/257, y = -10/257}, {b = 17, x = 17/29, y = -1/29}, {b = 18, x = 36/65, y = -2/65},
     {b = 19, x = 95/181, y = -5/181}, {b = 20, x = 200/401, y = -10/401}

The example structure C that you showed is not a set: it's a sequence: its order matters, and members may be repeated. If you want to subtract a member from a set, then use the Answer by Thomas Dean. If you want to remove all occurences of a member B from a sequence C, then use

remove(`=`, [C], B)[];

Note that the is not enclosed in { } in the solve command below.

Sol:= [solve(f, omega)];
min(select(`>`, Sol, 0));

Here's a procedure that will cancel the lowest floating-point power of 10 (positive or negative) in any fraction:

Cancel10s:= (E::algebraic)->
     `if`(
          hastype(E,And(float,Not(identical(0.)))),
          `/`((numer,denom)(E)/~10^ilog10~(indets(E,And(float,Not(identical(0.)))))[1]),
          E
      )
;

(Note that ilog10 also works for negative floats.) If the input is not a single fraction, it'll be rearranged to one. An expression mathematically equivalent to the input is returned in all cases, although it may not be the desired result if the expression contains nested floats. 

 

First 252 253 254 255 256 257 258 Last Page 254 of 395