6 years, 79 days

## @tomleslie Thans,The problem was the way...

@tomleslie Thans,The problem was the way I saved the matrix in matlab.

Here still a problem, since the matrix dimension is 5000*5000 it take five minutes for Maple to import. Any suggestion to speed up the transfer time?

## @mmcdara Thanks for your suggested metho...

Lets simplify the problem more to find a way to solve the problem.

First drop w and pi for simplicity. Since the function H(w) acts as a continuous Heviside function to change the integral boundaries ( within only positive region of w), the other way of computing the integral is to intersect H with w first, and then try to integrate L inside the upper region of the created area between the intersection of two functions H and w in -1<x,y<1.

 >
 >
 >
 >
 >
 >
 >
 >
 >
 >
 >
 >
 >

I have black shaded the region as below figure that the integral must be computed inside it.

What do you suggest a fast and convenient approach to calculate a double integral inside the domain of intersection of two functions?

## @tomleslie @tomleslie Let me explai...

@tomleslie @tomleslie Let me explain my problem in a simpler way. I have a big 3-dimentional matrix (array) function of x[1], x[2], x[3], ..., x[n]. I am looking for the simplest command line way to transfer this matrix to Matlab. The small version of it seem as bellow:

restart;
A(1, 1, 1) := x[1]*x[2]*x[3];
A(2, 1, 1) := sin(x[1]*x[2]*x[3]);
A(1, 2, 1) := cos(x[1]*x[2]*x[3]);
A(2, 2, 1) := -x[2]*x[3]+x[1];
A(1, 1, 2) := x[1]*x[2]-x[3];
A(2, 1, 2) := x[1]-x[2]-x[3];
A(1, 2, 2) := x[1]-x[2]+x[3];
A(2, 2, 2) := -x[2]*x[3]+x[1];

Actually how is it possible to transfer a numeric and symbolic n-dimentional array from Maple to Matlab?

## I want to do it by command line not manu...

@tomleslie your approach looks nice, but I want to do it by command line not manually without the use of other softwares.

## I used ExportMatrix, but faced errorExpo...

I used ExportMatrix, but faced error

ExportMatrix(matlabData, A, target = MATLAB, format = rectangular, mode = ascii);
Error, (in ExportMatrix) Matrix contains non-numeric entries:  cannot export to Matlab

## Not useful!...

@Carl Love Good comment, but not very usefull since this computation is only performed one time at the begining of the loop.

