Gillee

122 Reputation

6 Badges

3 years, 305 days

MaplePrimes Activity


These are answers submitted by Gillee

Hi,

This maybe a possible solution to your problem by using the compiler. On my computer it is about 8 minutes to complete the search. I hope the time is about the same on your computer. There are many solutions, so I hope I correctly understood your goal.

Here is the code:

mloops.mw

It was easier to find/replace your parameter list in 1D format. Please see attached file. 

 

CV_gl.mw

 

 

I noticed that the data structure of pts[1] and pts[2] created an error in Spline. I extracted two vectors from pts that were acceptable by Spline and kept changes to your script to a minimum.

 

import_gl.mw

 

By using hardware floating-point, evalhf in the procedure, it appears that the real-time value is reduced thread_map_gl.mw


 

restart; kernelopts(version); interface(version); multithread_capability := kernelopts(multithreaded); Number_of_CPUs := kernelopts(numcpus)

8

(1)

# The present method uses the function solve, about 853750 times. As you know there is a high price to pay in computation time in using solve. I know it, because I ran it and the script required several hours before displaying the two solutions, containing 6 integer value roots per solution. The question is: How can one reduce the number of possibilities? One way is to partially solve your function by using the quadratic formula and testing if the roots are of integer value and then apply the solve function. As you will see the method below will require an additional six more conditions for the first if-then statement, thus reducing the number of times the function solve is used to about 262 times.  The computation time was found to be under 30 seconds to arrived at the desired solutions.

NULL

abs(a*x+b)+abs(c*x+d)-t*x^2+m*x-n; -t*x^2+a*x+c*x+m*x+b+d-n

-t*x^2+a*x+c*x+m*x+b+d-n

(2)

NULL

-a*x-b+(c*x+d)-t*x^2+m*x-n; a*x+b-c*x-d-t*x^2+m*x-n

-t*x^2+a*x-c*x+m*x+b-d-n

(3)

NULL

 

 

restart; r := abs(a*x+b)+abs(c*x+d)-t*x^2+m*x-n; rn := -t*x^2+a*x+c*x+m*x+b+d-n; mnx := -2; mxx := 16; a := 9; b := 10; c := 2; d := 7; t := 1; m := 2; n := 3; p := plot(r, x = mnx .. mxx, color = black); pn := plot(rn, x = mnx .. mxx, color = red, style = point, symbol = asterisk); plots:-display({p, pn}); rn := -t*x^2+a*x+c*x+m*x+b+d-n; rnrp := (-a-c-m+sqrt((a+c+m)^2-(4*(-1))*(b+d-n)))/(2*(-1)); rnrn := (-a-c-m-sqrt((a+c+m)^2-(4*(-1))*(b+d-n)))/(2*(-1)); type((-a-c-m+sqrt((a+c+m)^2-(4*(-1))*(b+d-n)))/(2*(-1)), integer); type((-a-c-m-sqrt((a+c+m)^2-(4*(-1))*(b+d-n)))/(2*(-1)), integer)

true

(4)

restart; r := abs(a*x+b)+abs(c*x+d)-t*x^2+m*x-n; rn := -a*x-b+(c*x+d)-t*x^2+m*x-n; mnx := -9; mxx := 0; a := 9; b := 10; c := 2; d := 7; t := 1; m := 2; n := 3; p := plot(r, x = mnx .. mxx, color = black); pn := plot(rn, x = mnx .. mxx, color = red, style = point, symbol = asterisk); plots:-display({p, pn}); rnrp := (-m+a-c+sqrt((m-a+c)^2-(4*(-1))*(-b+d-n)))/(2*(-1)); rnrn := (-m+a-c-sqrt((m-a+c)^2-(4*(-1))*(-b+d-n)))/(2*(-1)); type((-m+a-c+sqrt((m-a+c)^2-(4*(-1))*(-b+d-n)))/(2*(-1)), integer); type((-m+a-c-sqrt((m-a+c)^2-(4*(-1))*(-b+d-n)))/(2*(-1)), integer)

true

(5)

``

