Carl Love

Carl Love

28015 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Note that your sequence has 11 elements, not 10. There are several ways to do what you want.

for j to 11 do  i:= -0.5+(j-1)*0.1; array1[j]:= sin(i) end do:

array1:= Vector(11, j-> sin(-0.5+(j-1)*0.1)):

array1:= <seq(sin(i), i= -0.5..0.5, 0.1)>:

To omit the zero, it is easiest to start with the first array and then exclude the middle index. You need 10 elements.

array2:= array1[[1..5, 7..11]]:

array2:= array1[[1..5, -5..-1]]:

 

They are not equal. What makes you think that they are? There are three plus/minus signs that switch among the four roots.

Sorry, I didn't read your post carefully at first, specifically the x in the example call Test(f(x)), until Markiyan pointed out my error. So, here's my corrected Answer.  The original answer is below.

Test:= (f::patfunc(anything,nothing))-> subsop(1= 10, f):

Test(f(x));
                             f(10)

The (anything,nothing) typespec is to restrict Test to functions of one argument. That can be easily changed if you want.
Test(f(x,y));
Error, invalid input: Test expects its 1st argument, f, to be of type patfunc(anything, nothing), but received f(x, y)

If you want the following to return f(g(10)) instead, I can change it. Let me know.
Test(f(g(x)));
                             f(10)

My erroneous original answer:

You do it just the way that you just did it:

Test:= proc(f) f(10) end proc:
Test(g);
                             g(10)
Test(sin);
                            sin(10)
Test(x-> x^2);
                              100

(You can include return in your procedure if you want. I omitted it because it is superfluous in the last statement of a procedure.)

Tables are what Maple calls a "mutable" data structure. This is a difficult concept to understand.  Most data structures (such as lists and sets) are not mutable. Mutable data structures cannot be compared for equality or membership by any of the standard commands. They would have to be checked elementwise or with verify. The equality and membership tests will check for identity of tables though. Another option for comparisons is to convert tables to lists.

Here are several examples. Please study these very carefully and let me know if you have any questions. I emphasize again that this is a difficult concept to learn.

 

is(table([0=0])=table([0=0]));

false

T||(1..5):=
     table([a=0,b=0,c=0,d=0]), table([a=6,b=1,c=2,d=0]),
     table([a=6,b=5,c=5,d=7]), table([a=7,b=1,c=2,d=0]),
     table([a=8,b=8,c=8,d=8])
;

table( [( c ) = 0, ( d ) = 0, ( b ) = 0, ( a ) = 0 ] ), table( [( c ) = 2, ( d ) = 0, ( b ) = 1, ( a ) = 6 ] ), table( [( c ) = 5, ( d ) = 7, ( b ) = 5, ( a ) = 6 ] ), table( [( c ) = 2, ( d ) = 0, ( b ) = 1, ( a ) = 7 ] ), table( [( c ) = 8, ( d ) = 8, ( b ) = 8, ( a ) = 8 ] )

is(T1 = table([a=0,b=0,c=0,d=0]));

false

T:= {
     [{a,b,c,d}, T1, 8], [{a,b,c,d}, T2, 8], [{a,b,c,d}, T3, 8],
     [{a,b,c,d}, T4, 8], [{a,b,c,d}, T5, 8]
};

member([{a,b,c,d}, T1, 8], T);

true

member([{a,b,c,d}, table([a=0,b=0,c=0,d=0]), 8], T);

false

Table to list conversion procedure:

TtoL:= ex-> subsindets(subsindets(ex, name(table), op), table, x-> op(2,x));

proc (ex) options operator, arrow; subsindets(subsindets(ex, name(table), op), table, proc (x) options operator, arrow; op(2, x) end proc) end proc

TtoL(T);

{[{a, b, c, d}, [c = 0, d = 0, b = 0, a = 0], 8], [{a, b, c, d}, [c = 2, d = 0, b = 1, a = 6], 8], [{a, b, c, d}, [c = 2, d = 0, b = 1, a = 7], 8], [{a, b, c, d}, [c = 5, d = 7, b = 5, a = 6], 8], [{a, b, c, d}, [c = 8, d = 8, b = 8, a = 8], 8]}

member(TtoL([{a,b,c,d}, table([a=0,b=0,c=0,d=0]), 8]), TtoL(T));

true

 

 

Download Mutable.mw

Change product to mul in your expression. The commands add, mul, and seq are alike in that they don't evaluate their arguments until the index values are substituted; whereas their analogs sum, product, and $ act like the vast majority of Maple commands by evaluating their arguments before they are even passed to the command. In your case, the attempt to evaluate k[j], etc., before j has been assigned a value causes the error.


UnionClosure:= proc(T::set(set))
local R,Iter,k,T1;
     #Next line doesn't change the output, but potentially reduces iterations by a factor of 4.
     T1:= T minus {`union`(T[]), {}};
    Iter:= combinat:-subsets(T1);
     for k while not Iter['finished'] do R[k]:= `union`(Iter['nextvalue']()[]) end do;
    {entries}(R, 'nolist')
end proc:

Example:
UnionClosure({{1},{1,2},{3}});
           {{}, {1}, {3}, {1, 2}, {1, 3}, {1, 2, 3}}

