Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

Hi Maple friends,

Id like to create an animation that rotates my 3d plot. Here is the file: https://www.dropbox.com/scl/fi/zop0jpid0ik0a1unxrzzn/Dynamisches_Modell_Final_filled_conts-1.mw?rlkey=eo482ihqw9pw3vn6qolnxlrwa&dl=0

This is the 3d plot:

plot3d([Vth - Vps], E = 0 .. 1000000, T = 0 .. 15, labels = ["E in (EUR)", "T (in Jahren)", "V (in EUR)"], view = 0 .. 180000, labelfont = [times, bold, 12]);

The starting view should be the following (ankle: -137, 74, -2):

After rotation, tId like to see this view (ankle: 180, 0, 180):

Can someone please help me with this issue? That would be so nice!!

Thanks a lot in advance and best regards
Rebekka

 Dear Sir/Madam,

I have faced a problem while using Maple 18. The  warning is the following

Error, (in f) unable to store 'HFloat(1.9648999999999983)-HFloat(500.0)*delta' when datatype=float[8]
Error, (in plots/odeplot) input is not a valid dsolve/numeric solution



#` Part(a)`  deSh := diff(Sh(t),t) = (alpha(h)*Nh) +(omega*Rh(t))- (((betahb*Iv(t))/(Nh) +p+ mu(h))*Sh(t));   deEh :=  diff(Eh(t),t) =  (((betahb*Iv(t))/(Nh) )*Sh(t))-((mu(h)+gamm)*Eh(t));   deIh := diff(Ih(t),t) = (gamm*Eh(t))-(theta+mu(h)+delta)*Ih(t);  deRh := diff(Rh(t),t) = (delta*Ih(t))-((mu(h)+omega)*Rh(t));  deSv := diff(Sv(t),t) =  (alpha(m)*Nv*(1-Nw/(Nm)))-(((betamb*Ih(t))/(Nh) +mu(m))*Sv(t));  deEv:=diff(Ev(t),t) =  (((betamb*Ih(t))/(Nh) )*Sv(t))-((mu(m)+delta(m))*Ev(t));  deIv:= diff(Iv(t),t) = (delta(m)*Ev(t))-(mu(m)*Iv(t));   mu(h):= .000045 :   Nh:=5071126:  betahb:=.750:  p:=.09 :  omega:=.001:  alpha(h):=.5:  gamm:=.1667 :  delta :=.328833:  theta:= .0000002:  alpha(m) :=.1167:    Nv :=40570:  Nw:= 10000:  Nm:=50570:   betamb := .375 :  mu(m) := .02941:  delta(m):= .1428:     u:= .5:   F := dsolve( {deSh, deEh,deIh,deRh,deSv,deEv,deIv,  Sh(0)=8500,Eh(0)=100,Ih(0)=500,Rh(0)=0,Sv(0)=3500,Ev(0)=500,Iv(0)=570},     { Sh(t),Eh(t),Ih(t),Rh(t),Sv(t),Ev(t),Iv(t) } , numeric );  with(plots):  odeplot( F, [[t,Sh(t)],[t,Eh(t)] ,[t,Ih(t)],[t,Rh(t)],[t,Sv(t)],[t,Ev(t)],[t,Iv(t)]], t=0..30, numpoints=100, colour=[black,blue,purple, red,green,yellow,orange] , legend = ["suspectible host", "exposed host", "infected host", "recovered host","suspectible  vector","exposed vector"," infected vector"]);
 


Hello everyone, I am working on a Maple code where I am dealing with a matrix X and performing several operations, so I can subsitute a set of lists. However, I feel Im doing some redundant things and I wonder if there are ways to make it more concise and efficient. More specifically,

  1. 'vals' and 'ecs' :
    'vals' gives me a set of lists with the values I'll use in matrix X , e.g., vals := {[-1, 1, 0], [0, -1, -1], [0, -1, 1]}.
    'ecs' creates a set of lists of equations that I can use in 'eval' (or 'subs') function, e.g., ecs := {[[X3_4 = -1, X3_3 = 1, X2_3 = 0]], [[X3_4 = 0, X3_3 = -1, X2_3 = -1]], [[X3_4 = 0, X3_3 = -1, X2_3 = 1]]}.
    But clearly, I'm getting an extra pair of brackets for each list so I will need to use double index in the eval command. Is there a way to avoid this?
  2. In the subsitution step, I've tried with both 'eval' and 'subs' and many modifications to avoid what I did in step 1 but without success. Also I need this extra 'Nelem' to get a list of indices so I can substitute all possible lists of values in 'ecs'.
  3. Finally, I'm wondering if what I'm getting from 'BoolEigs' is actually what I want. My final goal is to check if the eigenvalues of all possible solution matrices I got in 'Xs'  are nonnegative. So I need to avoid numerical computations and perform this step exactly. Is my code correct for this?
     
