MaplePrimes Questions

I am learning how to use Threads. I looked for an example code in Start / Programming / Example: Task Model and Multithreaded Programming. I found a MandelBrot code, which I was able to change a value in the If -then statement to run in Threads or no Threads mode. I added a time() function to get a sense of the execution time. The results are about 140s with Threads and 91s with no Threads. I would have thought that the execution time would be smaller in the Threads mode than in the no Threads mode. Did I assume incorrectly that I was creating a Threads and no Threads situations by modifying the if-then statement? Or is this not good example? Here is the code:

Threads_Ex3a.mw

with(PDEtools); declare(u(x, y, z, t), U(X, Y, Z, T)); interface(showassumed = 0); assume(a > 0, p > 0); W := diff_table(u(x, y, z, t)); E := 6*W[]*W[x]+W[t]+W[x, y, z] = 0; InvE := proc (PDE) local Eq1, Eq2, Eq3, Eq4, tr1, tr2, tr3, tr4, term1, term2, term3, term4, sys1; tr1 := {t = T/a^beta, x = X/a^alpha, y = Y/a^mu, z = Z/a^nu, u(x, y, z, t) = U(X, Y, Z, T)/a^zeta}; tr2 := eval(tr1, zeta = 1); Eq1 := combine(dchange(tr2, PDE, [X, Y, Z, T, U])); Eq2 := map(lhs, PDE = Eq1); term1 := select(has, select(has, select(has, rhs(Eq2), a), beta), a); term2 := expand(rhs(Eq2)/term1); term3 := select(has, select(has, term2, a), a); sys1 := {select(has, op(1, term3), a) = 1, select(has, op(2, term3), a) = 1}; tr3 := solve(sys1, {alpha, beta, mu, nu}); tr4 := subs(tr3, tr2); print(tr3, tr4); Eq3 := dchange(tr4, PDE, [X, Y, Z, T, U]); term4 := select(has, op(1, lhs(Eq3)), a); Eq4 := expand(Eq3/term4); PDE = simplify(Eq4) end proc; InvE(E)

> restart;
> u := c-6*mu*(1+lambda*sqrt(-mu)*coth(A+sqrt(-mu)*(x+y+mu*t)))/((a+b)*sqrt(-mu)*coth(A+sqrt(-mu)*(x+y+mu*t)))+6*mu*sqrt(sigma*(1-coth(A+sqrt(-mu)*(x+y+mu*t))^2))/(sqrt(sigma)*(a+b)*sqrt(-mu)*coth(A+sqrt(-mu)*(x+y+mu*t)));
            /                (1/2)     /         (1/2)               \\
       6 mu \1 + lambda (-mu)      coth\A + (-mu)      (x + y + mu t)//
   c - ----------------------------------------------------------------
                         (1/2)     /         (1/2)               \     
            (a + b) (-mu)      coth\A + (-mu)      (x + y + mu t)/     

                                                                 (1/2)   
               /      /                                       2\\        
               |      |        /         (1/2)               \ ||        
          6 mu \sigma \1 - coth\A + (-mu)      (x + y + mu t)/ //        
      + -----------------------------------------------------------------
             (1/2)              (1/2)     /         (1/2)               \
        sigma      (a + b) (-mu)      coth\A + (-mu)      (x + y + mu t)/
> c := 1;
                                      1
> mu := -1.5;
                                     1.5
> lambda := 1.5;
                                     1.5
> a := 1;
                                      1
> b := 1;
                                      1
> A := .5;
                                     0.5
> y := 0;
                                      0
> plot3d([abs(u)], x = -10 .. 3, t = -10 .. 3);
Warning, unable to evaluate the function to numeric values in the region; see the plotting command's help page to ensure the calling sequence is correct

 

 

> restart;
> u := a[0]-12*sqrt(mu)*(1+lambda*sqrt(mu)*tan(A-sqrt(mu)*(x+y+4*mu*t)))/((a+b)*tan(A-sqrt(mu)*(x+y+4*mu*t)));
              (1/2) /             (1/2)    /      (1/2)                 \\
         12 mu      \1 + lambda mu      tan\A - mu      (x + y + 4 mu t)//
  a[0] - -----------------------------------------------------------------
                                /      (1/2)                 \            
                     (a + b) tan\A - mu      (x + y + 4 mu t)/            
> a[0] := 2;
                                      2
> mu := 1.5;
                                     1.5
