Gillee

232 Reputation

8 Badges

7 years, 102 days

MaplePrimes Activity


These are answers submitted by Gillee

In line 2, change the three := assignment signs to = sign. The error goes away.

The value of N, printout or no printout, and compiled and not compiled have an effect on the elasped time.

 

see worksheet

Download try_this.mw

 

I found this Threads program many year ago in Maple. I made some script modifications to fit your problem. I noticed that genrating the x, y, and f(x,y) requires alot time for large numbers. So I put these calculations in the datLoop procedure. I used floating point calculations over the integer calculations found in the nested seq method and the Threads parallelism. I took the liberty of making many assumptions on what were your actual intentions. Hopefully, you can modify this script to your liking. 

Threads_datLoop_vs_seq.mw

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

 

1 2 Page 1 of 2