restart; r := abs(a*x+b)+abs(c*x+d)-t*x^2+m*x-n; rn := -a*x-b-c*x-d-t*x^2+m*x-n; mnx := -9; mxx := 0; a := 9; b := 10; c := 2; d := 7; t := 1; m := 2; n := 3; p := plot(r, x = mnx .. mxx, color = black); pn := plot(rn, x = mnx .. mxx, color = red, style = point, symbol = asterisk); plots:-display({p, pn}); rnrp := (-m+a+c+sqrt((m-a-c)^2-(4*(-1))*(-b-d-n)))/(2*(-1)); rnrn := (-m+a+c-sqrt((m-a-c)^2-(4*(-1))*(-b-d-n)))/(2*(-1)); type((-m+a+c+sqrt((m-a-c)^2-(4*(-1))*(-b-d-n)))/(2*(-1)), integer); type((-m+a+c-sqrt((m-a-c)^2-(4*(-1))*(-b-d-n)))/(2*(-1)), integer)

true

(6)

``

restart; r := abs(a*x+b)+abs(c*x+d)-t*x^2+m*x-n; rn := a*x+b-c*x-d-t*x^2+m*x-n; mnx := -9; mxx := 12; a := 9; b := 10; c := 2; d := 7; t := 1; m := 2; n := 3; p := plot(r, x = mnx .. mxx, color = black); pn := plot(rn, x = mnx .. mxx, color = red, style = point, symbol = asterisk); plots:-display({p, pn}); rnrp := (-m-a+c+sqrt((m+a-c)^2-(4*(-1))*(b-d-n)))/(2*(-1)); rnrn := (-m-a+c-sqrt((m+a-c)^2-(4*(-1))*(b-d-n)))/(2*(-1)); type((-m-a+c+sqrt((m+a-c)^2-(4*(-1))*(b-d-n)))/(2*(-1)), integer); type((-m-a+c-sqrt((m+a-c)^2-(4*(-1))*(b-d-n)))/(2*(-1)), integer)

true

(7)

NULL

``

restart; st := time(); k := 0; for a to 10 do for b to 10 do for c to 10 do for d to 10 do for t to 2 do for m to 10 do for n to 10 do if `and`(`and`(c < a, igcd(a, b, c, d, t, m, n) = 1), abs(b)+abs(d)-n <> 0) then k := k+1; L[k] := [a, b, c, d, t, m, n] end if end do end do end do end do end do end do end do; L := convert(L, list); k; time()-st

7.828

(8)

 

restart; st := time(); k := 0; for a to 10 do for b to 10 do for c to 10 do for d to 10 do for t to 2 do for m to 10 do for n to 10 do if `and`(`and`(`and`(`and`(`and`(`and`(`and`(`and`(c < a, igcd(a, b, c, d, t, m, n) = 1), abs(b)+abs(d)-n <> 0), type((-a-c-m+sqrt((a+c+m)^2-(4*(-1))*(b+d-n)))/(2*(-1)), integer)), type((-a-c-m-sqrt((a+c+m)^2-(4*(-1))*(b+d-n)))/(2*(-1)), integer)), type((-m+a-c+sqrt((m-a+c)^2-(4*(-1))*(-b+d-n)))/(2*(-1)), integer)), type((-m+a-c-sqrt((m-a+c)^2-(4*(-1))*(-b+d-n)))/(2*(-1)), integer)), type((-m+a+c+sqrt((m-a-c)^2-(4*(-1))*(-b-d-n)))/(2*(-1)), integer)), type((-m+a+c-sqrt((m-a-c)^2-(4*(-1))*(-b-d-n)))/(2*(-1)), integer)) then k := k+1; L[k] := [a, b, c, d, t, m, n] end if end do end do end do end do end do end do end do; k; L := convert(L, list); time()-st

13.000

(9)