X := Matrix([[1, -X3_3/2 - 1/2, 0, -X2_3], [-X3_3/2 - 1/2, -2*X3_4 - 1, X2_3, 0], [0, X2_3, X3_3, X3_4], [-X2_3, 0, X3_4, 1]]);
vars := [X3_4, X3_3, X2_3];

w := A^3 - A;
rootz := RootOf(w, A);
Pols := [(-A^2 + 1)/(3*A^2 - 1), (-A^2 - 1)/(3*A^2 - 1), A*(3*A^2 - 1)*1/(3*A^2 - 1)];

vals := {allvalues(eval(Pols, A = rootz))};
ecs := map(x -> convert(vars = x, listofequations), vals);

Nelem := [seq(k, k = 1 .. numelems(vals))];
Xs := map(x -> eval(X, ecs[x][1]), Nelem);#double index for eval
Xz := map(x -> subs(ecs[x][1], X), Nelem);#same for subs

with(LinearAlgebra);
Eigs := map(x -> Eigenvalues(x), Xs);
BoolEigs := map(x -> map(y -> is(Im(y) = 0) and is(0 <= Re(evalf(y))), x), Eigs);
evalf(Eigs);

I have been inspired by videos at this site: (1) Vorperian's Electronic Circuits Courses - YouTube

In these lectures, he shows an example of calculating the resistance of 2 series pairs of resistors in parallel, which is given by

(R3 + R4)*(R1 + R2)/(R1 + R2 + R3 + R4)  Eq1

This expression can be simplified, using the parallel operator (sometimes also referred to as the "reciprocal formula" or "harmonic sum") see Parallel (operator) - Wikipedia

`//` := (R1, R2) -> R2*R1/(R1 + R2)

Simplification 
`//`(R1, R2)*`//`(R3, R4)     EQ 2

This is easier to understand EQ2 compared to EQ1
1. Is there a way to display the function as a binary operator as in R1`//`R2 ?

2. Is there a way to add the parallel operator to the simplification procedure?

The videos referenced above go into more complex expressions that I would like to explore, but this seems like the first step.

point(A, xA, yA);
point(B, xB, yB);
point(C, xC, yC):
L3 := linestyle = 3
triangle(Tr, [A, B, C])
line(AP, [A, P]);
line(BP, [B, P]);
line(CP, [C, P]);
dr := draw([Tr(t3), AP(cbl, L3), BP(cbl, L3), CP(cbl, L3)]),
textplot([[coordinates(A)[], "A"], [coordinates(B)[], "B"], [coordinates(C)[], "C"]], align = {above, right});
display({dr, ellip}, scaling = constrained, axes = none, view = [-1 .. 14, -1 .. 11]);
Why doesn’t Maple show me the expected effect ? Thank you.

Hello, I am trying to refine my solid with some visual details. How can I draw the arcs (in 3D) that represent the angles of triangle ABC? Thank you.ConeTestLayout.mw

 

Just for my understanding

x^ln(x)-c;
solve(%,x,allsolutions);
indets((%));
print("but here it does:");
indets(%[-1])
                            ln(x)    
                           x      - c

                           /   ln(_Z)    \
                     RootOf\-_Z       + c/

          /     ln(_Z)        /   ln(_Z)    \        \ 
         { c, _Z      , RootOf\-_Z       + c/, ln(_Z) }
          \                                          / 

                      "but here it does:"

                          {_Z, ln(_Z)}

I have entered a few examples from the Maple Example Worksheets on the the topic of using compiled Fortran code. I got two simple examples to work as shown in my worksheet below. The third example was to perform a matrix multiplication and that is where I get the "Error, (in fmat_mult) unhandled return type". Could you point out my mistake? Thank you in advance.

Using compiled FORTRAN code:

 

1) write a FORTRAN function in Geany

2) compile it to an object file *.o

2) open terminal in the folder where the file is saved

3) generate a *.dll file by: gfortran -shared -o mult.dll mult.o

4) setup the call to your functions: see lines fmult:= define_external( ) and fmultf:= define_external( ).

 

restart:
kernelopts(version);

