pagan

5147 Reputation

23 Badges

17 years, 124 days

 

 

"A map that tried to pin down a sheep trail was just credible,

 but it was an optimistic map that tried to fix a the path made by the wind,

 or a path made across the grass by the shadow of flying birds."

                                                                 - _A Walk through H_, Peter Greenaway

 

MaplePrimes Activity


These are answers submitted by pagan

What are you trying to accomplish with this?

int(R(a, t), a = 0 .. infinity) := R(a, t);

You mentioned recursion (of some sort). Is that intended to be part of such? If not, then what is it intended to bring about? As it stands, it assigns to the remember table of int(), a bit as if you were trying to teach it a rule. But how is it supposed to make sense, if the dummy `a` disappears on the LHS?

Either way should work. Using the 2-argument form of Create is "easier".

> foo := proc(param1,param2)
> local res1,res2,bar,id1,id2;
> uses Threads;
>   bar := proc(a,b) assign(b,a^2); NULL; end proc;
>   id1:= Create(bar(param1, res1));
>   id2:= Create(bar(param2, res2));
>   Wait(id1);
>   Wait(id2);
>   print(res1);
>   print(res2);
> end proc:
>
> foo(3,17);
                                       9

                                      289


> foo := proc(param1,param2)
> local res1,res2,bar,id1,id2;
> uses Threads;
>   bar := proc(a) a^2; end proc;
>   id1:= Create(bar(param1), res1);
>   id2:= Create(bar(param2), res2);
>   Wait(id1);
>   Wait(id2);
>   print(res1);
>   print(res2);
> end proc:
>
> foo(3,17);
                                       9

                                      289
> r1 := fsolve(x^2/20-10*x-15*cos(x+15),x);
                               r1 := 1.274092075

> fsolve(x^2/20-10*x-15*cos(x+15),x=0..infinity,avoid={x=r1});
                                  200.1193789

There is a command to show the underlying storage of a Matrix.

> M := Matrix(100,100,'storage'='sparse'):

> MatrixOptions(M,'storage');
                                    sparse

There are also ways to see the exact number of stored entries.

> N := Matrix(100,100):

> rtable_num_elems(N,'Stored');
                                     10000
 
> M := Matrix(100,100,'storage'='sparse'):

> rtable_num_elems(M,'Stored');
                                       0

> M[3,3]:=1.0:
> rtable_num_elems(M,'Stored');
                                       1

That error message with HWcall[1] looks like a bug. You could report it. If you post it then someone might suggest a workaround.

 

> closest := (A::Matrix,value) -> rtable_scanblock(A,[rtable_dims(A)],
>     (val,ind,res)->`if`(abs(val-value)<abs(res[2]-value),
>     [ind,val],res),[[1,1],A[1,1]]):

> M:=LinearAlgebra:-RandomMatrix(5);
                          [ 76     20     31    94    -16]
                          [                              ]
                          [-44    -61    -50    12     -9]
                          [                              ]
                     M := [ 24    -48    -80    -2    -50]
                          [                              ]
                          [ 65     77     43    50    -22]
                          [                              ]
                          [ 86      9     25    10     45]
 
> closest(M,5.1);
                                  [[5, 2], 9]

array and matrix are deprecated in favour of Array and Matrix.

No doubt this could be made more efficient (eg. create graph by specifying all vertices in just a single call) and much more robust.

with(XMLTools):
with(GraphTheory):
G := Graph(0);

Input := CleanXML(ReadFile("biobased.xml")):
bottom:=GetChild(Input,3);
numelems := ContentModelCount(bottom);
graphtype := op(1,bottom);
elems := seq( GetChild(bottom,i), i=1..numelems):
nodes,edges := selectremove(t->type(t,specfunc(anything,_XML_node)),[elems]):

for i from 1 to nops(nodes) do
  temp := nodes[i];
  if HasAttribute(temp,"id") then
    nodenum,nodename := parse(rhs(GetAttribute(temp,"id"))),
                        GetChild(GetChild(temp,1),1);
    mapping[nodenum] := nodename;
    G:=AddVertex(G,nodename);
  end if;
end do:

for i from 1 to nops(edges) do
    temp := edges[i];
    src,targ,edgename := parse(rhs(GetAttribute(temp,"source"))),
                         parse(rhs(GetAttribute(temp,"target"))),
                         GetChild(GetChild(temp,1),1);
    AddEdge(G,{mapping[src],mapping[targ]});
    SetEdgeAttribute(G,{mapping[src],mapping[targ]},name=edgename);
end do:

eval(G);

GetEdgeAttribute(G,{"gasifier","methanolProduction"},name);

DrawGraph(G,style=circle); # resize using mouse-pointer

Could "graphml be a format supported by GraphTheory:-ImportGraph?

Can you roll you own routine to do this sort of thing? Maybe something like this?

> f := proc(X) if degree(X,{x,y,z})>8 then 0 else X; end if; end proc:

> expr := a*x^3*y^3 + b*x^3*y^6*z + c*x^2*y^2*z + d*x^9 + 1;
                         3  3      3  6        2  2        9
              expr := a x  y  + b x  y  z + c x  y  z + d x  + 1

> map(f,expr);
                               3  3          2  2
                            a x  y  + 1 + c x  y  z

> f := proc(X) if degree(X,{x,y,z})>4 then 0 else X; end if; end proc:

