Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

Hi,

I am trying to solve the equation below. First method was subbing in all the parameters into the equation and the second method is plugging all the parameters straight into the equation. As you can see below, they give different results. Can someone please help me? I've been scratching my head for the past hr trying to figure out what am I doing wrong.

Method 1:

Y1 := P*b*x*(-b^2+l^2-x^2)/(6*l*E*I)     

maxdeflection := subs(P = 60000, b = 2050, E = 16000, I = 3062827708, l = 6600, x = (50/3)*sqrt(47229), Y1)

=-(77224295347218906250/297)*sqrt(47229)

 

Method 2:

Y2 := (50/3)*(60000*2050)*sqrt(47229)*(6600^2-((50/3)*sqrt(47229))^2-2050^2)/(16000*(6*6600)*3062827708)

=(50426796875/1819319658552)*sqrt(47229)

 

Thank you!

Here's a slightly reduced form of a little module from some code that I posted recently:

KandR:= module()
local
   a, b, c, e, #parameters

   #procedure that lets user set parameter values:
   ModuleApply:= proc({
       a::algebraic:= KandR:-a, b::algebraic:= KandR:-b, 
       c::algebraic:= KandR:-c, e::algebraic:= KandR:-e
   })
   local k;
      for k to _noptions do thismodule[lhs(_options[k])]:= rhs(_options[k]) od;
      return
   end proc
;
end module:

The purpose of the module is simply to be a container for the four parameters and to provide a simple ModuleApply interface by which they can be set, reset, and/or unset. 

I very often use a procedure parameter of a ModuleApply to set a local variable of same name in the module. Because of the name conflict, thismodule needs to be used in these situations. I see this as the primary use of thismodule. In the module above, the purpose of the line 

for k to _noptions do thismodule[lhs(_options[k])]:= rhs(_options[k]) od;

is to avoid the need to explictly use the parameters yet a third time. First off, I am amazed that this works! I've had many disappointments with thismodule (which is essentially undocumented---its miniscule help page is nearly worthless). I am using Maple 2018, release 1. Another Maple 2018 user (not sure which release) reports that the above line gives an error (when executed) that thismodule's index must be a name.

Question 1: What's up with that?

[Edit: It's been determined that the problem was due to an unfortunate global assignment in that user's initialization file rather than different behavior of thismodule. So, I consider Question 1 to be completely answered, and it should be ignored.]

Question 2: The for loop is not entirely satisfying to me. Is there a better way?

[Status: Answered, see below.]

Question 3: Ideally, I'd like to explicity use the four parameters once, not two or three times. Is there a way? If I need to use a container for the parameters (such as a Record), to achieve that, I'd be happy to do that, and I wouldn't mind needing to invoke that container's name any number of times.

[Status: Answered, see below.]

Note that op and exports can be applied to thismodule to extract the module's operands. I have found this occasionally useful.

Question 4: What are some other good uses for thismodule? The one and only example given on its help page seems ridiculous to me.

The docs say that you can assign initial values to a record as shown in this screenshot:

I would expect the last two lines of output to be 1, 2. The slighly more complicated example in the docs does not work as expected either. This is the worksheet: queery.mw

I can assign to a record subsequently, but that makes for very prolix code,

Thanks for any help.

Hello,

I am trying to get Maple to recognize and reverse the product rule in more than one dimension. In one dimension, this works:

Int((Diff(f(x), x))*g(x)+(Diff(g(x), x))*f(x), x) = int((diff(f(x), x))*g(x)+f(x)*(diff(g(x), x)), x);

Int((Diff(f(x), x))*g(x)+(Diff(g(x), x))*f(x), x) = int((diff(f(x), x))*g(x)+f(x)*(diff(g(x), x)), x).

But in two dimensions, it no longer evaluates:

Int((Diff(f(x, y), x))*g(x, y)+(Diff(g(x, y), x))*f(x, y), x) = int((diff(f(x, y), x))*g(x, y)+f(x, y)*(diff(g(x, y), x)), x)

Int((Diff(f(x, y), x))*g(x, y)+(Diff(g(x, y), x))*f(x, y), x) = int((diff(f(x, y), x))*g(x, y)+f(x, y)*(diff(g(x, y), x)), x)

As far as I can tell, mathematically these should be identical (except for the antiderivatives being defined up to a constant in the first case and a function of y in the second). Is there a way to get Maple to reverse the product rule to integrate in more than one dimension? Or am I missing something mathematically that makes this incorrect?

Thanks for your help,

Johnathan