restart; st := time(); k := 0; for a to 10 do for b to 10 do for c to 10 do for d to 10 do for t to 2 do for m to 10 do for n to 10 do if `and`(`and`(`and`(`and`(`and`(`and`(`and`(`and`(c < a, igcd(a, b, c, d, t, m, n) = 1), abs(b)+abs(d)-n <> 0), type((-a-c-m+sqrt((a+c+m)^2-(4*(-1))*(b+d-n)))/(2*(-1)), integer)), type((-a-c-m-sqrt((a+c+m)^2-(4*(-1))*(b+d-n)))/(2*(-1)), integer)), type((-m+a-c+sqrt((m-a+c)^2-(4*(-1))*(-b+d-n)))/(2*(-1)), integer)), type((-m+a-c-sqrt((m-a+c)^2-(4*(-1))*(-b+d-n)))/(2*(-1)), integer)), type((-m+a+c+sqrt((m-a-c)^2-(4*(-1))*(-b-d-n)))/(2*(-1)), integer)), type((-m+a+c-sqrt((m-a-c)^2-(4*(-1))*(-b-d-n)))/(2*(-1)), integer)) then X := [solve(abs(a*x+b)+abs(c*x+d)-t*x^2+m*x-n = 0)]; if `and`(`and`(`and`(`and`(`and`(`and`(nops(X) = 6, type(X[1], integer)), type(X[2], integer)), type(X[3], integer)), type(X[4], integer)), type(X[5], integer)), type(X[6], integer)) then k := k+1; L[k] := [a, b, c, d, t, m, n, X[]] end if end if end do end do end do end do end do end do end do; k; L := convert(L, list); time()-st

21.016

(10)

NULL

``


 

Download lots_of_loops_solution.mw

 

with(Optimization):
list_1 := [POL[0], POL[1], POL[2], POL[3]];
res_1 := LSSolve(list_1);

res_1 := [4.53000183056274 10-14, [c[-2] = 1.42226604733081 106 , c[-1] = 1.75651468256660, c[0] = 0.296516836577408, c[1] = 1.58639160755944]]

You could try LSSolve (go to Help for an explaination of LSSolve). I got answers for the Q values, if you assumed the D values are constants. You will find three sets of resutls: D values all equal to 100, or 50, or 10). I could not get the D and Q values to be minimized together, so these results may not be what you want. Note to stop a printout, add a colon at the end of each equation

 

aceitoso_2.mw.


 

restart; g3 := (2*(1+exp(4*x)))/(exp(4*x)-1)

(2+2*exp(4*x))/(exp(4*x)-1)

(1)

a := `assuming`([eval((diff(g3, `$`(x, n)))/factorial(n), x = 0)], [n >= 0])

(Sum(binomial(n, _k1)*(2*pochhammer(1-_k1, _k1)+2*4^_k1)*(eval(diff(1/(exp(4*x)-1), [`$`(x, n-_k1)]), {x = 0})), _k1 = 0 .. n))/factorial(n)

(2)

hello := Sum(a*x^n, n = 0 .. infinity)

Sum((Sum(binomial(n, _k1)*(2*pochhammer(1-_k1, _k1)+2*4^_k1)*(eval(diff(1/(exp(4*x)-1), [`$`(x, n-_k1)]), {x = 0})), _k1 = 0 .. n))*x^n/factorial(n), n = 0 .. infinity)

(3)

``


 

Download Ans.mw

I get only odd numbers to print out using Math and C Maple Input. IsItTrue.mw

 

Please try this
 

restart``

action1 := module () export Mproc;  Mproc := proc (n) local y; y := n+2 end proc end module

_m1844886131808

(1)

action1:-Mproc(2)

4

(2)

``


Download Ex1.mw

 
 

This is the last variation I can think of: function operator ->, Array, and the add function. Bottomline: about the same execution time. Thanks for the problem I just started learning how to use this software in July.   

 


 