`Maple 2023.2, X86 64 WINDOWS, Nov 24 2023, Build ID 1762575`

(1)

 

Multiply two integers

 

fmult:=define_external('mult', LIB= "C:/Users/familee/OneDrive/Documents/Maple/DLL-example/mult.dll", FORTRAN, 'a'::(integer[4]), 'b'::(integer[4]), RETURN::(integer[4]))

(2)

 

Multiply two floating point numbers

 

fmultf:=define_external('multf', LIB= "C:/Users/familee/OneDrive/Documents/Maple/DLL-example/multf.dll", FORTRAN, 'a'::(float[8]), 'b'::(float[8]), RETURN::(float[8]))

fmult(10,3)

30

(3)

fmultf(10.1,3.3)

33.3299999999999983

(4)

fmultf(100.234,67.901)

6805.98883399999886

(5)

 

Matrix multiplication example

 

a:=Matrix([[1.,4.,7.],[2.,5.,8.],[3.,6.,9.]],datatype=float[8],order=Fortran_order);

Matrix(3, 3, {(1, 1) = 1.0, (1, 2) = 4.0, (1, 3) = 7.0, (2, 1) = 2.0, (2, 2) = 5.0, (2, 3) = 8.0, (3, 1) = 3.0, (3, 2) = 6.0, (3, 3) = 9.0})

(6)

b:=Matrix([[1.,4.,7.],[2.,5.,8.],[3.,6.,9.]],datatype=float[8],order=Fortran_order);

Matrix(3, 3, {(1, 1) = 1.0, (1, 2) = 4.0, (1, 3) = 7.0, (2, 1) = 2.0, (2, 2) = 5.0, (2, 3) = 8.0, (3, 1) = 3.0, (3, 2) = 6.0, (3, 3) = 9.0})

(7)

c:=Matrix(1 .. 3, 1 .. 3, fill = 0.,datatype=float[8],order=Fortran_order);

Matrix(3, 3, {(1, 1) = 0., (1, 2) = 0., (1, 3) = 0., (2, 1) = 0., (2, 2) = 0., (2, 3) = 0., (3, 1) = 0., (3, 2) = 0., (3, 3) = 0.})

(8)

a.b

Matrix(3, 3, {(1, 1) = 30.0, (1, 2) = 66.0, (1, 3) = 102.0, (2, 1) = 36.0, (2, 2) = 81.0, (2, 3) = 126.0, (3, 1) = 42.0, (3, 2) = 96.0, (3, 3) = 150.0})

(9)

 

Is it possible to use a subroutine to pass a matrix?

 

mat_mult,f subroutine returns c = a.b

 

FORTRAN code for mat_mult.f

 

       SUBROUTINE mat_mult(a,b,c,m,n)  
C
C      Compute matrix multiplication.
C
       INTEGER i,j,k
       INTEGER m,n
       
       REAL*8 tmp
C      m rows by n cols
       REAL*8 a(m,n)
       REAL*8 b(m,n)
       REAL*8, intent (out)::c(m,n)
C      m = n
       DO 11 j=1,n
         DO 12 i=1,n
            tmp = 0.0
            DO 13 k=1,n
               tmp = tmp + a(i,k) * b(k,j)
 13         CONTINUE
            c(i,j) = tmp
 12      CONTINUE
 11    CONTINUE
       RETURN
       END

Compiled to get the object file: mat_mult.o

Generate a dll: gfortran -shared -o mat_mult.dll mat_mult.o

 

fmat_mult:=define_external( 'mat_mult', LIB= "C:/Users/familee/OneDrive/Documents/Maple/DLL-example/mat_mult.dll", FORTRAN, 'a'::(ARRAY(datatype=float[8])), 'b'::(ARRAY(datatype=float[8])), 'c'::(ARRAY(datatype=float[8])), 'm'::(integer[4]), 'n'::(integer[4]), RETURN::(ARRAY(datatype=float[8])) )

(10)

 

The results should be the Matrix c

 

fmat_mult(a,b,c,3,3)

Error, (in fmat_mult) unhandled return type

 

 

mult-Fortran_dll.mw

 

How do  I solve system of differential equations in finite difference method or finite element method?

eq1 := (diff(f(x), x, x, x))*(a*beta*f(x)^2-1)+(diff(f(x), x))^2-2*a*beta*f(x)*(diff(f(x), x))*(diff(f(x), x, x))+(diff(f(x), x))*(M+k[1])-(diff(f(x), x, x))*f(x)-(alpha*theta(x)+delta*phi(x))/rho = 0;

