acer

32490 Reputation

29 Badges

20 years, 8 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

Maple 15 showed the double attractor nicely for your correction of the code, eg. with just a few more options to DEplot3d such as,

stepsize = .01, thickness=1, orientation=[90,70,135]

acer

That doesn't look right. You've used  rhs(func(1)[2])*z(t) which is hard-coded to evaluate func at the point 1.

sol1:=dsolve({x(0)=.1,diff(x(t),t)=x(t)},numeric,output=listprocedure);
func := eval(x(t),sol1);
func(2);
sol:=dsolve({z(0)=.1,diff(z(t),t)=func(t)*z(t)}, numeric,known=[func]);
plots:-odeplot(sol,0..4);

Using output=listprocedure makes it a bit easier to understand (I think) than the following, which is more like the original form posed,

restart:
sol1 := dsolve({diff(x(t), t) = x(t), x(0) = 0.1}, numeric):
func := proc(q)
   if not type(q,numeric) then 'procname'(q);
   else rhs( op(2, sol1(q)) ); end if;
end proc:
sol:=dsolve({diff(z(t), t) = func(t) * z(t), z(0) = 0.1},numeric,known=func):
func(2);
plots:-odeplot(sol,0..4);

Perhaps the submitter might also like to know that it is not always necessary to dsolve for a procedural solution to x(t) separately from solving for z(t). For the example given, Maple can solve them together as a coupled system.

restart:
sol:=dsolve({diff(x(t),t)=x(t), x(0)=.1}
            union
            {diff(z(t),t)=x(t)*z(t), z(0)=0.1},
            numeric):
sol(2);
plots:-odeplot(sol,[t,z(t)],0..4);

acer

That doesn't look right. You've used  rhs(func(1)[2])*z(t) which is hard-coded to evaluate func at the point 1.

sol1:=dsolve({x(0)=.1,diff(x(t),t)=x(t)},numeric,output=listprocedure);
func := eval(x(t),sol1);
func(2);
sol:=dsolve({z(0)=.1,diff(z(t),t)=func(t)*z(t)}, numeric,known=[func]);
plots:-odeplot(sol,0..4);

Using output=listprocedure makes it a bit easier to understand (I think) than the following, which is more like the original form posed,

restart:
sol1 := dsolve({diff(x(t), t) = x(t), x(0) = 0.1}, numeric):
func := proc(q)
   if not type(q,numeric) then 'procname'(q);
   else rhs( op(2, sol1(q)) ); end if;
end proc:
sol:=dsolve({diff(z(t), t) = func(t) * z(t), z(0) = 0.1},numeric,known=func):
func(2);
plots:-odeplot(sol,0..4);

Perhaps the submitter might also like to know that it is not always necessary to dsolve for a procedural solution to x(t) separately from solving for z(t). For the example given, Maple can solve them together as a coupled system.

restart:
sol:=dsolve({diff(x(t),t)=x(t), x(0)=.1}
            union
            {diff(z(t),t)=x(t)*z(t), z(0)=0.1},
            numeric):
sol(2);
plots:-odeplot(sol,[t,z(t)],0..4);

acer

@OxidisedLizard Ah, you are using Maple 12.

Better to let us know this detail earlier. I will change the top-post to reflect this.

@OxidisedLizard Ah, you are using Maple 12.

Better to let us know this detail earlier. I will change the top-post to reflect this.

@jeffb Yes, of course that doesn't work.

It doesn't work for those two Matrices with your original code, either.

You cannot multiply a 2x3 Matrix by a 2x3 Matrix, in the usual way. Look at my question to you above, about checking whether the number of columns of A should match the number of rows of B.

@jeffb Yes, of course that doesn't work.

It doesn't work for those two Matrices with your original code, either.

You cannot multiply a 2x3 Matrix by a 2x3 Matrix, in the usual way. Look at my question to you above, about checking whether the number of columns of A should match the number of rows of B.

@Hyperian ...with the op command.

@Hyperian ...with the op command.

