Gillee

157 Reputation

8 Badges

4 years, 105 days

MaplePrimes Activity


These are answers submitted by Gillee

The SurfacePlot function wants x, y, and z to work. I think I may have helped with speeding up the SurfacePlot by extracting the x and y values from data. It does get really slow when n is greater 3 using nested seq or nested Threads:-Seq.  Please review the worksheet.

seq.mw

In the K2_... example, Code Edit Regions are used. This is how it is done. Open a New Document or New Worksheet. In this illustration a Document is used, because in a Worksheet prompts are shown, which are not needed.  Click anywhere on the Document page to place your cursor. Click Insert on the menu bar and select the Code Edit Region. Copy some code from ex1.mw and paste it in the Code Edit Region. Please note at the end of each line of code you can use a semi-colon to allow results to be displayed or colon to stop the display of results after execution.  If you want annotation above the Code Edit Region, click anywhere inside the Code Edit Region, then click Insert, Paragraph, and select Before Cursor. Before entering the annotation, select Text found on the menu bar, so Maple does not think it is code. Click Execute the entire worksheet (!!!) periodically to see the results. This style is like the IPython editor. 
CodeEditRegion.mw

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

 

1 2 Page 1 of 2