Gillee

232 Reputation

8 Badges

7 years, 133 days

MaplePrimes Activity


These are questions asked by Gillee

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.

Thanks for your help.

 

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

Matrix(6, 5, {(1, 1) = 8.79, (1, 2) = 9.93, (1, 3) = 9.83, (1, 4) = 5.45, (1, 5) = 3.16, (2, 1) = 6.11, (2, 2) = 6.91, (2, 3) = 5.04, (2, 4) = -.27, (2, 5) = 7.98, (3, 1) = -9.15, (3, 2) = -7.93, (3, 3) = 4.86, (3, 4) = 4.85, (3, 5) = 3.01, (4, 1) = 9.57, (4, 2) = 1.64, (4, 3) = 8.83, (4, 4) = .74, (4, 5) = 5.8, (5, 1) = -3.49, (5, 2) = 4.02, (5, 3) = 9.8, (5, 4) = 10.0, (5, 5) = 4.27, (6, 1) = 9.84, (6, 2) = .15, (6, 3) = -8.99, (6, 4) = -6.02, (6, 5) = -5.31})

(1)

U,S,Vt:= SingularValues(X, output = ['U', 'S', 'Vt'],thin=true)

U, S, Vt := Matrix(6, 5, {(1, 1) = -.591142376412437, (1, 2) = .263167814714055, (1, 3) = .355430173862827, (1, 4) = .314264362726927, (1, 5) = .229938315364748, (2, 1) = -.397566794202426, (2, 2) = .243799027926330, (2, 3) = -.222390000685446, (2, 4) = -.753466150953458, (2, 5) = -.363589686697497, (3, 1) = -0.334789690624459e-1, (3, 2) = -.600272580693583, (3, 3) = -.450839268922308, (3, 4) = .233449657244714, (3, 5) = -.305475732747932, (4, 1) = -.429706903137018, (4, 2) = .236166806281125, (4, 3) = -.685862863873811, (4, 4) = .331860018200310, (4, 5) = .164927634884511, (5, 1) = -.469747921566658, (5, 2) = -.350891398883703, (5, 3) = .387444603099673, (5, 4) = .158735559582156, (5, 5) = -.518257437353535, (6, 1) = .293358758464403, (6, 2) = .576262119133891, (6, 3) = -0.208529179808710e-1, (6, 4) = .379077667060160, (6, 5) = -.652551600592398}), Vector(6, {(1) = 27.4687324182218, (2) = 22.6431850097747, (3) = 8.55838822848258, (4) = 5.98572320151213, (5) = 2.01489965871576, (6) = 0.}), Matrix(5, 5, {(1, 1) = -.251382792720498, (1, 2) = -.396845551776930, (1, 3) = -.692151007470363, (1, 4) = -.366170444772230, (1, 5) = -.407635238653352, (2, 1) = .814836686086339, (2, 2) = .358661500188002, (2, 3) = -.248888011159285, (2, 4) = -.368593537944618, (2, 5) = -0.979625692668875e-1, (3, 1) = -.260618505584221, (3, 2) = .700768209407253, (3, 3) = -.220811446720437, (3, 4) = .385938483188542, (3, 5) = -.493250142851024, (4, 1) = .396723777130597, (4, 2) = -.450711241216643, (4, 3) = .251321149693754, (4, 4) = .434248601436671, (4, 5) = -.622684072035804, (5, 1) = -.218027763686546, (5, 2) = .140209949871121, (5, 3) = .589119449239943, (5, 4) = -.626528250364817, (5, 5) = -.439551692342332})

(2)

SDM:= DiagonalMatrix(S[1..5],5,5)

Matrix(5, 5, {(1, 1) = 27.46873241822184, (1, 2) = 0., (1, 3) = 0., (1, 4) = 0., (1, 5) = 0., (2, 1) = 0., (2, 2) = 22.643185009774694, (2, 3) = 0., (2, 4) = 0., (2, 5) = 0., (3, 1) = 0., (3, 2) = 0., (3, 3) = 8.558388228482578, (3, 4) = 0., (3, 5) = 0., (4, 1) = 0., (4, 2) = 0., (4, 3) = 0., (4, 4) = 5.985723201512132, (4, 5) = 0., (5, 1) = 0., (5, 2) = 0., (5, 3) = 0., (5, 4) = 0., (5, 5) = 2.014899658715757})

(3)

THIS EQUALS TO ORIGINAL X MATRIX

 

U.SDM.Vt