Problem:

Suppose you have a bunch of 2D data points which:

  1. May include points with the same x-value but different y-values; and
  2. May be unevenly-spaced with respect to the x-values.

How do you clean up the data so that, for instance, you are free to construct a connected data plot, or perform a Discrete Fourier Transform? Please note that Curve Fitting and the Lomb–Scargle Method, respectively, are more effective techniques for these particular applications. Let's start with a simple example for illustration. Consider this Matrix:

A := < 2, 5; 5, 8; 2, 1; 7, 8; 10, 10; 5, 7 >;

Consolidate:

First, sort the rows of the Matrix by the first column, and extract the sorted columns separately:

P := sort( A[..,1], output=permutation ); # permutation to sort rows by the values in the first column
U := A[P,1]; # sorted column 1
V := A[P,2]; # sorted column 2

We can regard the sorted bunches of distinct values in U as a step in a stair case, and the goal is replace each step with the average of the y-values in V located on each step.

Second, determine the indices for the first occurrences of values in U, by selecting the indices which give a jump in x-value:

m := numelems( U );
K := [ 1, op( select( i -> ( U[i] > U[i-1] ), [ seq( j, j=2..m ) ] ) ), m+1 ];
n := numelems( K );

The element m+1 is appended for later convenience. Here, we can quickly define the first column of the consolidated Matrix:

X1 := U[K[1..-2]];

Finally, to define the second column of the consolidated Matrix, we take the average of the values in each step, using the indices in K to tell us the ranges of values to consider:

Y1 := Vector[column]( n-1, i -> add( V[ K[i]..K[i+1]-1 ] ) / ( K[i+1] - K[i] ) );

Thus, the consolidated Matrix is given by:

B := < X1 | Y1 >;

Spread Evenly:

To spread-out the x-values, we can use a sequence with fixed step size:

X2 := evalf( Vector[column]( [ seq( X1[1]..X1[-1], (X1[-1]-X1[1])/(m-1) ) ] ) );

For the y-values, we will interpolate:

Y2 := CurveFitting:-ArrayInterpolation( X1, Y1, X2, method=linear );

This gives us a new Matrix, which has both evenly-spaced x-values and consolidated y-values:

C := < X2 | Y2 >;

Plot:

plots:-display( Array( [
        plots:-pointplot( A, view=[0..10,0..10], color=green, symbol=solidcircle, symbolsize=15, title="Original Data", font=[Verdana,15] ),
        plots:-pointplot( B, view=[0..10,0..10], color=red, symbol=solidcircle, symbolsize=15, title="Consolidated Data", font=[Verdana,15] ),
        plots:-pointplot( C, view=[0..10,0..10], color=blue, symbol=solidcircle, symbolsize=15, title="Spread-Out Data", font=[Verdana,15] )
] ) );

Sample Data with Noise:

For another example, let’s take data points from a logistic curve, and add some noise:

# Noise generators
f := 0.5 * rand( -1..1 ):
g := ( 100 - rand( -15..15 ) ) / 100:

# Actual x-values
X := [ seq( i/2, i=1..20 ) ];

# Actual y-values
Y := evalf( map( x -> 4 / ( 1 + 3 * exp(-x) ), X ) );

# Matrix of points with noise
A := Matrix( zip( (x,y) -> [x,y], map( x -> x + f(), X ), map( y -> g() * y, Y ) ) );

Using the method outlined above, and the general procedures defined below, define:

B := ConsolidatedMatrix( A );
C := EquallySpaced( B, 21, method=linear );

Visually:

plots:-display( Array( [
    plots:-pointplot( A, view=[0..10,0..5], symbol=solidcircle, symbolsize=15, color=green, title="Original Data", font=[Verdana,15] ),
    plots:-pointplot( B, view=[0..10,0..5], symbol=solidcircle, symbolsize=15, color=red, title="Consolidated Data", font=[Verdana,15]  ),
    plots:-pointplot( C, view=[0..10,0..5], symbol=solidcircle, symbolsize=15, color=blue, title="Spread-Out Data", font=[Verdana,15] )
] ) );

  

Generalization:

Below are more generalized custom procedures, which are used in the above example. These also account for special cases.

