MapleMathMatt

367 Reputation

7 Badges

3 years, 298 days

MaplePrimes Activity


These are answers submitted by MapleMathMatt

Hi @daljit97,

I had hoped that

isolve( y^2 * z + y * z^2 = x^2 );

would work, but it didn't find any solutions.

There may well be quicker and more direct ways, but I tried these two programmatic methods, and they found solutions.

One: Find and test all possible [x,y,z]:

restart;

# Equation to be solved.
f := y^2 * z + y * z^2 = x^2;

# Variables in equation, {x,y,z}.
U := indets( f, 'name' );

# Values the variables can take.
V := [0,1];

# Create a list of all possible [x,y,z] values.
W := [ seq( seq( seq( [x,y,z], x = V ), y = V ), z = V ) ];

# Adjust W so that it is a list of terms of the form [x=a,y=b,z=c].
W := map( w -> U =~ w, W );

# Select the elements of W at which the equation is satisfied.
S := select( w -> eval( f, w ), W );

Note that another way of determining a list of all possible [x,y,z] values is to use a Cartesian product iterator:

T := combinat:-cartprod( [ seq( V, 1 .. numelems(U) ) ] );
W := [ while not T['finished'] do T['nextvalue']() end do ];

Two: Use SMTLIB:-Satisfy() to find individual solutions:

restart;

# Equation to be solved.
f := y^2 * z + y * z^2 = x^2;

# Equation to be solved, along with restrictions on the variables.
g := And( f, Or(x=0,x=1), Or(y=0,y=1), Or(z=0,z=1) );

# Initialize list of solutions.
S := [];

# Use SMTLIB:-Satisfy() to find solutions. When a solution is found, 
# add a condition to g to exclude this solution in future rounds.
do
  T := SMTLIB:-Satisfy( g );
  if T = () then
    break;
  else
    S := [ seq(S), T ];
    g := And( g, Not(T) );
  end if;
end do;

# All solutions found.
'S' = S;

 

Hi @Anthrazit,

You can use the indices command in conjuction with member:

L[ "hello" ] := "funny";
L[ "hi" ] := "not funny";

K := [ indices( L, 'nolist' ) ]; # [ "hi", "hello" ]
member( "hello", K ); # true
member( "goodbye", K ); # false

Maple 2020 introduced the hasindex command, which is more direct:

hasindex( L, "hello" ); # true
hasindex( L, "goodbye" ); # false

 

 

Hi @Anthrazit,

The condition in an "if-statement" is not simplified, like in a call to evalb(). I suggest using the verify() command, which supports units:

a := 15 * Unit( MPa );
b := 16 * Unit( N / mm^2 );
verify( a, b, units( less_than ) ); # true

Hi @MapleUser2017,

Here are a couple of options:

# Original list.
L := [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];

# Split L into pairs, i.e. [ [1,2], [3,4], ... ], and then create the ranges from the pairs.
L1 := map( `..`@op, [ ListTools:-LengthSplit( L, 2 ) ] );

# Split L into two lists, for odd and even elements, and then use zip() to create the ranges.
L2 := zip( `..`, selectremove( type, L, odd ) );

Note that the first applies to any list of even length, whereas the first takes advantage of the specific values.

Hi @wagaren ,

Another way would be to set the original expression to the desired form with undetermined coefficients, and then solve the identity for the constants:

f := cos(t)^6;
g := add( a[k] * cos(2*k*t), k = 0 .. 3 );
S := solve( identity( f = g, t ) );
h := eval( g, S );

Hi @meatboi ,

If you define a procedure for a numeric integral, you can get the plot:

G := proc( epsilon )
  int( exp( -epsilon * ( x^4 + x^2 ) ), x = -10 .. 10, numeric );
end proc:
plot( G, 0 .. infinity );

 

Assuming you're using Maple 2018, you could try the SMTLIB:-Satisfy() command. By converting the equations to a boolean expression, the retriction that a certain number of terms be 1 can be written as a condition on the sum of all the terms. For instance:

# equations/inequalities
E := [
    abs( x[1] * x[2] * x[3] ) <= 1,
    x[4] * x[5] * x[6] = 0,
    x[1] * x[4] + x[2] * x[5] + x[3] * x[6] = 1
];

# variables
V := indets( E, name );

# convert to boolean expression
f := &and( op(E), seq( &or( v=0, v=1 ), v=V ) );

# solution with two non-zero terms
SMTLIB:-Satisfy( f );

# solution with three non-zero terms
g := &and( f, add(V) > 2 );
SMTLIB:-Satisfy( g );

Hi @asa12,

This isn't quite what you're after, but it is close (I used regular indexed variables like x[1], not suffixed like x1, and Maple auto-sorted the terms, with your x1 and x2 becoming x[10] and x[11]):

restart;