> lambda := 2;
                                      2
> a := .5;
                                     0.5
> b := .5;
                                     0.5
> A := 1.5;
                                     1.5
> y := 0;
                                      0
> plot3d([abs(u)], x = -3 .. 3, t = -3 .. 3);
Warning, unable to evaluate the function to numeric values in the region; see the plotting command's help page to ensure the calling sequence is correct

 

i have a problem with readstat, when using proc , the readstat command returns some errors and do not complete the reading procedure, but without using proc, it is ok, what should i do ? is this a bug?
 

Download read.mw

Hi. I would like to learn to use your package. The example  document for it not running (for me). Included a screen shot and my test document. Basicially It would like to import .mpl procedures and use them as the exports of a module/package. I have no experience with code editors and this is the first time I have tried to use the code edit region. Also whathat does the (**) mean/do?

Edit: I redid the documet.

restart

with(CodeBuilder)

[Build, Directory, Export, File, Import, Mint, Read, Regions, Version]

(1)

"Directory("interface('worksheetdir')")"

"C:\Users\Ronan\AppData\Local\Temp\Rtestm"

(2)

Regions()

["Rtestm.mpl", "NewTest.mpl", "NewTest_ModuleApply.mpl"]

(3)

libname

"C:\Program Files\Maple 2017\lib", "C:\Users\Ronan\maple\toolbox\CodeBuilder\lib", "C:\Users\Ronan\maple\toolbox\personal\lib"

(4)
Rtestm := module ()

_m2199891725024

["C:\Users\Ronan\AppData\Local\Temp\Rtestm\Rtestm.mpl", "C:\Users\Ronan\AppData\Local\Temp\Rtestm\NewTest.mpl", "C:\Users\Ronan\AppData\Local\Temp\Rtestm\NewTest_ModuleApply.mpl"]

``

NewTest:=module()

"This is a NEW TEST"

_m2199890918688

``

``

ModuleApply:=proc()

proc () print("This is a NEW TEST") end proc

``

"" CodeBuilder:-Build"('mint','maplet', 'infolevel'=2,  'prefix' = "#!",  'main' = "Rtestm.mpl");"

mint, maplet, infolevel = 2, prefix = "#!", main = "Rtestm.mpl"

(5)

Rtestm:-Rtest()

"this is a test"

(6)

""Rtestm:-NewTest"()"

currentdir()

"C:\Users\Ronan\Documents\MAPLE\Rational_Trinonometry"

(7)

restart

Read*"C:\\Users\\Ronan\\AppData\\Local\\Temp\\Rtestm\\Rtestm.mpl"

Read*"C:\Users\Ronan\AppData\Local\Temp\Rtestm\Rtestm.mpl"

(8)

Rtestm:-Rtest()

Error, Rtest is not a command in the Rtestm package

 

Rtestm:-NewTest()

Error, NewTest is not a command in the Rtestm package

 

``

Download 1-CodeBuilder_Pkg_test.mw

@Joe Riel 

Hello,

I am plotting a three dimensional plot within a range in maple. There are two variables x and y. Third dimension is the objective function ( Z).

On this three dimensional plot, I want to show the point ( preferably by some colour, say red) which have maximum objective value. How it can be done in maple?

Also, Can I show the maximum objective function value (Z) and its coordinates (x,y) on the graph.

Thanks and regard,

Nilesh

I want ot add an annotation to a plot using the drawing facility. Then I export the plot. My problem is that I cannot increase the viewport of the plot without also increasing the size of the plot. For example the code:

plot(20-(20*(1/10))*P, P = 0 .. 10, labels = ["Q", "P"], scaling = constrained, tickmarks = [5, 3], size = [600, 400])

 

produces this plot:

I have constrained the plot and used the size option which together have the side effect of giving me more horizontal space. But this is a wretched hack! I want to size the viewport of the plot so I can write on it.

 

For sqrt(-1), Maple returns I. Why not -I? I understand why in general Maple does not, and should not, return both signs, because sqrt is defined with a branch cut - specifically out along the negative real axis:

FunctionAdvisor(branch_cuts,sqrt(s));

But as +I and -I lie symmetrically around the branch cut, I do not understand why +I should be chosen in favor of -I. Neither the square of +I or of -I crosses the branch cut, which is,  I guess, the standard way to select a unique value, although both squares end up on the branch cut itself - the latter fact leading to the following more general consideration:

