MaplePrimes Questions

restart;

A:= Matrix();

A := Matrix(1, 0, {})

(1)

i_choices:= [seq(i,i=0..10,1)];

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

(2)

j_choices:= [seq(j,j=0..10,1)];

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

(3)

for i in i_choices do:
 for j in j_choices do:
   A[i,j] :=i+j;
   print(A[i,j]);
 od:
od;

Error, Matrix index out of range

 

Download test_Matrix.mw

I would ask, why is the value of the global variable changed in procedure?

for example, we first define a global A2 and a proc()
but the value of A2 is changed in proc()?

How to fix this error?

Dill_ABC_Model_PDE_System_Solution.mw

The attached Maple 2019  document attempts to solve a non-linear system of two coupled, time-dependent first-order PDE's, given a list of initial and boundary conditions.  The system models the optical transmittance through a thin photoresist layer whose transmittance changes upon exposure to the incident exposure energy, and hence, the cumulative transmittance through the layer is itself a function of both the exposure time and the distance traveled through the resist layer.  The list of fixed parameters, P, defines the characteristics of a particular photoresist (hereafter "pr") and an assumed exposure irradiance.

My first attempt towards a general solution without initial or boundary conditions (hereafter "ics" & "bcs") apparently "succeeds" (in that no error messages are thrown), however, the form of the solution is quite complicated and difficult (for me at least) to interpret.  I think I understand that the _Cn are undefined constants that require supplying ics & bcs to determine the solutions for the transmitted intensity I(z,t) & the normalized molar fraction of the photo-active component in the pr, M(z,t).  However I do not understand what the symbol _f refers to in the returned solutions.

I make a second attempt to solve the system numerically, supplying a list of the [ics,bcs] as arguments to Pdesolve, however the error message "Error, (in pdsolve/numeric/process_PDEs) PDEs can only contain dependent variables with direct dependence on the independent variables of the problem, got {Iota(0, t), Iota(z, 0), Mu(0, t), Mu(z, 0)}" raises the question of whether I have misunderstood the required syntax in using Pdesolve or that the system as posed is in fact insoluble by Maple.

I would appreciate any insights that readers of this post can contribute, as my experience using Maple and PDesolve in particular must be considered embryonic at best.

Scott Milligan

Is their way to create a Random simple directed graph using random graphs package

RandomDigraph function I dont see an option to restrict it to give only simple graphs

Kind help if any code or way I can do that

One more thing is I dont see any directed special graph in maple

I would like to read data from a google sheet document. I can download a local copy to excel format, but then I'm no longer tied to the origional file.

Let's say I am solving a system of differential equation numerically with dsolve. 

In psolve, I use the option output = Array(...), and I assign the result of the call to a variable p. Given my problem such calls can take a few minutes to run.

Later I use odeplot and pass in this variable p. In this workflow I am doing all this in a single worksheet.

Now, I'd like to run dsolve multiple times and save the results of calls to files so that I can plot them later (what I am actually doing is running some code using the Grid package, and I would like each parallel process to save the plot data).

It would actually be great if I could run this code as a batch file. I am not sure how to do this yet (I read about some command line mode that would be best for this). 

So my questions are

- What is the recommended way to save data to files for loading later on?

- Does the answer the the above question work in command-line mode?

Hi Everyone, 

ich have a question, that is probably rather trivial. I am currently doing some calculations with the differential geometry package. (I know the Physics package was recommended, however, the DG package seems more appropriate for my purposes after having a look through the Physics help page)

My goal is to substitute a functional expression into equations derived in curvilinear (spherical and helical) coordinates. my problem now is that maple won't expand the differentials of the expressions I have substituted. 

I hope the answer isn't too trivial. Although I assume it will be :) 

NULL

restart

with(DifferentialGeometry); with(Tensor); with(Tools); Preferences("ShowFramePrompt", false); with(VectorCalculus); BasisFormat(false)
``

DGsetup([r, theta, phi], M)

DGsetup([r, theta, phi], M)

(1)

Defining the Metric Tensor and Calculating the Connection Coefficients

 

g := evalDG(`&t`(dr, dr)+r^2*sin(phi)^2*`&t`(dtheta, dtheta)+r^2*`&t`(dphi, dphi))

_DG([["tensor", M, [["cov_bas", "cov_bas"], []]], [[[1, 1], 1], [[2, 2], r^2*sin(phi)^2], [[3, 3], r^2]]])

(1.1)

g_inv := InverseMetric(g)

_DG([["tensor", M, [["con_bas", "con_bas"], []]], [[[1, 1], 1], [[2, 2], 1/(r^2*sin(phi)^2)], [[3, 3], 1/r^2]]])

(1.2)

C := Christoffel(g)

DGinfo(C, "ObjectComponents")

[[[1, 2, 2], -r*sin(phi)^2], [[1, 3, 3], -r], [[2, 1, 2], 1/r], [[2, 2, 1], 1/r], [[2, 2, 3], cos(phi)/sin(phi)], [[2, 3, 2], cos(phi)/sin(phi)], [[3, 1, 3], 1/r], [[3, 2, 2], -sin(phi)*cos(phi)], [[3, 3, 1], 1/r]]

