5338 Reputation

15 Badges

9 years, 274 days

MaplePrimes Activity

These are answers submitted by tomleslie

Assuming that you want to import data from Excel ranges to and assign these to "sensible" Maple names, consider the attached (contains a lot of step by step comments)

Well actually , as far as Maple is concerned, you hav 32 "variables". You seem to thing that Maple can telll the difference between "variablles" and "paramters" with no guidance. Trust me, this is not going to happen!!

You have 32 unknowns and 6 equations, which essentially means that you can pick any 6 unknowms and solve for these in terms of the other 26. The attached woksheet shows one possibility

I'm not exactly sure what you want because your question is too general.

However tha attached file computes

  1. the "exact" solution,
  2. the "approximate" solution ( using a method with which I am unfamilar)
  3. graphs the difference,
  4.  computes the differnce between the exact an the approximate solution at a few points

I'm not sure if this covers your requirements or not - maybe if you can clarify in some way???

File extension should be .mpl

If I run

read "J:\\Users\\TomLeslie\\testproc.mpl"
create({{a, b}, {b, c}, {b, d}});

where testproc.mpl is

create := proc (data::set)
                        local G;
                        G := GraphTheory:-Graph(data);
                        printf("My Graph is %a", G);
                        save G, "J:\\Users\\TomLeslie\\graph.txt":
              end proc:

Then the file graph.txt appears where I would expect it to.

Before trying the above you will have to change the path names back to those relevant for your machine


  1. Put a colon/semicolon after restart - otherwise maple thinks that you are making multiple assignments (which you aren't
  2. Be careful with brackets. (), [], {} all mean different things to Maple: [] implies an indexed name of some sort, and {} implies a set. () is used for simple grouping of terms within an expression. You have used [] brackets within the expression you wish to solve - syntactically incorrect and confuses Maple

See the attached, which at least executes - not sure you'll like the answer though!

Kitonum's solution will do the solve() operation for each value of b. This can be avoided with

fb:=unapply( solve( [x+b*y=0, b*x-y=10], {x, y}),b);

to produce a function which can be evaluated for any value of b with

fb(10); fb(11); #etc

or for a seqauence of values

seq( [b=j, fb(j)[]], j=10..20);


If you use 2-D math input in Maple then pages are not "mangled" they are "correct"

However I only ever use 1-D math input - I have never worked out what the advantage of 2D math input is supposed to be, and whenever I try it, something breaks, so I avoid it like the plague.

Generally I only ever use the local help on my machine rather than the on-line version. However even on local help pages I have noticed (in Maple 18 and esp Maple 2015) that the "default" presentation format for examples is 2-D Math input: so before using, I change these by unchecking  the View -> Display Examples with 2D Math on the help page. This gives me 1-D math input and copy/paste actions then always work

There appears to be no way convert the on-line Maple help from 2-D math input to 1-D input :-(

A bit like Preben, I had a great deal of difficulty trying to figure out, from your code, exactly what you are trying to do.

I wasn't even certain that your starting equation was of the Lane=Emden type, so I tarted from started from a different angle: I chose the canonical Lane-Emden equation from the Wikipedia page, and wrote the code to solve it. This is attached below

If you compare the graphical output with that on the Wikipedia page, you will note that it is identical. I did also verify that (for the canonical problem) Maple can produce analytical solutions for n=0 and 1, which agree with those on the wikipedia page. However Maple was unable to produce the analytical solution for n=5, which wikipedia says is possible - although - I didn't try very hard with this. I suspect that if I coded the approach for n=5 as shown on the wikipedia page then I would be successful

You may have write privileges - but that doesn't mean that Maple does!

Try starting Maple by right-clicking desktop icon and selecting run as administrator, cos

fd := FileTools[Text][Open]("C:\\foo.txt", create=true,overwrite=true);

works for me

The computation you require is relatively trivial. The optimum method for doing it depends very much on how you subsequently plan to use the data.

For the example you quote f(x,y,z)=x+yz. Well, you could use a 3-D array to store all the values, with

f:=(x, y, z)-> x + y * z;

ans:=Array( -10..10, -10..10, -10..10,

            [ seq
              ( [ seq
                  ( [ seq
                      ( f(x, y, z), x=-10..10)
                ],performing "SENSITIVITY ANALYSIS"

and then access values with (eg) f[2,3,4].

On the other hand you could just define the function

f:=(x, y, z)-> x + y * z;

and compute any values you happen to want on-the-fly.

The optimal method for performing "sensitivity analysis" really depends on exactly  how you are going to use the data, because, generating the data is trivial


To quote the manual entry for dsolve (with my emphasis)

Integrals appearing in answers returned by dsolve are expressed using the inert Int and Intat (not int or intat). These integrals appear when int is not able to calculate them or when it appears to be convenient not to evaluate them during the solving process. You can request the evaluation of these integrals using the value command.

And for some values of m,k in your loops, unevaluated integral were being returned - which broke the subsequent solve() command.

Somehat surprisingly, it seems that the relevant integrals can always be evaluated, and making the change below

soln[m, k] := rhs(dsolve(ode[m, k], f[m, k](r)));


soln[m, k] := value(rhs(dsolve(ode[m, k], f[m, k](r))));

means that your loop now completes, and the result[] table is populated.

See the attached

If your matrix only ever contains (real) numeric values (ie no symbols, complex nos, etc), the you can specifyt the datatype as an option to the Matrix() constructor

M:=Matrix(3,3, datatype=realcons);


M[1,1]:=1, or M[1,1]:=1.0 will work, but M[1,1]:=x, or M[1,1]=1+2*I will throw an error.

On the other hand, if you wnat to place assumptions on pre-existing symbolic matrix entries, then

MM:=Matrix(3,3, symbol=a);
map(assume, MM, real):

works for me

From the Maple toolbar

Help-> Manuals, Resources and more-> Manuals-> Programming Guide

Entering your vector as

v1:=Vector( [ (4/7)*exp(-t)*exp(-4*t)-(4/7)*exp(-t)*exp(3*t),

Then I find either

(combine@expand)~(map(integrate, v1, t));


map(integrate, (combine@expand)~(v1), t);

provides the answer you desire - so I'm not sure what the problem is??

Personally I would probably integrate first and then do the simplification, so use

(combine@expand)~(map(integrate, v1, t));

Your posted code runs in 1070 seconds on my machine

If I reorganise your code so that stuff executes in what I consider to be a logical order, and nothing is executed repeatedly, unless it actually has to be, I can get this down to ~21secs, producing the same answer. The absolute numbers on your machine will differ, but you ought to obtain the 50x improvement

Note that I have done nothing to improve the performance of the fsolve() command based on your specific problem, I have simply eliminated "redundant" operations.

See the attached

Would further improvements be possible??
Probably, but the law of diminishing returns would set in fairly quickly. I did the above improvement in about 15mins. I suspect that there might be another factor of 2 (or so) to be gained, but only if I spent a couple of hours on the problem - not sure I have the time/inclination :-)

First 109 110 111 112 113 114 115 Page 111 of 118