I do not understand why the square root of any negative real number (the above being just a specific case) should at all be assigned any meaning when lying as they do on the branch cut itself. I think it would be more sensible if Maple raised an error, telling you that the branch cut needs to be changed/moved if any value is to be assigned. Which leads me to the following question:

Can the branch cut of the logarithm, and thus of sqrt as well, be changed/moved? I would like it to lie out along the negative imaginary axis.

Update I: Concerning -1 lying on the branch cut itself, there is no issue, see my 'ups' in the reply to the answer by John May. But redefining the branch cut is still relevant.

Update II: Perhaps the issue raised is not all that trivial, after all. At least, it is "a subject of papers and debate", as Alejandro Jakubi formulated it in an email to me, pointing me to the article 'Function evaluation on branch cuts', by Rich and Jeffrey.

I have a symmetric big matrix (1000*1000). Some of its rows and columns are zero. Is there any command in Maple that recognize these rows and columns and then remove them to form new matrix?

What do you recommend?

Hello!

 

When I use simplify((t-1)/(-1+2*t)) it returns the same thing I entered, how come Maple doesn't return the actual simplified version that is (1/2)-(1/(2*(2*t-1))), even when using expand, it doesn't return anything really that good.

 

Do anyone know a good idea to get the desired result via Maple? Thank you. 

I am stumped with this trivial puzzle.  Let
z := arctan(x/sqrt(a^2-x^2));
                    
How do we simplify z to.

I tried all sorts of tricks with simplify(...) and convert(...), with assumptions, but did not get anywhere.  Any clues?

Versions: Maple 2016 and 2017.

I was trying to answer a question by torabi 25, August 14, 2017 to speed up his calculations. I got this idea of converting the original code to a procedure - that was not easy, run the procedure and obtain a value of time() to establish a baseline, and making sure the answer from the procedure was the same as from torabi 25. So far so good. Then I would compile the procedure, execute it, and get another value for time(). Hopefully the compiled procedure will be faster than the uncompiled procedure. I am close, but - please see if you can fix my compiler error. Thanks!


 

restart

pa := proc (k::integer, h::float, N::float, nu::float, E_m::float, E_c::float, rho_m::float, rho_c::float, d::(Matrix()))::float; local lambda_m::float, lambda_c::float, mu_m::float, mu_c::float, Z::float, U::float, S::float, e2::float, f::float, W::float, z::float, b::integer, alpha::integer, beta::integer; 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; 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 f := 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); e2 := e2-(int(f, z = -(1/2)*h .. (1/2)*h)) end do end do end do end proc

NULL

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.; d := Matrix([evalf([0, 0, 0, 0, 0, 0, 0, 0]), evalf([sqrt(3), 0, 0, 0, 0, 0, 0, 0]), evalf([0, sqrt(15), 0, 0, 0, 0, 0, 0]), evalf([sqrt(7), 0, sqrt(35), 0, 0, 0, 0, 0]), evalf([0, sqrt(27), 0, sqrt(63), 0, 0, 0, 0]), evalf([sqrt(11), 0, sqrt(55), 0, sqrt(99), 0, 0, 0]), evalf([0, sqrt(39), 0, sqrt(91), 0, sqrt(143), 0, 0]), evalf([sqrt(15), 0, sqrt(75), 0, sqrt(135), 0, sqrt(195), 0])], datatype = float[8])

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

2.156

(1)

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

-0.3192307695e12*W(1)+0.4396880666e12*W(3)-0.1474586302e12*W(5)-0.9235575679e11*W(2)+0.1979090107e12*W(4)

(2)

# Original Answer:        -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);NULL

cpa := Compiler:-Compile(pa)

Error, (in Compiler:-Compile) Array parameter types must specify a hardware datatype

 

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

0.

(3)

cpa(k, h, N, nu, E_m, E_c, rho_m, rho_c, d)

NULL


 

Download for_(5).mw

 

Is there a routine available to derive the variable (i.e for any given z) for the standard normal loss function, L(z)?

If we know the value of L(z), how can z be determined?

mathcontainerUses_Doubt.mw
 

restart; d[1] := [2.36, 26.90], [2.75, 30.0], [3.14, 31.9], [3.53, 32.8], [3.93, 33.4], [4.32, 32.8], [4.71, 31.9]