Matrix(6, 5, {(1, 1) = 8.789999999999997, (1, 2) = 9.93, (1, 3) = 9.829999999999995, (1, 4) = 5.449999999999993, (1, 5) = 3.159999999999998, (2, 1) = 6.1099999999999985, (2, 2) = 6.9099999999999975, (2, 3) = 5.0399999999999965, (2, 4) = -.26999999999999996, (2, 5) = 7.980000000000001, (3, 1) = -9.14999999999999, (3, 2) = -7.930000000000001, (3, 3) = 4.859999999999987, (3, 4) = 4.849999999999992, (3, 5) = 3.009999999999995, (4, 1) = 9.569999999999997, (4, 2) = 1.6399999999999977, (4, 3) = 8.82999999999999, (4, 4) = .7399999999999956, (4, 5) = 5.799999999999994, (5, 1) = -3.489999999999992, (5, 2) = 4.019999999999998, (5, 3) = 9.799999999999985, (5, 4) = 9.999999999999988, (5, 5) = 4.269999999999993, (6, 1) = 9.83999999999999, (6, 2) = .15000000000000033, (6, 3) = -8.989999999999982, (6, 4) = -6.0199999999999925, (6, 5) = -5.309999999999993})

(4)

X -~ U.SDM.Vt

Matrix(6, 5, {(1, 1) = 0.1776356839e-14, (1, 2) = 0., (1, 3) = 0.5329070518e-14, (1, 4) = 0.7105427358e-14, (1, 5) = 0.2220446049e-14, (2, 1) = 0.1776356839e-14, (2, 2) = 0.2664535259e-14, (2, 3) = 0.3552713679e-14, (2, 4) = -0.5551115123e-16, (2, 5) = -0.8881784197e-15, (3, 1) = -0.1065814104e-13, (3, 2) = 0.8881784197e-15, (3, 3) = 0.1332267630e-13, (3, 4) = 0.7993605777e-14, (3, 5) = 0.4884981308e-14, (4, 1) = 0.3552713679e-14, (4, 2) = 0.2220446049e-14, (4, 3) = 0.1065814104e-13, (4, 4) = 0.4440892099e-14, (4, 5) = 0.6217248938e-14, (5, 1) = -0.7993605777e-14, (5, 2) = 0.1776356839e-14, (5, 3) = 0.1598721155e-13, (5, 4) = 0.1243449788e-13, (5, 5) = 0.6217248938e-14, (6, 1) = 0.1065814104e-13, (6, 2) = -0.3330669074e-15, (6, 3) = -0.1776356839e-13, (6, 4) = -0.7105427358e-14, (6, 5) = -0.6217248938e-14})

(5)

EIGENVALUES

 

S*~S

Vector(6, {(1) = 754.5312606638714, (2) = 512.7138273868854, (3) = 73.24600906942915, (4) = 35.82888224512065, (5) = 4.059820634692874, (6) = 0.})

(6)

EIGENVECTORS

 

Transpose(Vt)

Matrix(5, 5, {(1, 1) = -.2513827927204978, (1, 2) = .8148366860863387, (1, 3) = -.2606185055842209, (1, 4) = .39672377713059703, (1, 5) = -.21802776368654583, (2, 1) = -.3968455517769299, (2, 2) = .35866150018800186, (2, 3) = .7007682094072526, (2, 4) = -.45071124121664313, (2, 5) = .1402099498711206, (3, 1) = -.6921510074703628, (3, 2) = -.2488880111592855, (3, 3) = -.22081144672043732, (3, 4) = .2513211496937536, (3, 5) = .5891194492399427, (4, 1) = -.3661704447722298, (4, 2) = -.3685935379446182, (4, 3) = .3859384831885419, (4, 4) = .434248601436671, (4, 5) = -.6265282503648171, (5, 1) = -.4076352386533523, (5, 2) = -0.979625692668875e-1, (5, 3) = -.4932501428510237, (5, 4) = -.6226840720358041, (5, 5) = -.4395516923423325})

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

evalues, evectors := Vector(5, {(1) = 754.531260663872+0.*I, (2) = 512.713827386885+0.*I, (3) = 73.2460090694292+0.*I, (4) = 35.8288822451207+0.*I, (5) = 4.05982063469289+0.*I}), Matrix(5, 5, {(1, 1) = -.251382792720496+0.*I, (1, 2) = -.814836686086340+0.*I, (1, 3) = -.260618505584220+0.*I, (1, 4) = .396723777130597+0.*I, (1, 5) = .218027763686546+0.*I, (2, 1) = -.396845551776929+0.*I, (2, 2) = -.358661500188003+0.*I, (2, 3) = .700768209407252+0.*I, (2, 4) = -.450711241216643+0.*I, (2, 5) = -.140209949871121+0.*I, (3, 1) = -.692151007470364+0.*I, (3, 2) = .248888011159284+0.*I, (3, 3) = -.220811446720437+0.*I, (3, 4) = .251321149693753+0.*I, (3, 5) = -.589119449239943+0.*I, (4, 1) = -.366170444772231+0.*I, (4, 2) = .368593537944617+0.*I, (4, 3) = .385938483188543+0.*I, (4, 4) = .434248601436671+0.*I, (4, 5) = .626528250364817+0.*I, (5, 1) = -.407635238653353+0.*I, (5, 2) = 0.979625692668865e-1+0.*I, (5, 3) = -.493250142851024+0.*I, (5, 4) = -.622684072035804+0.*I, (5, 5) = .439551692342333+0.*I})