restart; st := time(); k := 6; h := 1; N := .5; nu := .3; E_m := 7.0*10^10; E_c := 3.80*10^11; rho_m := 2702.; rho_c := 3800.; lambda_m := nu*E_m/((1+nu)*(1-2*nu)); lambda_c := nu*E_c/((1+nu)*(1-2*nu)); mu_m := E_m/(2*(1+nu)); mu_c := E_c/(2*(1+nu)); Z := rho_m+(rho_c-rho_m)*(1/2+z/h)^N; U := lambda_m+(lambda_c-lambda_m)*(1/2+z/h)^N; S := mu_m+(mu_c-mu_m)*(1/2+z/h)^N; d := Matrix([[0, 0, 0, 0, 0, 0, 0, 0], [sqrt(3), 0, 0, 0, 0, 0, 0, 0], [0, sqrt(15), 0, 0, 0, 0, 0, 0], [sqrt(7), 0, sqrt(35), 0, 0, 0, 0, 0], [0, sqrt(27), 0, sqrt(63), 0, 0, 0, 0], [sqrt(11), 0, sqrt(55), 0, sqrt(99), 0, 0, 0], [0, sqrt(39), 0, sqrt(91), 0, sqrt(143), 0, 0], [sqrt(15), 0, sqrt(75), 0, sqrt(135), 0, sqrt(195), 0]]); f := proc (al, b, be) options operator, arrow; -2*S*d[be+1, al+1]*W(be)*sqrt(al+1/2)*orthopoly:-P(al, z)*d[2, b+1]*sqrt(b+1/2)*orthopoly:-P(b, z) end proc; e2X := Array(0 .. 5, 0 .. 5, 0 .. 5, f); e2 := add(e2X[() .. (), () .. (), () .. ()]); int(e2, z = -(1/2)*h .. (1/2)*h); time()-st

.766

(1)

NULL

# Original Ans:                -3.192307692*10^11*W(1)+4.396880662*10^11*W(3)-1.474586301*10^11*W(5)-9.235575669*10^10*W(2)+1.979090105*10^11*W(4);

``

``


 

Download for_(10).mw

You could speed up execution by replacing nested for-do loops. I tried with nested add functions. Compared head to head the execution times were about the same. Unlike the previous version for (4).mw where a procedure was created, I kept the code as close as to the original. As you will notice I suppressed printout to the screen that saves time. Hope these methods helps?


 

restart; st := time(); k := 6; h := 1; N := .5; nu := .3; E_m := 7.0*10^10; E_c := 3.80*10^11; rho_m := 2702.; rho_c := 3800.; lambda_m := nu*E_m/((1+nu)*(1-2*nu)); lambda_c := nu*E_c/((1+nu)*(1-2*nu)); mu_m := E_m/(2*(1+nu)); mu_c := E_c/(2*(1+nu)); Z := rho_m+(rho_c-rho_m)*(1/2+z/h)^N; U := lambda_m+(lambda_c-lambda_m)*(1/2+z/h)^N; S := mu_m+(mu_c-mu_m)*(1/2+z/h)^N; d := Matrix([[0, 0, 0, 0, 0, 0, 0, 0], [sqrt(3), 0, 0, 0, 0, 0, 0, 0], [0, sqrt(15), 0, 0, 0, 0, 0, 0], [sqrt(7), 0, sqrt(35), 0, 0, 0, 0, 0], [0, sqrt(27), 0, sqrt(63), 0, 0, 0, 0], [sqrt(11), 0, sqrt(55), 0, sqrt(99), 0, 0, 0], [0, sqrt(39), 0, sqrt(91), 0, sqrt(143), 0, 0], [sqrt(15), 0, sqrt(75), 0, sqrt(135), 0, sqrt(195), 0]]); e2 := add(add(add(-2*S*d[be+1, al+1]*W(be)*sqrt((2*al+1)*(1/2))*orthopoly:-P(al, z)*d[2, b+1]*sqrt((2*b+1)*(1/2))*orthopoly:-P(b, z), be = 0 .. 5), b = 0 .. 5), al = 0 .. 5); int(e2, z = -(1/2)*h .. (1/2)*h); time()-st

.750

(1)

# Original Ans:                -3.192307692*10^11*W(1)+4.396880662*10^11*W(3)-1.474586301*10^11*W(5)-9.235575669*10^10*W(2)+1.979090105*10^11*W(4);


 

Download for_(10a).mw

 

Using @epostma idea of moving the int(..) outside the loops and turning the your code into a procedure, you can get another reduction in time by almost one half. Of course writing a procedure requires a little work, as you will see below. One advantage of a procedure you run it again with new input parameters.


 

restart