(1.3)

Defining the PDF as a Tensor (Metric) Density

 

f := f__1(r, theta, phi)

f__1(r, theta, phi)

(2.1)

rho := MetricDensity(g, -1)

_DG([["tensor", M, [[], [["bas", -1]]]], [[[], 1/(r^4*sin(phi)^2)^(1/2)]]])

(2.2)

Tools:-DGinfo(rho, "TensorDensityType")

Convective Operator

 

CONV := CovariantDerivative(v*f, C)

CONV_1 := simplify(ContractIndices(CONV, [[1, 2]]))

CONV_2 := expand(subs(f__1(r, theta, phi) = f__2(r, theta, phi)*rho, CONV_1))

2*f__2(r, theta, phi)*_DG([["tensor", M, [[], [["bas", -1]]]], [[[], 1/(r^4*sin(phi)^2)^(1/2)]]])*v__r/r+v__phi*(diff(f__2(r, theta, phi), phi))*_DG([["tensor", M, [[], [["bas", -1]]]], [[[], 1/(r^4*sin(phi)^2)^(1/2)]]])+v__phi*f__2(r, theta, phi)*(diff(_DG([["tensor", M, [[], [["bas", -1]]]], [[[], 1/(r^4*sin(phi)^2)^(1/2)]]]), phi))+cos(phi)*f__2(r, theta, phi)*_DG([["tensor", M, [[], [["bas", -1]]]], [[[], 1/(r^4*sin(phi)^2)^(1/2)]]])*v__phi/sin(phi)+(diff(f__2(r, theta, phi), theta))*_DG([["tensor", M, [[], [["bas", -1]]]], [[[], 1/(r^4*sin(phi)^2)^(1/2)]]])*v__theta+v__r*(diff(f__2(r, theta, phi), r))*_DG([["tensor", M, [[], [["bas", -1]]]], [[[], 1/(r^4*sin(phi)^2)^(1/2)]]])+v__r*f__2(r, theta, phi)*(diff(_DG([["tensor", M, [[], [["bas", -1]]]], [[[], 1/(r^4*sin(phi)^2)^(1/2)]]]), r))

(3.1)

NULL

In particular, the last line should simplify quite a bit when expanding derivatives.

Download Tensor_Calc_simplified.mw

I hope the solution is not too obvious...

My expression is

G1*P3 + G1*P5 + G1*P6 + G2*P3 + G2*P6 + G3*P2 + G3*P5 + G4*P2 + G4*P3 + G4*P5 + G4*P6 + G5*P2 + G5*P3 + G5*P5 + G5*P6 + G6*P3 + G6*P6 + G7*P2 + G7*P5 + G8*P2 + G8*P3 + G8*P5 + G8*P6

I want this to become as short (in terms of display characters) as possible. I tried simplify, which gives

(G1 + G2 + G4 + G5 + G6 + G8)*P3 + (G1 + G3 + G4 + G5 + G7 + G8)*P5 + (G1 + G2 + G4 + G5 + G6 + G8)*P6 + P2*(G3 + G4 + G5 + G7 + G8)

How do I get

(G1 + G2 + G4 + G5 + G6 + G8)*(P3+P6) + (G1 + G3 + G4 + G5 + G7 + G8)*P5 + (G3 + G4 + G5 + G7 + G8)*P2

which is shorter and which you can get from directly looking at the expression? The Terms Gi and Pj are just scalar variables as a placeholder. Using collect seems only to work on one variable.

dx/dt = x − xy      dy/dt = xy − y

where: x represents prey density and y represents predator density. Create a vector field for this system. The predator should be represented on the y-axis and the prey should be represented on the x-axis. Consider values 0 ≤ x ≤ 3 and 0 ≤ y ≤ 3. Hint: divide the two differential equations.

) Write a procedure that generates a plot of a ‘rose’. If the number of petals is even, have your procedure colour in the petals aquamarine, if the number of petals is odd, colour in the petals pink.

Test your procedure by generating two flowers, one with an even number of petals and one with an odd number of petals.

Consider the function f(x, y) = (x − 3)(y − 2) − 2.

Create a contour plot of f(x, y). Include 20 contour lines.

Encountered new exception using odetest which can't be cought. Is this new one? I do not have earlier version of Maple than 2022.2 to check. On windows 10.

btw, I could not update to latest Physics now, may be server problem.  Attached worksheet

interface(version);

`Standard Worksheet Interface, Maple 2022.2, Windows 10, October 23 2022 Build ID 1657361`

Physics:-Version(latest)

