[go: up one dir, main page]

Items tagged with list

Feed App Center
Also available: list

I am writing a small code to find median and mean. The code works for an even number of terms, not for an odd number of terms. I tried to find the error but cannot.

restart:medianmean:= proc(x) local a,b,c,d,m,g;
a:=sort(x); b:=nops(x); c:=nops(x)/2; d:=(nops(x)+1)/2;
m:=(a[c]+a[c+1])/2; g:=add(a)/b;
if (b mod 2 = 0) then evalf([a,m,g]) ;
else evalf([a,a[d],g]);
end if; end proc:

 


The command L2(1,2) etc (statements 5 to 8) all are considered as valid and gives the complete list as the answer. Can anyone interpret the behaviour and logic behind the maple answers?

s := [1], [2]

[1], [2]

(1)

L2 := [s]

[[1], [2]]

(2)

type(L2, listlist)

true

(3)

L2__1

L2__1

(4)

"Following commands  give the list L2, which in my opinion is wrong."

L2(1)

[[1], [2]]

(5)

L2(1, 1)

[[1], [2]]

(6)

L2(1, 2)

[[1], [2]]

(7)

L2(2, 2)

[[1], [2]]

(8)

``

L2[2]

[2]

(9)

L2[1][2]

Error, invalid subscript selector

 

``


 

Download Doubt1.mw

Hi,

how do I make second power of integers in a list?

e. g.: L1:=[-3,-2,-1,0,1,2,3]

and i want

L2:=[9,4,1,0,1,4,9]

Thanks

I have two lists, A and B, with the same number of elements and I want A to be on the Y-axis and B on the X-axes and do a point plot

Given a list with sublists e.g.

[[a,b],[[c,d,e]]]

is there a way of merging everything into a single list, for example

[a,b,c,d,e]

I want to learn about why sometimes different algebraic expressions are ordered differently, and what would be the best way to instruct maple to chose a different "rule" for which a set of arithmetic functions are ordered, while still maintaining the axiom of uniqueness. 

 

I figured this would be accomplished on a case by case basis, and it may involve just using lists instead,defining a procedure to produce the desired ordering for any given set of functions, and using the "remove" command to replace the set "difference" operator and the Join command for the lists in place of the union operator. Then of course using the "Remove Duplicates" option from ListTools to impose the axiom of unique elements. 

 

Is this the best way to go about this, or is there a much simpler way, that includes an abstract algebra package that I'm unaware of thus far?

Hi, my problem is that I have a set of variables stored in a list, then when I try to sum with differentiation inside the sum, Maple immediately tries to differentiate before summing, thus returning zero.

 

So I define a list coords := [t, r, theta, varphi], then call sum(diff(r^2, coords[k]), k = 1 .. 4), however Maple does the differentiation first, so it becomes 0 instead of 8r.

 

I attached the maple worksheet with what I did, on the first line I define the list with variables, on the second line I show that maple evaluates diff(r^2, coords[k]) to zero before doing the sum, where k is what is being summed over, on the third line I show that it copes fine if a specific element of the list is called, on the fourth line I show that summation over elements of the list is fine, and the last two lines show an example of the kind of thing I would like to do

 

Is there a way to make this work?

Hello everyone,

 

I am currently trying to plot lines from different lists.

I got 3 lists with points and another 3 lists with points (Connect each point from one list with the other), and another list with my x-axis.

 

I tried something like that

(nply in this case is 4)

for i from 1 to nply do

sigma1P1[i] := display(line([grenzeu[i], sigma1unter[i]], [grenzeo[i], sigma1ober[i]])):

sigma2P1[i] := display(line([grenzeu[i], sigma2unter[i]], [grenzeo[i], sigma2ober[i]])): 

tau12P1[i] := display(line([grenzeu[i], tau12unter[i]], [grenzeo[i], tau12ober[i]])):

end do:
plot:-display(sigma1P1,sigma2P1,tau12P1);

The for loop creates 3 tables with 4 line plots, but the plot:-display(sigma1P1,sigma2P1,tau12P1);

gives me this Error message:

Error, `plot` does not evaluate to a module

Have anyone an idea how to get these 3 table with plots in one plots?

Plot_problem.mw

And if yes is it possible to implement this in a EMbedded Plot Window?

 

Many thanks in advance!

 

 

 

I want to check that all entries in a list are of some value. Say 0. (or in general, if all entries satisfy some condition).

So, If any entry is not zero, then it returns false. It returns true only if all elements meet this conditions.

What would be the right way to do this in Maple? I know I could write a loop. But I am asking if there is a build-in function in Maple. Here is an example

ode:=y(x)*diff(y(x),x)=x*(y(x)^2+2):
sol:= dsolve(ode,y(x)):
check:=map(z->odetest(z,ode1),[sol]);

                       check := [0, 0]