eq2 := -(diff(theta(x), x, x))*K[SB]*(Df-(Rd+k[hnf]/k[bf])/Pr)+N[t]*K[SB]*(diff(theta(x), x))^2-N[b]*(diff(theta(x), x))*(diff(phi(x), x))-(diff(f(x), x))*(diff(theta(x), x))-lambda*theta(x)-mu*Ec*(M*(diff(f(x), x))^2+(diff(f(x), x, x))^2) = 0;

eq3 := diff(phi(x), x, x)+Le*Sr*(diff(theta(x), x, x))+Le*f(x)*(diff(phi(x), x)) = 0;

ics := f(0) = 0, (D(f))(0) = 0, theta(0) = 1, phi(0) = 1;

bcs := (D(f))(100) = 0, theta(100) = 0, phi(100) = 0;


Parameters1 := rho = 2063.905, k[hnf] = .29942, k[bf] = .2520, mu = .38694, a = .1, beta = 5, k[1] = 2.0, M = 10, alpha = 20, delta = 20, K[SB] = .5, Df = 3, Pr = 1.2, Rd = 5, N[t] = 1.2, N[b] = 1.0, lambda = 1.5, Ec = 5, Le = .1, Sr = .1;

 

How to solve delay differential equations in maple?

restart;
with(PDETools);
eq1 := (D(x))(t) = 2*a[4]*y(t)-c[1]*z(t)*x(t)-d[2]*x(t)-a[1]*x(t-tau);

eq2 := (D(y))(t) = a[1]*x(t-tau)-d[3]*y(t)-a[4]*y(t)-c[3]*z(t)*y(t)-k[1]*(1-exp(-k[2]*w(t)))*y(t);

eq3 := (D(z))(t) = K+rho*z(t)*(x(t)+y(t))^3/(alpha+(x(t)+y(t))^3)-c[2]*z(t)*x(t)-c[4]*y(t)*z(t)-d[1]*z(t)-k[3]*(1-exp(-k[4]*w(t)))*z(t);

eq4 := (D(w))(t) = -gamma*w(t);


ics := x(0) = 1, y(0) = 1, z(0) = 1, w(0) = 1;

Parameters := a[1] = .84, a[4] = .91, c[1] = 7.56*10^(-2), c[3] = 7.56*10^(-2), c[2] = 3.422*10^(-4), c[4] = 3.422*10^(-4), d[1] = 0.4e-1, d[2] = .11, d[3] = .66, K = 0.37e-1;

 

Is there a way to do calculations with tensors on arbitrary smooth manifolds without fixing a dimension and/or a coordinate system? (things like tensor products, contractions, covariant derivatives, Lie derivatives, exterior calculus, Riemann Tesnsor, torsion tensor,...)

The physcis package (thougfh really good otherwise)  always needs a dimension and a metric, default being 4 dimesnion and Minkowski, metric "arbitrary" is not an option since dimension must still be fixed and calculations become extremely slow and cluttered for very low dimesnional manifolds.

The DifferentialGeometry seems to always need a fixed dimension and a coordinate system. Or am I overlooking some options? 


I would need a solution for either using only geometric objects or an abstract index notation a la Wald (ideally without assuming holonomic bases). 

The only external package I could find is tensorpack, but this seems to be no longer maintained and depends on other packages (Riemann, Canon) which seem to be no longer maintained as well, and it has some drawbacks, e.g. consistent handling of dummy indices is not enforced (e.g. renaming when a conflict arises)

Is there any solution?