@jeffb No, the code I wrote has that op() fragment as it ought to be. op(1,A) should return two values, the row and column dimension of Matrix A.

The code I posted above works for me when I paste it -- as is -- into either Document or Worksheet of the Standard GUI of Maple versions 11.02, 12.02, 13.02, 14.01, 15.01, and 16.00 on MS-Windows.

What version and platform are you using? Can you save your worksheet, once you get the error, and upload it in a Comment here (using the green up-arrow in the Mapleprimes editing menubar)?

@jeffb No, the code I wrote has that op() fragment as it ought to be. op(1,A) should return two values, the row and column dimension of Matrix A.

The code I posted above works for me when I paste it -- as is -- into either Document or Worksheet of the Standard GUI of Maple versions 11.02, 12.02, 13.02, 14.01, 15.01, and 16.00 on MS-Windows.

What version and platform are you using? Can you save your worksheet, once you get the error, and upload it in a Comment here (using the green up-arrow in the Mapleprimes editing menubar)?

@jeffb You haven't shown your revised code, so we cannot tell the source of the error message.

mymatrix:=proc(A::Matrix,B::Matrix)
local i,j,q,C,numrowsA,numcolsA,numcolsB;
   numrowsA,numcolsA:=op(1,A);
   numcolsB:=op([1,2],B);
   C:=Matrix(numrowsA,numcolsB);
   for i from 1 to numrowsA do
      for j from 1 to numcolsB do
         for q from 1 to numcolsA do
            C[i,j]:=C[i,j] + A[i,q]*B[q,j];
         od;
      od;
   od;
   return C;
end proc:

x:=Matrix(3,2,symbol=X):
y:=Matrix(2,4,symbol=Y):

mymatrix(x,y) - x . y;

                                [0  0  0  0]
                                [          ]
                                [0  0  0  0]
                                [          ]
                                [0  0  0  0]

Should you add a check that the number of columns of A equals the number of rows of B?

If you've been instructed to not use any "built-in" routines then the spirit of that instruction is presumably to prevent you from simply using `.` or MatrixMatrixMultiply or something similar. You'll still have to use something to pick off the dimensions of A and B or else you'd have to pass those in as additional arguments in order to have the code get them right. I would guess that you probably are allowed to use LinearAlgebra:-Dimensions(), but if not then you might be allowed to use op() as above.

Don't blindly trust that code above: check it, via understanding.

@jeffb You haven't shown your revised code, so we cannot tell the source of the error message.

mymatrix:=proc(A::Matrix,B::Matrix)
local i,j,q,C,numrowsA,numcolsA,numcolsB;
   numrowsA,numcolsA:=op(1,A);
   numcolsB:=op([1,2],B);
   C:=Matrix(numrowsA,numcolsB);
   for i from 1 to numrowsA do
      for j from 1 to numcolsB do
         for q from 1 to numcolsA do
            C[i,j]:=C[i,j] + A[i,q]*B[q,j];
         od;
      od;
   od;
   return C;
end proc:

x:=Matrix(3,2,symbol=X):
y:=Matrix(2,4,symbol=Y):

mymatrix(x,y) - x . y;

                                [0  0  0  0]
                                [          ]
                                [0  0  0  0]
                                [          ]
                                [0  0  0  0]

Should you add a check that the number of columns of A equals the number of rows of B?

If you've been instructed to not use any "built-in" routines then the spirit of that instruction is presumably to prevent you from simply using `.` or MatrixMatrixMultiply or something similar. You'll still have to use something to pick off the dimensions of A and B or else you'd have to pass those in as additional arguments in order to have the code get them right. I would guess that you probably are allowed to use LinearAlgebra:-Dimensions(), but if not then you might be allowed to use op() as above.

Don't blindly trust that code above: check it, via understanding.

@andrewfortune Applying the ``() procedure to something makes a function call out of it, which prettyprints with round brackets. Thus, ``(17) gets printed as (17), which is useful. And `expand` undoes this, which is also useful.

So, ``(17)! gets printed just as (17)!

The operation subsindets(A,B,C) changes the expression A by substituting C(z) for all subexpressions z in A which are of type B.