# Takes a matrix with two columns, and returns a new matrix where the new x-values are unique and sorted,
# and each new y-value is the average of the old y-values corresponding to the x-value.
ConsolidatedMatrix := proc( A :: 'Matrix'(..,2), $ )

        local i, j, K, m, n, P, r, U, V, X, Y:
  
        # The number of rows in the original matrix.
        r := LinearAlgebra:-RowDimension( A ):

        # Return the original matrix should it only have one row.
        if r = 1 then
               return A:
        end if:

        # Permutation to sort first column of A.
        P := sort( A[..,1], ':-output'=permutation ):       

        # Sorted first column of A.
        U := A[P,1]:

        # Corresponding new second column of A.
        V := A[P,2]:

        # Return the sorted matrix should all the x-values be distinct.
        if numelems( convert( U, ':-set' ) ) = r then
               return < U | V >:
        end if:

        # Indices of first occurrences for values in U. The element m+1 is appended for convenience.
        m := numelems( U ):
        K := [ 1, op( select( i -> ( U[i] > U[i-1] ), [ seq( j, j=2..m ) ] ) ), m+1 ]:
        n := numelems( K ):

        # Consolidated first column.
        X := U[K[1..-2]]:

        # Determine the consolidated second column, using the average y-value.
        Y := Vector[':-column']( n-1, i -> add( V[ K[i]..K[i+1]-1 ] ) / ( K[i+1] - K[i] ) ):

        return < X | Y >:

end proc:

# Procedure which takes a matrix with two columns, and returns a new matrix of specified number of rows
# with equally-spaced x-values, and interpolated y-values.
# It accepts options that can be passed to ArrayInterpolation().
EquallySpaced := proc( M :: 'Matrix'(..,2), m :: posint )

        local A, i, r, U, V, X, Y:

        # Consolidated matrix, the corresponding number of rows, and the columns.
        A := ConsolidatedMatrix( M ):
        r := LinearAlgebra:-RowDimension( A ):
        U, V := evalf( A[..,1] ), evalf( A[..,2] ):

        # If the consolidated matrix has only one row, return it.
        if r = 1 then
               return A:
        end if:

        # If m = 1, i.e. only one equally-spaced point is requested, then return a matrix of the averages.
        if m = 1 then
               return 1/r * Matrix( [ [ add( U ), add( V ) ] ] ):
        end if:

        # Equally-spaced x-values.
        X := Vector[':-column']( [ seq( U[1]..U[-1], (U[-1]-U[1])/(m-1), i=1..m ) ] ):

        # Interpolated y-values.
        Y := CurveFitting:-ArrayInterpolation( U, V, X, _rest ):    

        return < X | Y >:

end proc:

Worth Checking Out:

 


 

M := `<,>`(`<|>`(1, 2, 3), `<|>`(4, 5, 6), `<|>`(7, 8, 9))

Matrix(%id = 18446745804653824710)

(1)

b := `<|>`(10, 11, 12)

Vector[row](%id = 18446745804653819654)

(2)

M+b

Error, (in rtable/Sum) invalid input: dimensions do not match: Matrix(1 .. 3, 1 .. 3) cannot be added to Vector[row](1 .. 3)

 

``

Of course the above addition will throw an error because M and b have different dimensions. But if broadcasting was allowed, then the row vector b is added to each row in the matrix M. For example, in Python:

 

 

Is there a similar feature in Maple?


 

Download question.mw

I am working on solving a set of equations for a number of parameters, and everything looks great except that I am getting a "1." in front of the solution for a couple of variables. What does this mean? In the example below, in the solution for both d__1 and d__2, there is a "1." (3 of them in fact).

 

s1Mean := -1/(2*(-rho^2+1))*(-2*d__1/c__1)-2*rho*d__2/((2*(-rho^2+1))*c__1^.5*c__2^.5) = -2*(-(-X*beta+y)*kappa/(2*sigma)+xi__2*Z__2*gamma__1/(2*tau__2)-xi__1*Z__1/(2*tau__1))

s2Mean := -1/(2*(-rho^2+1))*(-2*d__2/c__2)-2*rho*d__1/((2*(-rho^2+1))*c__1^.5*c__2^.5) = -2*(-(-X*beta+y)*gamma__2/(2*sigma)-xi__2*Z__2/(2*tau__2))

 

meanSol := solve({s1Mean, s2Mean}, {d__1, d__2})

with maple 2015

how can type log[2](3) into

Can you help me?

Thank you very much.

log.mw

 

 Any one can help me to solve the differential equations using maple to get the velocities u ,v and pressure p for the problem mentioned below

I tried the example in BodePlot help.

restart;
with(DynamicSystems):
sys := TransferFunction( 1/(s-10) ):
BodePlot(sys);


That works OK. But, if I invoke Syrup, the example no longer works.