dS := -beta*S*Q;
dQ := Q*S*beta - Q*alpha;
dR := alpha*Q;
beta := 0.2;
alpha := 0.1;
S0 := 0.8;
Q0 := 0.2;
R0 := 0;
RungeKutta := proc(f::list, y0::list, t0::float, tf::float, h::float) local n, t, y, k1, k2, k3, k4, i; n := 1 + floor((tf - t0)/h); t := Vector(n, fill = 0); y := Matrix(n, length(y0), fill = 0); t[1] := t0; y[1] := Vector(y0); for i to n - 1 do k1 := Vector(map(f, t[i], y[i])); k2 := Vector(map(f, t[i] + 1/2*h, y[i] + 1/2*h*k1)); k3 := Vector(map(f, t[i] + 1/2*h, y[i] + 1/2*h*k2)); k4 := Vector(map(f, t[i] + h, y[i] + h*k3)); y[i + 1] := y[i] + 1/6*h*(k1 + 2*k2 + 2*k3 + k4); t[i + 1] := t[i] + h; end do; [t, y]; end proc;
f = [dS, dQ, dR];
t0 := 0;
tf := 50;
h := 0.1;
result := RungeKutta(f, [S0, Q0, R0], t0, tf, h);
t_values := result[1];
S_values := result[2][() .. (), 1];
Q_values := result[2][() .. (), 2];
R_values := result[2][() .. (), 3];
plots:-display(plot(t_values, S_values, color = "blue", legend = "Susceptible"), plot(t_values, Q_values, color = "red", legend = "Infected"), plot(t_values, R_values, color = "green", legend = "Recovered"), legend = ["Susceptible", "Infected", "Recovered"], title = "Simulation of Infectious Disease Model", xlabel = "Time", ylabel = "Population", view = [0 .. tf, 0 .. 1]);
Warning, (in RungeKutta) `i` is implicitly declared local
                         dS := -0.2 S Q

                     dQ := 0.2 S Q - 0.1 Q

                          dR := 0.1 Q

                          beta := 0.2

                          alpha := 0.1

                           S0 := 0.8

                           Q0 := 0.2

                            R0 := 0

RungeKutta := proc (f::list, y0::list, t0::float, tf::float, 

   h::float) local n, t, y, k1, k2, k3, k4, i; n := 1+floor((tf-\

  t0)/h); t := Vector(n, fill = 0); y := Matrix(n, length(y0), 

   fill = 0); t[1] := t0; y[1] := Vector(y0); for i to n-1 do 

   k1 := Vector(map(f, t[i], y[i])); k2 := Vector(map(f, 

   t[i]+(1/2)*h, y[i]+(1/2)*h*k1)); k3 := Vector(map(f, 

   t[i]+(1/2)*h, y[i]+(1/2)*h*k2)); k4 := Vector(map(f, t[i]+h, 

   y[i]+h*k3)); y[i+1] := y[i]+(1/6)*h*(k1+2*k2+2*k3+k4); 

   t[i+1] := t[i]+h end do; [t, y] end proc


[-0.2 S Q, 0.2 S Q - 0.1 Q, 0.1 Q] = [-0.2 S Q, 0.2 S Q - 0.1 Q, 

  0.1 Q]


                            t0 := 0

                            tf := 50

                            h := 0.1

Error, invalid input: RungeKutta expects its 3rd argument, t0, to be of type float, but received 0
                     t_values := result[1]

               S_values := result[2][() .. (), 1]

               Q_values := result[2][() .. (), 2]

               R_values := result[2][() .. (), 3]

Warning, expecting only range variable result[2][(NULL) .. (NULL),1] in expression result[1] to be plotted but found name result[1]
Warning, expecting only range variable result[2][(NULL) .. (NULL),2] in expression result[1] to be plotted but found name result[1]
Warning, expecting only range variable result[2][(NULL) .. (NULL),3] in expression result[1] to be plotted but found name result[1]
Error, (in plots:-display) unexpected options: [xlabel = "Time", ylabel = "Population"]

I want to center align all the math in my document. I have not been able to find a shortcut key for alignment, and I cannot find a default setting for alignment anywhere. I don't want to mouse click every single time.

Please help, thanks!

Howdy,

I am trying to do explicit Lie algebra computations, and I am not sure the best way to automate these.

Suppose I have a Lie algebra with basis e1 through e8, and I have some linear functions:

f(e1,e2) = c1e1+c2e2+...+c8e8

Now suppose I want to compute something like

[e5, f] - f([e5,e1],e2) + f([e5,e2],e1), or more generally x.f with the typical module structure.

I can do this line by line - say [e5,e1] = -e1 and [e5,e2] = 0, then I can ask Maple for LieBracket(e5,f)+f(e1,e2)-0. However, I'd like to make an operator that does this for me. Can anyone please point me in the right direction?

Thanks!

If we solve the equation  x^x=1/sqrt(2)  in Maple 2018.2, then Maple returns only one solution  x=1/2 , although this equation has 2 solutions  x=1/2  or  x=1/4 . This can be seen if you plot graphs or , for example, solve by the  Student:-Calculus1:-Roots  command. In this case, the root  x=1/4   is returned only as a numerical approximation. I wonder if this bug has been fixed in the latest versions of Maple?

restart;
solve(x^x=1/sqrt(2));
Student:-Calculus1:-Roots(x^x=1/sqrt(2));

First 14 15 16 17 18 19 20 Last Page 16 of 2097