Error, (in Physics:-Version) unable to determine the Physics Updates version, could you please report the problem to support@maplesoft.com

Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 1351. The version installed in this computer is 1348 created 2022, November 14, 15:59 hours Pacific Time, found in the directory C:\Users\Owner\maple\toolbox\2022\Physics Updates\lib\`

restart;

 

sol:=y(x) = -LambertW(x/sin(x)*exp(c[1]/sin(x)))+c[1]/sin(x);
ode:=exp(y(x))+cos(x)*y(x)+(exp(y(x))*x+sin(x))*diff(y(x),x) = 0;
odetest(sol,ode)

y(x) = -LambertW(x*exp(c[1]/sin(x))/sin(x))+c[1]/sin(x)

exp(y(x))+cos(x)*y(x)+(exp(y(x))*x+sin(x))*(diff(y(x), x)) = 0

Error, (in tools/map) too many levels of recursion

try
sol:=y(x) = -LambertW(x/sin(x)*exp(c[1]/sin(x)))+c[1]/sin(x);
ode:=exp(y(x))+cos(x)*y(x)+(exp(y(x))*x+sin(x))*diff(y(x),x) = 0;
odetest(sol,ode);
catch:
   print("error in odetest");
end try;

y(x) = -LambertW(x*exp(c[1]/sin(x))/sin(x))+c[1]/sin(x)

exp(y(x))+cos(x)*y(x)+(exp(y(x))*x+sin(x))*(diff(y(x), x)) = 0

Error, (in tools/map) too many levels of recursion

 

Download problem_odetest_nov_20_2022.mw

I do not know what to do now, since if I can't catch the exception, the program can't run anymore and just stops.

I am trying to do something which I am almost able to do but I have what seems like a final roadblock.

My goal is to be able to call procedures that dynamically update the maple initialization file (init on a Mac, located at ~/Library/Frameworks/Maple.framework/Versions/2022/lib/init).

Let's say this file starts empty.

I want to be able to use a procedure addPackageDirectoryToLibname that will remove all the contents of init and replace it with a newly constructed string. 

The newly constructed string will be libname: and then the previous libname string (which is just libname while the procedure is executing), prepended with an argument to the procedure, packageDir.

So, something like libname := MyNewDir, libname:

I also want to have a procedure removeEntryFromLibname that removes the entry in libname at the argument index.

Now I can already do all of this EXCEPT I can't remove the contents of the file init. Therefore, I am simply adding ever longer strings to init. I don't want to delete the file and recreate it, though I could do this. How do I wipe the contents of init clean programatically?

A few observations

- I had a working version of addPackageDirectoryToLibname but I realized that it was too limited (for the record, it was just adding a new line to the init file each time. The new line was something like libname := MyNewDirectory, libname:.

There is a problem that for my personal use is minor (but if this were for more widespread use I would want to fix it): if addPackageDirectoryToLibname works, you can't call it twice in a row without a restart:, because it depends on the current value of libname. After adding something to libname if you add something else, this something else will be added to the old libname, not the libname that was updated.

If you'd like to see the code I have so far, you can see it in this Github repository.

MyPackageTools := module()
    option package;

    export addPackageDirectoryToLibname, savePackageToMla;

    addPackageDirectoryToLibname := proc(packageDir)

        local mapleInitFile, newLibname:

        mapleInitFile := "/Library/Frameworks/Maple.framework/Versions/2022/lib/init":

        try 
            FileTools:-Text:-Open(mapleInitFile, 'append'):
        catch:
            return "Failed to open file":
        end:

        try
            newLibname := cat("libname := \"", packageDir, "\", libname:" ):
            FileTools:-Text:-WriteLine(mapleInitFile, newLibname):
        catch:
            FileTools:-Text:-Close(mapleInitFile):  
            return "Failed to write to file.": 
        end: 

        try
            FileTools:-Text:-Close(mapleInitFile):   
            return "Added to libname successfully. Restart worksheet for changes to come into effect.":
        catch: 
            return "Failed to close file":
        end:
    end:

    savePackageToMla := proc(mlaPath, mplPath, packageName)

        read(mplPath);

        LibraryTools:-Save(packageName, mlaPath);

    end:
end:

I'd like to automate my workflow a bit. I having a hard time making savePackageToMla work. The commands inside it are the ones I would run in a Maple worksheet to save a package to an .mla file.

The error I get when I try to use this is

Error, (in LibraryTools:-Save) 1st variable is not a name or equation |/Users/marcusegues/maple/Packages/MyPackageTools/MyPackageTools.mpl:38|

Note that the goal is to pass in an mla path and an mpl path. The mpl file is read. The package that is read is the same as the argument packageName. 

I invoke this procedure with something like

savePackageToMla(mlaPath, mplPath, 'MyPackage')

where 

mplPath := '/somePath/MyPackage.mpl';
mlaPath := 'somePath/MyPackage.mla';

and MyPackage.mpl contains something like

MyPackage := module()
  option package;
  (...)
end;

My question is based on this worksheet: uneval.mw

Consider the following procedure

myTest1 := proc()
     local s, gen;
     gen := proc()
          return 5;
     end

     s := seq(['gen()', 'gen()', 'gen()']);
     print(s);
     return s;

end;

If I call this procedure, myTest1(), the result is gen(),gen(),gen() printed out and then also returned from the procedure.

If I change local s to global s, the result changes to 5,5,5. That is, the sequence 5,5,5 is both printed and returned.

Why?

In the attached worksheet I have both cases that you can test.

First 24 25 26 27 28 29 30 Last Page 26 of 2195