[2.36, 26.90], [2.75, 30.0], [3.14, 31.9], [3.53, 32.8], [3.93, 33.4], [4.32, 32.8], [4.71, 31.9]

(1)

NULL

d[2] := [2.36, 32.40], [2.75, 34.90], [3.14, 36.90], [3.53, 38.00], [3.93, 38.40], [4.32, 37.8], [4.71, 36.5]

[2.36, 32.40], [2.75, 34.90], [3.14, 36.90], [3.53, 38.00], [3.93, 38.40], [4.32, 37.8], [4.71, 36.5]

(2)

d[3] := [2.36, 27.9], [2.75, 28.3], [3.14, 30.0], [3.53, 30.9], [3.93, 31.3], [4.32, 30.8], [4.71, 29.7]

[2.36, 27.9], [2.75, 28.3], [3.14, 30.0], [3.53, 30.9], [3.93, 31.3], [4.32, 30.8], [4.71, 29.7]

(3)

y := a*x^2+b*x+c; for i to 3 do d[i] := [d[i]]; c[i] := CurveFitting[LeastSquares](d[i], x, curve = y) end do

HFloat(8.047886108501745)+HFloat(11.793324911833839)*x-HFloat(1.5172878997894277)*x^2

(4)

 

curve1 := [c[1], c[2]]; k[1] := [1, 2]; curve1p := [d[1], d[2]]; l[1] := "plot 1"

"plot 1"

(5)

curve2 := [c[2], c[3]]; k[2] := [2, 3]; curve2p := [d[2], d[3]]; l[2] := "plot 2"

"plot 2"

(6)

curve3 := [c[1], c[3]]; k[3] := [1, 3]; curve3p := [d[1], d[3]]; l[3] := "plot 3"

"plot 3"

(7)
Table 1

 

xlabel := "Brake Power"; ylabel := "Efficiency"

"Efficiency"

(8)

p1 := plot(curve1, x = 2.0 .. 5.0, labels = [xlabel, ylabel], labeldirections = ["horizontal", "vertical"], color = [black], linestyle = [1, 2], thickness = [3, 1], title = Title, caption = "Fig. 1 cool  Example 1", legend = ["curve1", "curve2"]); p2 := plot(curve1p, style = point, color = [black], symbol = [soliddiamond, box], symbolsize = 10); plots:-display(p1, p2)

 

p1 := plot(curve2, x = 2.0 .. 5.0, labels = [xlabel, ylabel], labeldirections = ["horizontal", "vertical"], color = [black], linestyle = [1, 2], thickness = [3, 1], title = Title, caption = "Fig. 1 cool  Example 1", legend = ["curve1", "curve2"]); p2 := plot(curve2p, style = point, color = [black], symbol = [box, point], symbolsize = 10); plots:-display(p1, p2)

 

p1 := plot(curve3, x = 2.0 .. 5.0, labels = [xlabel, ylabel], labeldirections = ["horizontal", "vertical"], color = [black], linestyle = [1, 2], thickness = [3, 1], title = Title, caption = "Fig. 1 cool  Example 1", legend = ["curve1", "curve2"]); p2 := plot(curve3p, style = point, color = [black], symbol = [soliddiamond, point], symbolsize = 10); plots:-display(p1, p2)

 

 

"for j from 1 to 3 do  print( Report on l[j]); for i in k[j] do x1(i):=solve((ⅆ)/(ⅆ x)c[i]);  y1(i):=eval( c[i], [x = x1(i)]):  print( Maximum brake thermal efficiency of,y1(i) "%"occurs at brake power value of , x1(i)kW);  end do;  end do;"

Maximum*brake*thermal*efficiency*of, HFloat(30.964188366461613)*"%"*occurs*at*brake*power*value*of, 3.886317459*kW

(9)

NULL


 

Download mathcontainerUses_Doubt.mw

Can any one state the uses of mathcontainer?

1. It can store only one algebraic expression at a time?

2. Can it handle list of algebraic expressions?

3. Can it store list data points (x,y) for a list of curves?

4. Can there be any use for click to edit this component?

More than a simple Yes or No a simple example for each yes answer would be very helpful.

I enclose a document with list of coordinates for for three curves, expression for curve fitting, three expressions derived for these plot points (coordinates), a command for optimum y for each of the three curves (maximum y and corresponding x value), 

Thanks for answering.

Ramakrishnan V

First 942 943 944 945 946 947 948 Last Page 944 of 2428