The main problem is that Maple allocates new memory for the same variables in each iteration without discarding the previous one. We need to find a way to discard this memory.

 >
 >
 >
 >
 >
 >
 >
 >
 qs qs := proc(tn) local s, Qn__2, Qn__3, F, EQ, G, G1, X, k, Wxy2, Wxy3, Plt, j, Hvs2, i, Pnt, a__e, b__e, xc, yc, Hv2, Qnt, ii; global t;      |Calls Seconds  Words| PROC |    1   2.391 36561056|    1 |    1   0.000    752| Qn__2 := LinearAlgebra:-Transpose(Matrix(1,M+Nm));    2 |    1   0.000    752| Qn__3 := LinearAlgebra:-Transpose(Matrix(1,M+Nm));    3 |    1   0.000   4009| F := MTM:-diff(MTM:-diff(MTM:-sin(omega__b*t),t)*LinearAlgebra:-Transpose(convert(F0,Matrix)),t);    4 |    1   0.000      0| s := 1;    5 |    1   0.000      4| for t from t__0 by dt to tn do    6 |    1   0.016 180433|   EQ := Typesetting:-delayDotProduct(KL,V)+eqMNL+Typesetting:-delayDotProduct(a__0*ML,V)+Typesetting:-delayDotProduct(a__1*CL,V)-Typesetting:-delayDotProduct(ML,a__0*q(1 .. M+Nm,s .. s)+a__2*dq(1 .. M+Nm,s .. s)+a__3*ddq(1 .. M+Nm,s .. s))-Typesetting:-delayDotProduct(CL,a__1*q(1 .. M+Nm,s .. s)+a__4*dq(1 .. M+Nm,s .. s)+a__5*ddq(1 .. M+Nm,s .. s))-F-Qn__2-Qn__3;    7 |    1   0.000   4376|   G := Matrix(M+Nm,(i, j) -> MTM:-diff(EQ[i],V[j,1])[1]);    8 |    1   0.000   6755|   G1 := 1/G;    9 |    1   0.000      3|   if t = t__0 then   10 |    1   0.015 124077|     X[1] := Typesetting:-delayDotProduct(1/(CL*a__1+ML*a__0+KL),F+Typesetting:-delayDotProduct(ML,a__0*q(1 .. M+Nm,s .. s)+a__2*dq(1 .. M+Nm,s .. s)+a__3*ddq(1 .. M+Nm,s .. s))+Typesetting:-delayDotProduct(CL,a__1*q(1 .. M+Nm,s .. s)+a__4*dq(1 .. M+Nm,s .. s)+a__5*ddq(1 .. M+Nm,s .. s)))                               else   11 |    0   0.000      0|     X[1] := q(1 .. M+Nm,s .. s)                               end if;   12 |    1   0.000      0|   for k to 11 do   13 |   11   0.016 376894|     X[k+1] := eval(V-Typesetting:-delayDotProduct(G1,EQ),Equate(V,X[k]))                               end do;   14 |    1   0.000     37|   q(1 .. M+Nm,s+1 .. s+1) := X[k];   15 |    1   0.000   5925|   ddq(1 .. M+Nm,s+1 .. s+1) := a__0*(q(1 .. M+Nm,s+1 .. s+1)-q(1 .. M+Nm,s .. s))-a__2*dq(1 .. M+Nm,s .. s)-a__3*ddq(1 .. M+Nm,s .. s);   16 |    1   0.000   5716|   dq(1 .. M+Nm,s+1 .. s+1) := dq(1 .. M+Nm,s .. s)+a__6*ddq(1 .. M+Nm,s .. s)+a__7*ddq(1 .. M+Nm,s+1 .. s+1);   17 |    1   0.000 151003|   Wxy2 := add(add(add(h*W[i,j,2,o]*LegendreP(i,zeta__2)*LegendreP(j,eta__2)*q[o,s+1],i = 0 .. II),j = 0 .. JJ),o = 1 .. M);   18 |    1   0.015 151003|   Wxy3 := add(add(add(h*W[i,j,3,o]*LegendreP(i,zeta__2)*LegendreP(j,eta__2)*q[o,s+1],i = 0 .. II),j = 0 .. JJ),o = 1 .. M);   19 |    1   2.266 35071942|   Plt := plots:-implicitplot(Wxy2-Wxy3,zeta__2 = -1 .. 1,eta__2 = -1 .. 1,color = red,thickness = 2,gridrefine = 3);   20 |    1   0.000      0|   j := 111111;   21 |    1   0.000      0|   Hvs2 := 1;   22 |    1   0.000     33|   for i while i <= j do   23 |   10   0.000    433|     Pnt[i] := op([1, i],Plt);   24 |   10   0.047  90747|     if Wxy2-Wxy3 = 0 then   25 |    0   0.000      0|       j := 0                                 elif convert(Pnt[i],string)[1] = "C" then   26 |    1   0.000      0|       j := 0                                 else   27 |    9   0.000   7436|       a__e[i] := 1/2*MTM:-abs(max(LinearAlgebra:-Column(Pnt[i],1))-min(LinearAlgebra:-Column(Pnt[i],1)));   28 |    9   0.000     81|       if a__e[i] = 0 then   29 |    0   0.000      0|         a__e[i] = .1e-5                                   end if;   30 |    9   0.000   7113|       b__e[i] := 1/2*MTM:-abs(max(LinearAlgebra:-Column(Pnt[i],2))-min(LinearAlgebra:-Column(Pnt[i],2)));   31 |    9   0.000     81|       if b__e[i] = 0 then   32 |    0   0.000      0|         b__e[i] = .1e-5                                   end if;   33 |    9   0.000   7031|       xc[i] := 1/2*max(LinearAlgebra:-Column(Pnt[i],1))+1/2*min(LinearAlgebra:-Column(Pnt[i],1));   34 |    9   0.000   6969|       yc[i] := 1/2*max(LinearAlgebra:-Column(Pnt[i],2))+1/2*min(LinearAlgebra:-Column(Pnt[i],2));   35 |    9   0.000   1939|       Hv2[i] := (zeta__2-xc[i])^2/a__e[i]^2+(eta__2-yc[i])^2/b__e[i]^2-1;   36 |    9   0.000    154|       Hvs2 := Hv2[i]*Hvs2                                 end if                               end do;   37 |    1   0.016 352769|   Qnt := LinearAlgebra:-Transpose(convert([k__d*Grid:-Seq(Student:-NumericalAnalysis:-Quadrature(Student:-NumericalAnalysis:-Quadrature(Heaviside(-Hvs2)*MTM:-abs(Wxy2-Wxy3)*add(add(W[i,j,2,r]*LegendreP(i,zeta__2)*LegendreP(j,eta__2),i = 0 .. II),j = 0 .. JJ),zeta__2 = -1 .. 1,method = romberg[5]),eta__2 = -1 .. 1,method = romberg[5]),r = 1 .. M)/a[2]/b[2], seq(0,n = 1 .. Nm)],Matrix));   38 |    1   0.000      0|   Qn__2 := Qnt;   39 |    1   0.000   1846|   Qn__3 := -Qn__2;   40 |    1   0.000      0|   s := s+1;   41 |    1   0.000      0|   EQ := 'EQ';   42 |    1   0.000      0|   G := 'G';   43 |    1   0.000      0|   G1 := 'G1';   44 |    1   0.000      6|   X[1] := 'X[1]';   45 |    1   0.000      0|   Wxy2 := 'Wxy2';   46 |    1   0.000      0|   Wxy3 := 'Wxy3';   47 |    1   0.000      0|   Plt := 'Plt';   48 |    1   0.000      0|   Hvs2 := 'Hvs2';   49 |    1   0.000      0|   for ii to i do   50 |   11   0.000    117|     Pnt[ii] := 'Pnt[ii]';   51 |   11   0.000    124|     a__e[ii] := 'a__e[ii]';   52 |   11   0.000    124|     b__e[ii] := 'b__e[ii]';   53 |   11   0.000    124|     xc[ii] := 'xc[ii]';   54 |   11   0.000    124|     yc[ii] := 'yc[ii]';   55 |   11   0.000    124|     Hv2[ii] := 'Hv2[ii]'                               end do;   56 |    1   0.000      0|   Hvs2 := 'Hvs';   57 |    1   0.000      0|   Qnt := 'Qnt'                             end do;   58 |    1   0.000      0| t := 't';   59 |    1   0.000      0| q end proc
 >
 >
 >
 qs qs := proc(tn) local s, Qn__2, Qn__3, F, EQ, G, G1, X, k, Wxy2, Wxy3, Plt, j, Hvs2, i, Pnt, a__e, b__e, xc, yc, Hv2, Qnt, ii; global t;      |Calls Seconds  Words| PROC |    2   8.485 105246895|    1 |    2   0.000   1504| Qn__2 := LinearAlgebra:-Transpose(Matrix(1,M+Nm));    2 |    2   0.000   1504| Qn__3 := LinearAlgebra:-Transpose(Matrix(1,M+Nm));    3 |    2   0.000   7448| F := MTM:-diff(MTM:-diff(MTM:-sin(omega__b*t),t)*LinearAlgebra:-Transpose(convert(F0,Matrix)),t);    4 |    2   0.000      0| s := 1;    5 |    2   0.000     12| for t from t__0 by dt to tn do    6 |    3   0.016 543683|   EQ := Typesetting:-delayDotProduct(KL,V)+eqMNL+Typesetting:-delayDotProduct(a__0*ML,V)+Typesetting:-delayDotProduct(a__1*CL,V)-Typesetting:-delayDotProduct(ML,a__0*q(1 .. M+Nm,s .. s)+a__2*dq(1 .. M+Nm,s .. s)+a__3*ddq(1 .. M+Nm,s .. s))-Typesetting:-delayDotProduct(CL,a__1*q(1 .. M+Nm,s .. s)+a__4*dq(1 .. M+Nm,s .. s)+a__5*ddq(1 .. M+Nm,s .. s))-F-Qn__2-Qn__3;    7 |    3   0.000  13136|   G := Matrix(M+Nm,(i, j) -> MTM:-diff(EQ[i],V[j,1])[1]);    8 |    3   0.000  20270|   G1 := 1/G;    9 |    3   0.000      9|   if t = t__0 then   10 |    2   0.031 248154|     X[1] := Typesetting:-delayDotProduct(1/(CL*a__1+ML*a__0+KL),F+Typesetting:-delayDotProduct(ML,a__0*q(1 .. M+Nm,s .. s)+a__2*dq(1 .. M+Nm,s .. s)+a__3*ddq(1 .. M+Nm,s .. s))+Typesetting:-delayDotProduct(CL,a__1*q(1 .. M+Nm,s .. s)+a__4*dq(1 .. M+Nm,s .. s)+a__5*ddq(1 .. M+Nm,s .. s)))                               else   11 |    1   0.000     34|     X[1] := q(1 .. M+Nm,s .. s)                               end if;   12 |    3   0.000      0|   for k to 11 do   13 |   33   0.078 1122449|     X[k+1] := eval(V-Typesetting:-delayDotProduct(G1,EQ),Equate(V,X[k]))                               end do;   14 |    3   0.000    111|   q(1 .. M+Nm,s+1 .. s+1) := X[k];   15 |    3   0.000  17334|   ddq(1 .. M+Nm,s+1 .. s+1) := a__0*(q(1 .. M+Nm,s+1 .. s+1)-q(1 .. M+Nm,s .. s))-a__2*dq(1 .. M+Nm,s .. s)-a__3*ddq(1 .. M+Nm,s .. s);   16 |    3   0.015  16801|   dq(1 .. M+Nm,s+1 .. s+1) := dq(1 .. M+Nm,s .. s)+a__6*ddq(1 .. M+Nm,s .. s)+a__7*ddq(1 .. M+Nm,s+1 .. s+1);   17 |    3   0.016 453009|   Wxy2 := add(add(add(h*W[i,j,2,o]*LegendreP(i,zeta__2)*LegendreP(j,eta__2)*q[o,s+1],i = 0 .. II),j = 0 .. JJ),o = 1 .. M);   18 |    3   0.047 453009|   Wxy3 := add(add(add(h*W[i,j,3,o]*LegendreP(i,zeta__2)*LegendreP(j,eta__2)*q[o,s+1],i = 0 .. II),j = 0 .. JJ),o = 1 .. M);   19 |    3   8.031 101020050|   Plt := plots:-implicitplot(Wxy2-Wxy3,zeta__2 = -1 .. 1,eta__2 = -1 .. 1,color = red,thickness = 2,gridrefine = 3);   20 |    3   0.000      0|   j := 111111;   21 |    3   0.000      0|   Hvs2 := 1;   22 |    3   0.000     99|   for i while i <= j do   23 |   30   0.000    966|     Pnt[i] := op([1, i],Plt);   24 |   30   0.141 271948|     if Wxy2-Wxy3 = 0 then   25 |    0   0.000      0|       j := 0                                 elif convert(Pnt[i],string)[1] = "C" then   26 |    3   0.000      0|       j := 0                                 else   27 |   27   0.000  21307|       a__e[i] := 1/2*MTM:-abs(max(LinearAlgebra:-Column(Pnt[i],1))-min(LinearAlgebra:-Column(Pnt[i],1)));   28 |   27   0.000    243|       if a__e[i] = 0 then   29 |    0   0.000      0|         a__e[i] = .1e-5                                   end if;   30 |   27   0.000  21009|       b__e[i] := 1/2*MTM:-abs(max(LinearAlgebra:-Column(Pnt[i],2))-min(LinearAlgebra:-Column(Pnt[i],2)));   31 |   27   0.000    243|       if b__e[i] = 0 then   32 |    0   0.000      0|         b__e[i] = .1e-5                                   end if;   33 |   27   0.000  20597|       xc[i] := 1/2*max(LinearAlgebra:-Column(Pnt[i],1))+1/2*min(LinearAlgebra:-Column(Pnt[i],1));   34 |   27   0.000  20577|       yc[i] := 1/2*max(LinearAlgebra:-Column(Pnt[i],2))+1/2*min(LinearAlgebra:-Column(Pnt[i],2));   35 |   27   0.000   5480|       Hv2[i] := (zeta__2-xc[i])^2/a__e[i]^2+(eta__2-yc[i])^2/b__e[i]^2-1;   36 |   27   0.000    462|       Hvs2 := Hv2[i]*Hvs2                                 end if                               end do;   37 |    3   0.110 957757|   Qnt := LinearAlgebra:-Transpose(convert([k__d*Grid:-Seq(Student:-NumericalAnalysis:-Quadrature(Student:-NumericalAnalysis:-Quadrature(Heaviside(-Hvs2)*MTM:-abs(Wxy2-Wxy3)*add(add(W[i,j,2,r]*LegendreP(i,zeta__2)*LegendreP(j,eta__2),i = 0 .. II),j = 0 .. JJ),zeta__2 = -1 .. 1,method = romberg[5]),eta__2 = -1 .. 1,method = romberg[5]),r = 1 .. M)/a[2]/b[2], seq(0,n = 1 .. Nm)],Matrix));   38 |    3   0.000      0|   Qn__2 := Qnt;   39 |    3   0.000   5538|   Qn__3 := -Qn__2;   40 |    3   0.000      0|   s := s+1;   41 |    3   0.000      0|   EQ := 'EQ';   42 |    3   0.000      0|   G := 'G';   43 |    3   0.000      0|   G1 := 'G1';   44 |    3   0.000     18|   X[1] := 'X[1]';   45 |    3   0.000      0|   Wxy2 := 'Wxy2';   46 |    3   0.000      0|   Wxy3 := 'Wxy3';   47 |    3   0.000      0|   Plt := 'Plt';   48 |    3   0.000      0|   Hvs2 := 'Hvs2';   49 |    3   0.000      0|   for ii to i do   50 |   33   0.000    344|     Pnt[ii] := 'Pnt[ii]';   51 |   33   0.000    358|     a__e[ii] := 'a__e[ii]';   52 |   33   0.000    358|     b__e[ii] := 'b__e[ii]';   53 |   33   0.000    358|     xc[ii] := 'xc[ii]';   54 |   33   0.000    358|     yc[ii] := 'yc[ii]';   55 |   33   0.000    358|     Hv2[ii] := 'Hv2[ii]'                               end do;   56 |    3   0.000      0|   Hvs2 := 'Hvs';   57 |    3   0.000      0|   Qnt := 'Qnt'                             end do;   58 |    2   0.000      0| t := 't';   59 |    2   0.000      0| q end proc
 >