I want to check that all entries in check are zero. This tells me all my solution are correct.

I can't use member(check,0) since this only check if at least one entry is zero. I want to chek that all entries are zero.

In Mathematica, it has AllTrue function. Like this

check = {0, 0, 0};
AllTrue[check, # == 0 &]

     True

The "#==0&"  is the test to do. It uses this test on each element automatically. If all satisfy this test, then it returns true.

Again, I can easily write a small function in Maple to do this,

alltrue :=proc(arr,value)
    local z;
    for z in arr do
        if z<>value then
           return(false);
        fi;
    od;
    return(true);
end proc:

alltrue(check,0) return true.

But I am asking if there is a build-in such function similar to the above one in Mathematica, which accepts a more general test function to use.

What is the best way to check if solve returned one or more solution? Currently I check if the returned sol is of type exprseq, and if so, I put the result in a list. If the sol is not of type exprseq, then I know only one solution is returned. Here is an example

foo:=proc(eq,x)
  local sol;
  sol:=solve(eq,x);
  if whattype(sol)='exprseq' then
     sol:=[sol];
  fi;
  return(sol);
end proc:

And now

Is there better way to do this?

 

1-Write a Maple ProcInserer procedure (x, pos, L) that inserts the element x into L at position pos.
 2- Write an inverse procedure (L) taking as argument a list L and returning the list obtained by inverting L in the decreasing direction of the indices.

I have a list of relationships between variables, in this example there are three. The second of these requires one of the parameters to have a relationshipo that is not allowed with one of the other parmaters i.e. k[d2] = k[d1]; the rule is a parameter without h in its name can only be equated to itself or an expression with at least one parameter with h in its name.

How can I eliminate sets with relationships that break this rule?



Sa1 := [{R = R, Rh = R, C[T] = Ch[T]*kh[a1]/k[a2], Ch[T] = Ch[T], k[a1] = kh[a2]*k[a2]/kh[a1], k[a2] = k[a2], k[d1] = k[d1], k[d2] = k[d2], kh[a1] = kh[a1], kh[a2] = kh[a2]}, {R = R, Rh = R, C[T] = C[T], Ch[T] = Ch[T], k[a1] = -(C[T]*k[a2]-Ch[T]*kh[a1]-Ch[T]*kh[a2])/C[T], k[a2] = k[a2], k[d1] = k[d1], k[d2] = k[d1], kh[a1] = kh[a1], kh[a2] = kh[a2]}, {R = R, Rh = Rh, C[T] = C[T], Ch[T] = Ch[T], k[a1] = -k[a2], k[a2] = k[a2], k[d1] = k[d1], k[d2] = k[d1], kh[a1] = -kh[a2], kh[a2] = kh[a2]}]

A:={4,5,6,-9};
                          A := {4, 5, 6, -9}

E:={a,a,-2,4,-6};
                         E := {-2, 4, -6, a}

how does maple treat sets , and  what is the diffrence between sets and lists ?

The set and list produced by map (see below) contain duplicates.  How to remove duplicates?
 

p := (1+5^(1/2))*(1/2)

1/2+(1/2)*5^(1/2)

(1)

with(Bits)

[And, FirstNonzeroBit, GetBits, Iff, Implies, Join, Nand, Nor, Not, Or, Settings, Split, String, Xor]

(2)

with(LinearAlgebra)

[`&x`, Add, Adjoint, BackwardSubstitute, BandMatrix, Basis, BezoutMatrix, BidiagonalForm, BilinearForm, CARE, CharacteristicMatrix, CharacteristicPolynomial, Column, ColumnDimension, ColumnOperation, ColumnSpace, CompanionMatrix, CompressedSparseForm, ConditionNumber, ConstantMatrix, ConstantVector, Copy, CreatePermutation, CrossProduct, DARE, DeleteColumn, DeleteRow, Determinant, Diagonal, DiagonalMatrix, Dimension, Dimensions, DotProduct, EigenConditionNumbers, Eigenvalues, Eigenvectors, Equal, ForwardSubstitute, FrobeniusForm, FromCompressedSparseForm, FromSplitForm, GaussianElimination, GenerateEquations, GenerateMatrix, Generic, GetResultDataType, GetResultShape, GivensRotationMatrix, GramSchmidt, HankelMatrix, HermiteForm, HermitianTranspose, HessenbergForm, HilbertMatrix, HouseholderMatrix, IdentityMatrix, IntersectionBasis, IsDefinite, IsOrthogonal, IsSimilar, IsUnitary, JordanBlockMatrix, JordanForm, KroneckerProduct, LA_Main, LUDecomposition, LeastSquares, LinearSolve, LyapunovSolve, Map, Map2, MatrixAdd, MatrixExponential, MatrixFunction, MatrixInverse, MatrixMatrixMultiply, MatrixNorm, MatrixPower, MatrixScalarMultiply, MatrixVectorMultiply, MinimalPolynomial, Minor, Modular, Multiply, NoUserValue, Norm, Normalize, NullSpace, OuterProductMatrix, Permanent, Pivot, PopovForm, ProjectionMatrix, QRDecomposition, RandomMatrix, RandomVector, Rank, RationalCanonicalForm, ReducedRowEchelonForm, Row, RowDimension, RowOperation, RowSpace, ScalarMatrix, ScalarMultiply, ScalarVector, SchurForm, SingularValues, SmithForm, SplitForm, StronglyConnectedBlocks, SubMatrix, SubVector, SumBasis, SylvesterMatrix, SylvesterSolve, ToeplitzMatrix, Trace, Transpose, TridiagonalForm, UnitVector, VandermondeMatrix, VectorAdd, VectorAngle, VectorMatrixMultiply, VectorNorm, VectorScalarMultiply, ZeroMatrix, ZeroVector, Zip]

(3)

with(VectorCalculus)

[`&x`, `*`, `+`, `-`, `.`, `<,>`, `<|>`, About, AddCoordinates, ArcLength, BasisFormat, Binormal, Compatibility, ConvertVector, CrossProduct, Curl, Curvature, D, Del, DirectionalDiff, Divergence, DotProduct, Flux, GetCoordinateParameters, GetCoordinates, GetNames, GetPVDescription, GetRootPoint, GetSpace, Gradient, Hessian, IsPositionVector, IsRootedVector, IsVectorField, Jacobian, Laplacian, LineInt, MapToBasis, Nabla, Norm, Normalize, PathInt, PlotPositionVector, PlotVector, PositionVector, PrincipalNormal, RadiusOfCurvature, RootedVector, ScalarPotential, SetCoordinateParameters, SetCoordinates, SpaceCurve, SurfaceInt, TNBFrame, Tangent, TangentLine, TangentPlane, TangentVector, Torsion, Vector, VectorField, VectorPotential, VectorSpace, Wronskian, diff, eval, evalVF, int, limit, series]

(4)

b := proc (x, w) options operator, arrow; (-1)^GetBits(x, w, output = number) end proc

proc (x, w) options operator, arrow; (-1)^Bits:-GetBits(x, w, output = number) end proc

(5)

l := proc (x, t, u, v) options operator, arrow; frac(x)*Vector([b(floor(x), 0)*t, b(floor(x), 1)*u, b(floor(x), 2)*v])+(1-frac(x))*Vector([b(floor(x), 0)*v, b(floor(x), 1)*t, b(floor(x), 2)*u]) end proc

proc (x, t, u, v) options operator, arrow; VectorCalculus:-`+`(VectorCalculus:-`*`(frac(x), VectorCalculus:-Vector([VectorCalculus:-`*`(b(floor(x), 0), t), VectorCalculus:-`*`(b(floor(x), 1), u), VectorCalculus:-`*`(b(floor(x), 2), v)])), VectorCalculus:-`*`(VectorCalculus:-`+`(1, VectorCalculus:-`-`(frac(x))), VectorCalculus:-Vector([VectorCalculus:-`*`(b(floor(x), 0), v), VectorCalculus:-`*`(b(floor(x), 1), t), VectorCalculus:-`*`(b(floor(x), 2), u)]))) end proc

(6)

map(l, {0, 1, 2, 3, 4, 5, 6, 7, 8}, 0, 1, p)

{Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian])}

(7)

map(l, [0, 1, 2, 3, 4, 5, 6, 7, 8], 0, 1, p)

[Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian])]

(8)

q := ListTools:-MakeUnique(%)

q := [Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian])]

(9)

Equal(q[1], q[9])

true

(10)

qq := [op({q[]})]

qq := [Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian])]

(11)

LinearAlgebra:-Equal(qq[1], qq[5])

true

(12)

NULL


 

Download cp.mw

Hello, i need to remove specific elements of a list but cannot do so with the conversion to a set and the use of the difference operation, because there are other repeatitions that are important so i cannot impose the condition of uniqueness in the process of excluding these elements, and want to keep other repeatitions in the original multiset.

I know this must be fairly straight forward because the "Remove Duplication" function retains the order of the original multiset

 

EDIT: i seem to have found a way to it using the "SearchAll" function from the ListTools package, so i can then reconstruct a second list by specifying a set of sequence ranges paritioned accordingly to the indices of the elements of the original i want removed that are obtains using this "SearchAll" function

5 6 7 8 9 Page 7 of 9