In order for your operation to be well defined, there can be no repeats among the first elements within each list of ordered pairs. Given that, here's an example of how to do your operation. We convert the lists to tables, add the tables (essentially), and convert the result back into a list of ordered pairs.

 

restart;

with(RandomTools,Generate):

Generate two lists of distinct random numbers that will be the first elements of the ordered pairs.

(X1,X2):= '[{Generate(list(posint(range= 9), 9))[]}[]]' $ 2;

[1, 2, 4, 5, 6, 7, 8], [2, 3, 4, 8, 9]

Generate lists of second elements.

(Y1,Y2):= 'Generate(list(posint(range= 9), nops(X||k)))' $ k= 1..2;

[1, 6, 7, 7, 3, 3, 5], [3, 8, 3, 1, 1]

Form the two lists of ordered pairs.

(L1,L2):= 'zip(`[]`, X||k, Y||k)' $ k= 1..2;  

[[1, 1], [2, 6], [4, 7], [5, 7], [6, 3], [7, 3], [8, 5]], [[2, 3], [3, 8], [4, 3], [8, 1], [9, 1]]

Convert them to tables.

(T1,T2):= 'table(map(`=`@op, L||k))' $ k= 1..2:

 

Perform the desired adding operation, storing the results in a third table.

for x in indices(T1, nolist) do
     if assigned(T2[x]) then  T3[x]:= T1[x]+T2[x]  end if
end do;

Convert the resulting table into a list of ordered pairs

map([lhs,rhs], op(2,op(T3)));

[[2, 9], [4, 10], [8, 6]]

 

Download ListTableList.mw

You have entered the following equation with mod:

As far as I know, there is no provision in Maple for non-integer moduli. (I hope that someone will correct me if I am wrong about that or confirm that I am right.) Maple allows you to enter the expression because it is symbolic, and thus there's a chance that the expression will become integer when values are supplied for w and v. But that's not going to happen here. The above equation causes lengthy modp expressions to be carried through your computation. This is not the direct cause of your fsolve error, but after you correct the situation pointed out by Preben, you will eventually get an error because of the mod.

Your attached file is missing. But attemping to answer anyway, I get the different series:

series(exp(1/z), z=1);
                          3               2   13               3
exp(1) - exp(1) (z - 1) + - exp(1) (z - 1)  - -- exp(1) (z - 1)
                          2                   6                 

     73               4   167               5    /       6\
   + -- exp(1) (z - 1)  - --- exp(1) (z - 1)  + O\(z - 1) /
     24                   40                               

series(exp(z), z=1);

                          1               2   1               3
exp(1) + exp(1) (z - 1) + - exp(1) (z - 1)  + - exp(1) (z - 1)
                          2                   6                

     1                4    1                5    /       6\
   + -- exp(1) (z - 1)  + --- exp(1) (z - 1)  + O\(z - 1) /
     24                   120                              


The data matrix for most simple plots p (including the ones here) is op([1,1], p). We can take both the x and y coordinates from the first plot and take just the y coordinate column ([..,2]) from the other two. We paste the columns together with the Matrix constructor `<|>` (which is not often used in this prefix form). Putting that all together, we get the 50 x 4 Matrix via

M:= `<|>`(op([1,1], p1), map(p-> op([1,1], p)[..,2]^%T, [p2,p3])[]);

Then you can right click on it and select Export, or use ExportMatrix(...).

Note that if you use 50 points on the interval 0..1, then the spacing is 1/49, so you're not going to get nice round x values like you show in your example.

Did you mean p(max(m)) = max(n) rather than what you wrote, p(max(m)) = p(max(n))? If so, this will work:

m:= [$0..5]:  n:= [$0..9]:
M:= nops(m):  N:= nops(n):
R:= rand(N):
p:= table(m =~ [0, sort(['R()' $ M-2])[], n[-1]]);

Like this

Sum(Sum(A[i2]*A[n-i2], i2= 0..n)*
    Sum(u[j]*Sum(u[r]*u[m-1-n-j-r], r= 0..m-1-n-j), j= 0..m-1-n),
n= 0..m-1);

Ordinary division by `/` is overloaded to work correctly with mod:

s= 2503/2275 mod 1563;
                            s = 976

For your other question, put the equation just as you have it into isolve:

isolve(s = (940+1563*k)/2275);
           {k = 1420 + 2275 _Z1, s = 976 + 1563 _Z1}

Maple's Matrices and multi-dimensional Arrays should be indexed SOM[i,j]. Your second attempt didn't work because you had SOM[i][j]. This latter style of indexing will work sometimes, such as when accessing the value, but it won't work for an Array or Matrix element on the left side of the assignment operator (:=). Unfortunately, it doesn't produce an error message either.

Your first attempt didn't work because your initializer wasn't a procedure. Markiyan's answer shows how to correct that.

You can use the regular plot command to plot any procedure that takes a real numeric argument and returns a real numeric value. The procedure could encapsulate your fsolve call. Like this:

f:= proc(x)
   local y;
   fsolve(sin(y)=x, y= -Pi/2..Pi/2)
end proc:

plot(f, -0.9..0.9);

First 370 371 372 373 374 375 376 Last Page 372 of 394