## My main problem is more complicate...

@Joe Riel My main problem is more complicate, here I put my proc just to see how it is like. So it seems to me I only need to find a way for getting rid of new memmory allocation in loop.

 >

I am wondering why Maple allocate new memory to the same variable in a loop without discarding the previous one.

## do not work for my main problem!...

@Joe Riel I created this analogy example since my main problem is something similar to it, but in a big scale. So your creative method does not work for my main problem. Any recommendation on getting rid of new memmory allocation?

## Not return numerical value...

@tomleslie as I emphasised in my question I am looking for numerical values of V[1], V[2], not symbolic. Your method only returns sympolic parametric values. Why the for loop in proc does not subs the values of t in equatins M:=A+A^(-1) and V[s]:=(M.B)???

## could not find helpful information...

@dharr I could not find helpful information in help page suitable for me, let me know if you have any sample Profiling or another suggestions.

## not compatible with the amount that task...

@Carl Love I am wondering why the memory usage number at the the right side of the bottom is not compatible with the amount that task manager shows??!!!

## Any change in new versions of Maple?...

Any change in new versions of Maple?

## @acer Interesting idea....

@acer Interesting idea.

## does not work!...

@acer actually my function is composed of another factor as well, which by considering it your propose method does not work! What about proposing a proper numerical intergration method?

 >
 >
 (1)
 >
 >
 >
 >
 >
 >
 (2)
 >
 >
 >