(8)

sdm:= DiagonalMatrix(evalues[1..5],5,5)

Matrix(5, 5, {(1, 1) = 754.5312606638715+0.*I, (1, 2) = 0.*I, (1, 3) = 0.*I, (1, 4) = 0.*I, (1, 5) = 0.*I, (2, 1) = 0.*I, (2, 2) = 512.7138273868852+0.*I, (2, 3) = 0.*I, (2, 4) = 0.*I, (2, 5) = 0.*I, (3, 1) = 0.*I, (3, 2) = 0.*I, (3, 3) = 73.2460090694292+0.*I, (3, 4) = 0.*I, (3, 5) = 0.*I, (4, 1) = 0.*I, (4, 2) = 0.*I, (4, 3) = 0.*I, (4, 4) = 35.82888224512066+0.*I, (4, 5) = 0.*I, (5, 1) = 0.*I, (5, 2) = 0.*I, (5, 3) = 0.*I, (5, 4) = 0.*I, (5, 5) = 4.0598206346928905+0.*I})

(9)

THIS SHOULD EQUAL TO THE ORIGINAL X MATRIX??

 

U.sdm.Transpose(evectors)

Matrix(6, 5, {(1, 1) = 0.6552908001635141e-1+0.*I, (1, 2) = 141.65095872384822+0.*I, (1, 3) = 338.83755003799257+0.*I, (1, 4) = 228.5810832324622+0.*I, (1, 5) = 175.59568314998398+0.*I, (2, 1) = -33.23139659260195+0.*I, (2, 2) = 75.17135144556929+0.*I, (2, 3) = 236.421687561631+0.*I, (2, 4) = 136.98207278415265+0.*I, (2, 5) = 158.72195870452097+0.*I, (3, 1) = 268.7849531650388+0.*I, (3, 2) = 93.67237457619457+0.*I, (3, 3) = -48.99100376421241+0.*I, (3, 4) = -114.08088481922744+0.*I, (3, 5) = -9.317711776596651+0.*I, (4, 1) = .7955765643196264+0.*I, (4, 2) = 44.582065761106776+0.*I, (4, 3) = 268.23773062231106+0.*I, (4, 4) = 149.54848119026994+0.*I, (4, 5) = 161.6981236670314+0.*I, (5, 1) = 230.09623253311864+0.*I, (5, 2) = 222.80201293072588+0.*I, (5, 3) = 196.9514995697131+0.*I, (5, 4) = 75.57668964466434+0.*I, (5, 5) = 108.39382140065305+0.*I, (6, 1) = -291.18409102891843+0.*I, (6, 2) = -200.6307865795955+0.*I, (6, 3) = -74.35923030344051+0.*I, (6, 4) = 31.501149679670085+0.*I, (6, 5) = -70.1539507795088+0.*I})

(10)

X -~ U.sdm.Transpose(evectors)

Matrix(6, 5, {(1, 1) = 8.724470919983649+0.*I, (1, 2) = -131.7209587238482+0.*I, (1, 3) = -329.0075500379926+0.*I, (1, 4) = -223.1310832324622+0.*I, (1, 5) = -172.435683149984+0.*I, (2, 1) = 39.34139659260195+0.*I, (2, 2) = -68.26135144556929+0.*I, (2, 3) = -231.381687561631+0.*I, (2, 4) = -137.25207278415266+0.*I, (2, 5) = -150.74195870452098+0.*I, (3, 1) = -277.9349531650388+0.*I, (3, 2) = -101.60237457619456+0.*I, (3, 3) = 53.85100376421241+0.*I, (3, 4) = 118.93088481922743+0.*I, (3, 5) = 12.32771177659665+0.*I, (4, 1) = 8.774423435680374+0.*I, (4, 2) = -42.942065761106775+0.*I, (4, 3) = -259.4077306223111+0.*I, (4, 4) = -148.80848119026993+0.*I, (4, 5) = -155.8981236670314+0.*I, (5, 1) = -233.58623253311865+0.*I, (5, 2) = -218.78201293072587+0.*I, (5, 3) = -187.15149956971308+0.*I, (5, 4) = -65.57668964466434+0.*I, (5, 5) = -104.12382140065306+0.*I, (6, 1) = 301.0240910289184+0.*I, (6, 2) = 200.7807865795955+0.*I, (6, 3) = 65.36923030344052+0.*I, (6, 4) = -37.52114967967009+0.*I, (6, 5) = 64.8439507795088+0.*I})

(11)

 

Download SVD_test.mw

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

 

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

`Maple 2023.0, X86 64 WINDOWS, Mar 06 2023, Build ID 1689885`

(1)

p := proc( x :: float ) :: float; 2.3 * x end proc:

cp:=Compiler:-Compile(p)

Error, (in Compiler:-Compile) linker exited with nonzero status 1:

 

cp(1.1)

cp(1.1)

(2)

 

Download compile_ex.mw

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