> expr := a*x^2*y + b*x^3*y^4*z + c*x^2*y*z + d*x^8 + 1;
                          2        3  4        2          8
               expr := a x  y + b x  y  z + c x  y z + d x  + 1

> map(f,expr);
                                2            2
                             a x  y + 1 + c x  y z

If A*x=lambda*x holds then what could you say about  A*(rho/nu)*x= lambda*(rho/nu)*x ?

Maybe his example was more like the following (which do not seem to work in Maple 13).

expr := piecewise(t>3/2,t*Unit(m),t*2*Unit(m)):

plot(expr,t=1..2*Unit(s));
plot(expr,useunits=[Unit(s),Unit(m)],t=1..2*Unit(s));

Those might be made to work, without having to change the piecewise itself, by calling plot on an operator instead,

plot(unapply(expr,t),1..2*Unit(s));
plot(unapply(expr,t),useunits=[Unit(s),Unit(m)],1..2*Unit(s));
The plotting should also work for an expression like piecewise(...)*Unit(m), without recourse to operators, but maybe his expression was already obtained. It's not so easy to check a piecewise for a common dimension and pull it out as a common unit (respecting possible conversions).

 

Look at CI(x), rather than at CI(0.9), since that is what plot3d is seeing.

You could have a look at the Maple help page for mod.

If I understand what you want, then you might look at these

> restart:
> 3*x mod 2 = 1;
                                     x = 1
 
> restart:
> msolve(3*x=1,2);
                                    {x = 1}
 
> restart:
> Roots(3*x-1) mod 2;
                                   [[1, 1]]

Note that you can simplify the rhs

> simplify( E(x+1)=E(x)+(E(x)*(P-E(x)))/P*10 );
                                   E(x) (-11 P + 10 E(x))
                      E(x + 1) = - ----------------------
                                             P

Suppose that you construct a procedure that computes E(x), and which does so by calling E(x-1).

> simplify( E(x)=E(x-1)+(E(x-1)*(P-E(x-1)))/P*10 );
                             E(x - 1) (-11 P + 10 E(x - 1))
                    E(x) = - ------------------------------
                                           P

You should probably first see whether the rsolve command can do anything nice with it.

If not, then construct procedure E by with `option remember` so that each separate inner invocation of E(x-1) does not needlessly duplicate each others' subcomputations. (You want to avoid unnecessary growth of the computation tree.)

> restart:
> P:=15000:
> E:=proc(x) option remember;
>    -E(x-1)*(-11*P+10*E(x-1))/P;
> end proc:
> E(1):=1:

Now observe how the length of the exact results grows, and how the computation time grows.

> for i from 10 to 18 do
> st:=time():
> print([length(E(i)), time()-st]);
> end do:
                                  [3270, 0.]

                                  [6541, 0.]

                                [13080, 0.004]

                                [26159, 0.008]

                                [52316, 0.020]

                                [104630, 0.080]

                                [209260, 0.292]

                                [418520, 1.128]

                                [837038, 4.345]

Deduce how long the result for E(20) would be, and how much time it would take to compute it.

Try it all again, but with evalf(...) around the inside of the E procedure. Try it also without the option remember, and find the timings and lengths for i=1..6, and make inferences.

Suppose that you have extracted the Matrix of coefficients and the right-hand-side like this

M,B:=LinearAlgebra:-GenerateMatrix(...)

Then, you can try to solve it like this

LinearAlgebra:-LinearSolve(M,B);

If your system turns out to be inconsistent (and if that is not simply due to input error on your part) then you might consider trying to fit a least squares solution

LinearAlgebra:-LeastSquares(M,B);

Will this so?

> e1 := diff(f(x,y),x);
                                     d
                               e1 := -- f(x, y)
                                     dx

> eval(e1, [f(x,y)=f(xi(x),zeta(y))]);
                                              /d       \
                      D[1](f)(xi(x), zeta(y)) |-- xi(x)|
                                              \dx      /

> eval(%, [xi(x)=x/x0,zeta(y)=y/y0]);
                                       x     y
                              D[1](f)(----, ----)
                                       x0    y0
                              -------------------
                                      x0

> e2 := diff(f(x,y),x$2) + diff(f(x,y),x) + diff(f(x,y),y);
                     / 2         \
                     |d          |   /d         \   /d         \
               e2 := |--- f(x, y)| + |-- f(x, y)| + |-- f(x, y)|
                     |  2        |   \dx        /   \dy        /
                     \dx         /

> eval(e2, [f(x,y)=f(xi(x),zeta(y))]);
                                                                 / 2       \
                           /d       \2                           |d        |
D[1, 1](f)(xi(x), zeta(y)) |-- xi(x)|  + D[1](f)(xi(x), zeta(y)) |--- xi(x)|
                           \dx      /                            |  2      |
                                                                 \dx       /

                               /d       \
     + D[1](f)(xi(x), zeta(y)) |-- xi(x)|
                               \dx      /

                               /d         \
     + D[2](f)(xi(x), zeta(y)) |-- zeta(y)|
                               \dy        /

> eval(%, [xi(x)=x/x0,zeta(y)=y/y0]);
                  x     y               x     y               x     y
      D[1, 1](f)(----, ----)   D[1](f)(----, ----)   D[2](f)(----, ----)
                  x0    y0              x0    y0              x0    y0
      ---------------------- + ------------------- + -------------------
                 2                     x0                    y0
               x0
First 42 43 44 45 46 47 48 Page 44 of 48