For example,

expr:=(sin(2*x)+7)*exp(3*t);

                       expr := (sin(2 x) + 7) exp(3 t)

subsindets(expr,integer,z->z^2);

                          (sin(4 x) + 49) exp(9 t)

Here we have substituted each integer in `expr` by its square.

In simpler terms, what I did to my `T` to get my `Q` was to substitute for everything of a type matching z! with ``(z)!, where z could be anything.

You can `lprint` both `T` and `Q`, to see the difference.

You can also create your own Taylor series operator in Maple. And you can adjust it to suspend the factorial execution, as well.

restart:

taylor(sin(x),x=0,11); # The stock Library routine for this

                  1  3    1   5    1    7     1     9    / 11\
              x - - x  + --- x  - ---- x  + ------ x  + O\x  /
                  6      120      5040      362880            

convert(%,polynom);

                       1  3    1   5    1    7     1     9
                   x - - x  + --- x  - ---- x  + ------ x 
                       6      120      5040      362880   

t:=(e,x,x0,n)->add((x-x0)^i/i!*eval(diff(e,x$i),x=x0),i=1..n):
t(sin(x),x,0,9);

                       1  3    1   5    1    7     1     9
                   x - - x  + --- x  - ---- x  + ------ x 
                       6      120      5040      362880   

q:=(e,x,x0,n)->add((x-x0)^i/``(i)!*eval(diff(e,x$i),x=x0),i=1..n):
q(sin(x),x,0,9);

                            ((e,x,x0,n)->add((x-x0)^i/``(i)!*eval(diff(e,x$i),x=x0),i=1..n))(sin(x),x,0,9)

expand(%);

                       1  3    1   5    1    7     1     9
                   x - - x  + --- x  - ---- x  + ------ x 
                       6      120      5040      362880   

@andrewfortune Applying the ``() procedure to something makes a function call out of it, which prettyprints with round brackets. Thus, ``(17) gets printed as (17), which is useful. And `expand` undoes this, which is also useful.

So, ``(17)! gets printed just as (17)!

The operation subsindets(A,B,C) changes the expression A by substituting C(z) for all subexpressions z in A which are of type B.

For example,

expr:=(sin(2*x)+7)*exp(3*t);

                       expr := (sin(2 x) + 7) exp(3 t)

subsindets(expr,integer,z->z^2);

                          (sin(4 x) + 49) exp(9 t)

Here we have substituted each integer in `expr` by its square.

In simpler terms, what I did to my `T` to get my `Q` was to substitute for everything of a type matching z! with ``(z)!, where z could be anything.

You can `lprint` both `T` and `Q`, to see the difference.

You can also create your own Taylor series operator in Maple. And you can adjust it to suspend the factorial execution, as well.

restart:

taylor(sin(x),x=0,11); # The stock Library routine for this

                  1  3    1   5    1    7     1     9    / 11\
              x - - x  + --- x  - ---- x  + ------ x  + O\x  /
                  6      120      5040      362880            

convert(%,polynom);

                       1  3    1   5    1    7     1     9
                   x - - x  + --- x  - ---- x  + ------ x 
                       6      120      5040      362880   

t:=(e,x,x0,n)->add((x-x0)^i/i!*eval(diff(e,x$i),x=x0),i=1..n):
t(sin(x),x,0,9);

                       1  3    1   5    1    7     1     9
                   x - - x  + --- x  - ---- x  + ------ x 
                       6      120      5040      362880   

q:=(e,x,x0,n)->add((x-x0)^i/``(i)!*eval(diff(e,x$i),x=x0),i=1..n):
q(sin(x),x,0,9);

                            ((e,x,x0,n)->add((x-x0)^i/``(i)!*eval(diff(e,x$i),x=x0),i=1..n))(sin(x),x,0,9)

expand(%);

                       1  3    1   5    1    7     1     9
                   x - - x  + --- x  - ---- x  + ------ x 
                       6      120      5040      362880   
First 410 411 412 413 414 415 416 Last Page 412 of 594