phi := proc( p :: polynom(integer,x) )

    local c, f, i, q, u:

    c := 1:

    f := proc( y :: symbol, n :: posint )
        local j, Y:
        Y := [ seq( y[j], j=c..c+n-1 ) ]:
        c := c + n:
        return Y:
    end proc:

    q := collect( p, x ):
    q := evalindets( q, `&*`(posint,`^`(identical(x),posint)), u -> add( mul( f(x,op([2,2],u)) ), i=1..op(1,u) ) ):    
    q := evalindets( q, `&*`(posint,identical(x)), u -> add( f(x,op(1,u)) ) ):

    return q:

end proc:

p := 2 * x + 3 * x^3;
q := phi( f );

Hi @zjervoj97,

You can use the element-wise operator ~, or the map() function:

L1 := [-3,-2,-1,0,1,2,3];
L2 := L1^~2;
L3 := map( u -> u^2, L1 );

Hi @maple2015,

A drawback of using op(2,M) is that it won't include elements that are 0. I suggest using the indices() command instead:

restart;

M := < 1, 2; 3, 0; 0, 2 >;

# Doesn't include (2,2)=0 and (3,1)=0.
op( 2, M );

SearchMatrix := proc( A :: Matrix, x :: anything, $ )
    return select( u -> A[op(u)] = x, { indices( A ) } ):
end proc:

# { [2,2], [3,1] }
SearchMatrix( M, 0 );

 

 

 

Hi @Adam Ledger ,

Maybe it is Maple's engine security.

I received the same error when I tried the code with an existing file, but after going to "Tools" > "Options" > "Security", checking "Enable engine security", adding the file under "Readable files", and choosing to "Apply to session", Maple read the file with no error.

Hi @kumar29 ,

When you make an implicit plot in Maple, the plot structure contains an array of the points, which can be extracted and exported. For example:

p := plots:-implicitplot( x^2 + y^2 - 1, x=-1..1, y=-1..1 );
A := op( [1,1], p );
ExcelTools:-Export( A, "data.xlsx" );

Hi @Annonymouse ,

I suggest the indets() command, which returns a set of indeterminates. You can then divide these into those that are variables and those that are parameters. Please try the following:

A := [ k[a1]*C[T]*(R-x[1]-x[2])-k[d1]*x[1], k[a2]*C[T]*(R-x[1]-x[2])-k[d2]*x[2] ];

# All indeterminates.
U := indets( A, 'name' );

# Variables.
V := select( u -> type( u, 'indexed' ) and member( op( 0, u ), ['x','y'] ), U );
v := numelems( V );

# Parameters.
P := U minus V;
p := numelems( P );

Hi @student_md

If you specify the 'insequence'=true option for display(), you can create the animation. Here's my variation:

restart;

# endpoints for extension
a, b := -Pi, Pi;

# original function
f := t -> t / Pi;

# periodic extension
g := proc(t)
  option cache:
  piecewise( t > b, g(t+a-b), t < a, g(t+b-a), f(t) ):
end proc:

# constant term of Fourier series
alpha := 1/(b-a) * int( f(t), t=a..b );

# Fourier cosine coefficients
A := unapply( simplify( 2/(b-a) * int( f(t) * cos(2*Pi/(b-a)*n*t), t=a..b ) ), n ) assuming n :: posint;

# Fourier sine coefficients
B := unapply( simplify( 2/(b-a) * int( f(t) * sin(2*Pi/(b-a)*n*t), t=a..b ) ), n ) assuming n :: posint;

# Inert Fourier series
F := unapply( alpha/2 + Sum( A(n) * cos(2*Pi/(b-a)*n*t) + B(n) * sin(2*Pi/(b-a)*n*t), n=1..infinity ), t );

# Truncated series
G := proc( t, m )
  alpha/2 + add( A(n) * cos(2*Pi/(b-a)*n*t) + B(n) * sin(2*Pi/(b-a)*n*t), n=1..m ):
end proc:

# animation
M := 20:
plots:-display( seq( plot( [ 'g'(t), 'G'(t,m) ], 'tickmarks'=[piticks,[-1,1]], 'color'=[blue,red], 'thickness'=3, 'discont'=true ), m=1..M ), 'insequence'=true );

 

Hi @Dim

 

If you are using the default grading code

evalb(($ANSWER)-($RESPONSE)=0);

for a Maple-graded question, it won't mark equations as being equal, since it is comparing the difference with zero. However, this should work:

evalb(($ANSWER)=($RESPONSE));

To make the grading code more robust, you can also allow for equivalent equations:

EquivEQ := proc( A :: 'Or'(equation,algebraic), B :: 'Or'(equation,algebraic), { params :: set := {} } )
    local phi, X, Y, k, sol:
    phi := u -> `if`( type( u, 'equation' ), lhs(u) - rhs(u), u ):
    X := simplify( phi(A) ):
    Y := simplify( phi(B) ):
    sol := solve( { X = k * Y, k <> 0 }, k ):
    return is( numelems( sol ) = 1 and indets( sol ) = { k } union params ):
end proc:

EquivEQ( $ANSWER, $RESPONSE );

For an example in Maple:

f := s*Y(s)-2-3*Y(s) = 2/(s-1);
g := simplify( f );
evalb( f = g ); # false
is( f = g ); # false
EquivEQ( f, g ); # true

 

 

1 2 Page 1 of 2