pa := proc (k::integer, h::integer, N::float, nu::float, E_m::float, E_c::float, rho_m::float, rho_c::float) local lambda_m::float, lambda_c::float, mu_m::float, mu_c::float, Z::float, U::float, S::float, d::(Array(datatype = float[8])), e2::float, f::float, b::integer, alpha::integer, beta::integer, i::integer, W::float, z::float; lambda_m := nu*E_m/((1+nu)*(1-2*nu)); lambda_c := nu*E_c/((1+nu)*(1-2*nu)); mu_m := E_m/(2+2*nu); mu_c := E_c/(2+2*nu); Z := rho_m+(rho_c-rho_m)*(1/2+z/h)^N; U := lambda_m+(lambda_c-lambda_m)*(1/2+z/h)^N; S := mu_m+(mu_c-mu_m)*(1/2+z/h)^N; d := Matrix([[0, 0, 0, 0, 0, 0, 0, 0], [sqrt(3), 0, 0, 0, 0, 0, 0, 0], [0, sqrt(15), 0, 0, 0, 0, 0, 0], [sqrt(7), 0, sqrt(35), 0, 0, 0, 0, 0], [0, sqrt(27), 0, sqrt(63), 0, 0, 0, 0], [sqrt(11), 0, sqrt(55), 0, sqrt(99), 0, 0, 0], [0, sqrt(39), 0, sqrt(91), 0, sqrt(143), 0, 0], [sqrt(15), 0, sqrt(75), 0, sqrt(135), 0, sqrt(195), 0]]); e2 := 0; for alpha from 0 to k-2 do for b from 0 to k-2 do for beta from 0 to k-1 do e2 := e2-2*S*d[beta+1, alpha+1]*W(beta)*sqrt(alpha+1/2)*orthopoly:-P(alpha, z)*d[2, b+1]*sqrt(b+1/2)*orthopoly:-P(b, z) end do end do end do; int(e2, z = -(1/2)*h .. (1/2)*h) end proc

k := 6; h := 1; N := .5; nu := .3; E_m := 7.0*10^10; E_c := 3.80*10^11; rho_m := 2702.; rho_c := 3800.

time(pa(k, h, N, nu, E_m, E_c, rho_m, rho_c))

.671

(1)

pa(k, h, N, nu, E_m, E_c, rho_m, rho_c)

0.4396880665e12*W(3)-0.1474586298e12*W(5)+0.1979090107e12*W(4)-0.9235575677e11*W(2)-0.3192307694e12*W(1)

(2)

# Original Ans:                -3.192307692*10^11*W(1)+4.396880662*10^11*W(3)-1.474586301*10^11*W(5)-9.235575669*10^10*W(``2)+1.979090105*10^11*W(4);


 

Download for(4).mw

 

You could use DeleteColumn() and DeleteRow() after determining if the sum of the elements in the column or row add up to zero.


 

restart; with(LinearAlgebra)

``

M := Matrix([[0, 0, sqrt(66), 45, 0, 0, exp(-23), 0], [tanh(3), 0, 0, 0, 0, 3^4, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [sqrt(7), 0, sqrt(35), 0, 0, 0, cos(56), 0], [0, sqrt(27), 0, sqrt(63), 0, 0, sin(12), 0], [sqrt(11), 0, sqrt(55), 0, 0, 0, 0, 0], [0, sqrt(39), 0, sqrt(91), 0, sqrt(43), 0, 0], [sqrt(15), 0, sqrt(75), 0, 0, 0, sqrt(195), 0]])

Matrix(%id = 18446746093103943062)

(1)

``

ColumnDimension(M); RowDimension(M)

8

(2)

``

``

for i from ColumnDimension(M) by -1 to 1 do if add(M[() .. (), i]) = 0 then M := DeleteColumn(M, i) end if end do; M
NULL

Matrix(%id = 18446746093124955182)

(3)

``

for i from RowDimension(M) by -1 to 1 do if add(M[i, () .. ()]) = 0 then M := DeleteRow(M, i) end if end do; M

Matrix(%id = 18446746093124947230)

(4)

ColumnDimension(M); RowDimension(M)

7

(5)

``

``


 

Download DeleteZeroColumnsRows.mw

1 2 Page 1 of 2