MaplePrimes Questions

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.

Dear all

I have a function F(x,t) , I would like to get the first asymptotic approximations of this function when t goes to infinity for fixed x

But maple return 

Error, (in asympt) unable to compute series

series.mw

Thank you 

Dears,

Of course, I'm not talking about questioning the structure of the data itself.  This is the basic form of data manipulation in packages such as R, Julia, Python. I am asking what is the DataFrame in Maple for?
Importing a file (attachment) containing about 50,000 rows in 13 columns takes nearly 1 minute. Attempting to do any operation using DataFrame is practically impossible due to computer slowdown. (DELL XPS 17 9710, Maple 2022.2).

Whereas ImportMatrix() and matrix operations (select, remove, map, etc.) take a part of one second.

I wanted to give an example of some simple operation on the DataFrame object, but unfortunately, I lost my patience.

I have attached the file that I wanted to load for testing, which is part of the original (250K rows x 13 columns):

https://www.kaggle.com/datasets/subhamjain/loan-prediction-based-on-customer-behavior?resource=download

50kX13_LOAN.xlsx

It's also possible that I'm doing something wrong..., then I'd like some guidance from you guys. I like the DataFrame concept in Maple. It's just about usability.

wzelik

Hi, 

I have a problem with the graphic of arcsin((2*x)/(1+x^2)). The domain is IR 

arcsin.mw

Ideas? Thanks

Please help me consider the convergence of this improper integral without using Maple. Thank you so much.

First 139 140 141 142 143 144 145 Last Page 141 of 2308