## How can I use a compiled Fortran code in Maple wor...

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);
 (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)
 (3)
 > fmultf(10.1,3.3)
 (4)
 > fmultf(100.234,67.901)
 (5)

Matrix multiplication example

 > a:=Matrix([[1.,4.,7.],[2.,5.,8.],[3.,6.,9.]],datatype=float[8],order=Fortran_order);
 (6)
 > b:=Matrix([[1.,4.,7.],[2.,5.,8.],[3.,6.,9.]],datatype=float[8],order=Fortran_order);
 (7)
 > c:=Matrix(1 .. 3, 1 .. 3, fill = 0.,datatype=float[8],order=Fortran_order);
 (8)
 > a.b
 (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)
 >
mult-Fortran_dll.mw

## How do I solve system of differential equations i...

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;

## I don't know there is a connection error between W...

I know that I can have Websource and WebSink at the beginning and end of the web. However, when the roller is set to a variable roller, the following error occurs when connecting the websource and websink. I would like to know why the error occurs and what I should do.

## How do I solve delay differential equations?...

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;

## Abstract Tensor calculus possible? ...

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?

## sir model Error code ...

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"]

## Center Align Math...

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.

## Automate Lie Algebra Computaitons...

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!

## Bug in the solve command...

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));


## Probleme with factor...

condi := [p1 + p2 + p3 = 1];
simplify(s, condi);
condi := [p1 + p2 + p3 = 1]

/      c (-1 + p1 + p2)        c (-1 + p1 + p2)
{ a = - ----------------, b = - ----------------,           c = c,
\             p1                               p2

c (p1 + p2) (-1 + p1 + p2)           c (p2 - 1)          c (p1 - 1)
d = --------------------------,             e = ----------, f = ----------
p1 p2                                       p1                 p2

\
}
/

assigne(%);
c := 10;
a := factor(simplify(a, condi));
b := factor(simplify(b, condi));
d := factor(simplify(d, condi));
e := factor(simplify(e, condi));
f := factor(simplify(f, condi));
c := 10

a := a

b := b

d := d

e := e

f := f

NULL;
Why "factor" does not play its role ?   Thank you.

## How to work with functions that contain units insi...

I'd like to be able to define functions with units and then use them.

In the example below, things don't work with Maple input. I've shown one example, with the function f2.

It seems to work better with 2D input, but it seems that it is not possible to make plots.

In the example below, I define f4 as a function of two variables that returns a function of one variable.

I'd like to call the outer function, obtain a function as a result (r1 below) and then plot the latter.

 (1)

 (2)

f2:=x->xUnit(m)

 (3)

 (4)

 (5)

 (6)

 (7)

 (8)

 (9)

The contents above aren't showing the error that Maple gives when I try to plot.

Here is a screenshot

## How to print a variable with units?...

I have a variable with the unit Volt.

I'd like to print something like "The voltage is %f" where the floating point is the value of the variable with the unit.

I've tried the options below so far.

How would one accomplish this?

 (1)

 5*Units:-Unit(V)

 5*Units:-Unit(V)

 5*Units:-Unit(V)

 5*Units:-Unit(V)

 5 Units:-Unit(V)

 (2)

 (3)

 (4)

## integral of Dirac...

Performing

II := int( Dirac(x^2+y^2-1), x = -infinity..infinity )

gives

II = 1/sqrt(abs(y^2 - 1))

with no restriction on y. It seems that the answer (at least to the question I thought I was asking) is actually

II = 1/sqrt(1-y^2) for y\in[-1,1], 0 else

Am I misunderstaning the meaning of Dirac and its integral?

## How Can I sort a list of polynomials with parametr...

Hi all,

How Can I sort a list of polynomials with parametric coefficients based on the following criteria?
1. Fewer different parameters in the coefficients.
2. If the number of parameters is the same, the lower power of the parameters.
3. If the previous criteria are the same, sentences with parametric coefficients appear later.

Otherwise, the list is in order. For example, I want to obtain the sorted list

[(a+2)*x[1]+3*x[2]-x[3]+(a-2)*x[4],2*x[1]+2*x[2]-b*x[3]+(c+1)*x[4], (a-1)*x[1]+x[2]+(a+1)*x[3]+(C^2-1)*x[4], (a+b)*x[1]+(c-3)*x[2]+(-b-1)*x[3]+2*x[4]] from the following list:

[(a-1)*x[1]+x[2]+(a+1)*x[3]+(C^2-1)*x[4], 2*x[1]+2*x[2]-b*x[3]+(c+1)*x[4], (a+2)*x[1]+3*x[2]-x[3]+(a-2)*x[4], (a+b)*x[1]+(c-3)*x[2]+(-b-1)*x[3]+2*x[4]].

Thanks.

## How can I construct my data table to provide the n...

Good day.

I recently constructed a Maple model using an LPSolve routine to solve for a classic factory (Operations Research) assignment problem. Basically, this involves 4 factories that, in any combination, can supply goods and fulfil demand to 10 customers. If any given factory is activated, the model determines what factory should supply what customer so that the weighted-distance is minimized.

However, in addtion to this - I would like to know the quantity of items that each factory supplies to each of their respective customers and I would like to verify that the quantity demanded by each customer is fulfilled.

I was hoping that somebody could guide me on how to do this. Any suggestions would be most welcomed.

The model is attached.