restart;
with(Syrup);
with(DynamicSystems):
ckt := [V, Rsrc(50), C1(15e-9), L1(15e-6), C2(22e-9), L2(15e-6), C3(22e-9), L3(15e-6), C4(15e-9), 1, Rload(50)];

TF := subs(other, V=1, v[Rload]);
sys := TransferFunction(TF);

BodePlot(sys);
I get a message "not a valid plot structure".  OK, try the example, again.

sys := TransferFunction( 1/(s-10) ):
BodePlot(sys);
I also get the "not a valid plot structure" message.

What am I doing wrong?

I have asked this before but am still confused. I have a half-dozen procedures I want to save. Don't want them in a module/package. I am using windows 10.

I just can't get the syntax correct on this.

Obviously after saving restart and load to test.

libname;
       "C:\Program Files\Maple 2018\lib", 

         "C:\Users\Ronan\maple\toolbox\CodeBuilder\lib", 

         "C:\Users\Ronan\maple\toolbox\OEIS\lib", 

         "C:\Users\Ronan\maple\toolbox\personal\lib", 

         "C:\Users\Ronan\maple\toolbox\UTF8\lib"
libdir := "C:/Users/Ronan/maple/toolbox/personal/lib";
     libdir := "C:/Users/Ronan/maple/toolbox/personal/lib"
NULL;

LibraryTools:-Save(Pedal, cat(kernelopts(homedir), "/maple/toolbox/personal/lib/Pedal.mpl"));
Error, (in LibraryTools:-Save) could not open `C:\Users\Ronan/maple/toolbox/personal/lib/Pedal.mpl\Pedal.m` for writing

 

Please tell me where I go wrong

And I have not even tried lamda in nanometers

Since theata is small I repalce sin(theta) by theta because, with units, sin did not compute

Anyone know a good reference (book/website) explaing Maple units?

Many thanks


TelescopeUnits.mw

Hi

I hope everyone is fine.

Here is a nice question :

I have an inequality ( please see maple code) if I assume a special condition (on |f(u,s)| used in the code )

how can I get an upper bound of the function |x(t)| and is the upper bound converges to zero when t goes to infinity.

Maybe this is can be done using maple because by hand up to know I can't find an upper bound which converges to zero as t goes to infinity.

Maybe, there is  a good, nice and appropriate answer using maple.

Below, please find the upper_bound.mw code.

Many thinks

 

Upper_bound.mw


 

``

restart; assume*(0 < gamma); assume*(0 < M)

(0 < gamma)*assume

 

(0 < M)*assume

(1)

abs(x(t)) <= exp(-gamma*t)*abs(x(0))+int(abs(x(s))*(int(exp(-gamma*(t-u))*abs(f(u, s)), u = s .. t)), s = 0 .. t);

abs(x(t)) <= exp(-gamma*t)*abs(x(0))+int(abs(x(s))*(int(exp(-gamma*(t-u))*abs(f(u, s)), u = s .. t)), s = 0 .. t)

(2)

assume*(int(abs(f(u, s)), u = 0 .. infinity) < M)

(int(abs(f(u, s)), u = 0 .. infinity) < M)*assume

(3)

``

 

(I*Can*get*an*upper*bound*of*abs(x(t))*when*I)*assume; int(abs(f(u, s)), u = 0 .. infinity) < M


 

Download Upper_bound.mw

I am curious how one can fine the whattype of operation in expression when two variables are actually doing difference or division operation

like

whattype(a-b);
whattype(a/b);

is there any better method to find out actually for all five operations exactly.

1. a-b;  should tell the operation is difference(substraction(`-`))
2. a+b; should tell the operation is addition(`+`)
3. a*b;  should tell the operation is multiplication(`*`)
4. a/b;  should tell the operation is division(`/`)
5. a^b;  should tell the operation is power(`^`)

I understood that maple is reading a-b as a+(-b) and same a/b as a*(1/b). but, for programing it is very much comfortable to know exactly the operation. Especially when solving partial differentiation it is easy if I know exactly.

would be very grateful if I can get this thing solved. Any suggestions and coments are welcomed and thanks in advance
 

Hi,

      I need to compute something involved with the pseudo differential operators.

https://en.wikipedia.org/wiki/Pseudo-differential_operator

Specifically, I need to calculate the inverse of a pseudo differential operator, the multiplication of two pseudo differential operators, and the n-th root of a pseudo differential operator. 

I don't know whether Maple could handle these. 

Thanks.

First 627 628 629 630 631 632 633 Last Page 629 of 2097