## 232 Reputation

6 years, 288 days

## How to generate a ColumnGraph with bars ...

Maple 2024

Hello,

I would like to generate a ColumnGraph such that the bars are centered over 1, 2, and 3. For example, I have a vector:

x:= Vector([1,2,3]);

When you execute ColumnGraph(x), you a get the first bar centered over 0.375, instead of 1, second bar centered over 1.375, instead of 2, and so on.

## singularvalues and eigenvectors...

Maple 2023

WHY DOES THE TRANSPOSE OF Vt DETERMINED BY THE FUNCTION SingularValues NOT AGREE WITH THE evectors CALCULATED BY THE FUNCTION Eigenvectors?

 > restart: with(LinearAlgebra):
 > X := Matrix([[8.79,9.93,9.83,5.45,3.16],            [6.11,6.91,5.04,-0.27,7.98],            [-9.15,-7.93,4.86,4.85,3.01],            [9.57,1.64,8.83,0.74,5.80],            [-3.49,4.02,9.80,10.00,4.27],            [9.84,0.15,-8.99,-6.02,-5.31]],            datatype=float[8],order=Fortran_order);
 (1)
 > U,S,Vt:= SingularValues(X, output = ['U', 'S', 'Vt'],thin=true)
 (2)
 > SDM:= DiagonalMatrix(S[1..5],5,5)
 (3)

THIS EQUALS TO ORIGINAL X MATRIX

 > U.SDM.Vt
 (4)
 > X -~ U.SDM.Vt
 (5)

EIGENVALUES

 > S*~S
 (6)

EIGENVECTORS

 > Transpose(Vt)
 (7)

COMPARE LINE (6) AND THE evalues OF  LINE  (8), IN AGREEMENT.

COMPARE LINE (7) AND THE evectors OF LINE (8), NOT IN AGREEMENT.

 > evalues, evectors:= Eigenvectors(Transpose(X).X)
 (8)
 > sdm:= DiagonalMatrix(evalues[1..5],5,5)
 (9)

THIS SHOULD EQUAL TO THE ORIGINAL X MATRIX??

 > U.sdm.Transpose(evectors)
 (10)
 > X -~ U.sdm.Transpose(evectors)
 (11)
 >

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

Maple

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 can I get the Compiler to work?...

Maple 2023

I made the upgrade to Maple 2023 today and for fun I compiled a simple procedure. I got an error in Maple 2023. So I ran the same lines of code in Maple 2022 and eveything works. Does anyone sees this problem?

 > restart: kernelopts(version);
 (1)
 > p := proc( x :: float ) :: float; 2.3 * x end proc:
 > cp:=Compiler:-Compile(p)
 > cp(1.1)
 (2)
 >

## How to convert a netlist to a ladder sch...

Maple 2021

Hi Everyone,

I would like to convert a netlist to a ladder schematic by using Draw (Syrup). So far I have tried combinations of &+ and &// and have not achieved the correct result. Please help.

capnet:= "
V  1 0 1
L  1 2 1
C1 2 3 2uF
C2 2 4 3uF
C3 4 3 1uF
C4 4 5 1.5uF
C5 3 5 2.5uF
C6 3 0 3.5uF
C7 5 0 0.5uF
.end":

ckt:= [ V(1), L(1), C1(2.8E-6),
C2(3.E-6),  C3(1.E-6),
C4(1.5E-6), C5(2.5E-6) &+ C6(3.5E-6)
]:
Draw(ckt);

Thanks.

SyrupQuestion.mw

 1 2 3 4 5 Page 1 of 5
﻿