acer

32333 Reputation

29 Badges

19 years, 323 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

add(x, x in A);

or,

convert(A,`+`);

or, (essentialy like the last one),

`+`(A[]);

acer

If you are not using high precision (ie, Digits > evalhf(Digits) ) then you may as well just use method=LU. And that is the default method for such float data.

Below, I set the infolevel so that some additional details about the computation are shown.

restart;
with(LinearAlgebra):

infolevel[LinearAlgebra]:=2:

A:=Matrix([[1,3],[2,5]],datatype=float):
b:=Vector([1,1],datatype=float):
LinearSolve(A,b);

LinearSolve: using method LU
LinearSolve: calling external function
LinearSolve: NAG hw_f07adf
LinearSolve: NAG hw_f07aef
                                    [-2.]
                                    [   ]
                                    [ 1.]

acer

The display command is part of the plots package. So either load that package first, by issuing,

with(plots):

or call it by its long-form names plots:-display or plots[display].

I edited your code a bit. As a general rule, don't try and use a non-indexed name such as x alongside its indexed form such as x[i]. Check that I didn't mess it up.

restart:

h := .1;
x[0] := 0;
y[0] := 1;
xf := 3;
n := floor(xf/h);
f:= (x,y)->1/(3*y-x-2);

for i from 0 to n do
k1 := f(x[i], y[i]);
k2 := f(x[i]+(1/2)*h, y[i]+(1/2)*h*k1);
k3 := f(x[i]+(1/2)*h, y[i]+(1/2)*h*k2);
k4 := f(x[i]+h, h*k3+y[i]);
k := (k1+2*k2+2*k3+k4)*(1/6);
y[i+1] := h*k+y[i];
x[i+1] := x[i]+h
end do:

data := [seq([x[n], y[n]], n = 0 .. 30)]:

p[2] := plot(data, style = point, color = blue):
p[3] := plot(data, style = line, color = blue):

exact := dsolve( { diff(Y(X),X)=1/(3*Y(X)-X-2), D(Y)(0)=1 } ):

Pexact := plot( eval(Y(X), exact), X=0..3, style=point,
                symbol=cross, symbolsize=20,
                adaptive=false, numpoints=20 ):

plots:-display(seq(p[n], n = 2 .. 3), Pexact);

acer

What you see at the end of the AiryBiZeros procedure is an unevaluated return. Notice the single right-quotes in that function call, which will be a return value.

It just means that, when argument n is something for which the procedure cannot compute a result then the procedure returns an unevaluated function call to itself.

acer

In your example eq is of type `=` and lhs(eq) is of type `+`.

The op command allows you to pick off specific operands (addends of the sum), by position.

restart:

act := proc(eqn)
  if type(eqn,`=`) and type(lhs(eqn),`+`) then
    eqn - op(2, lhs(eqn));
  end if;
end proc:

act( a + b = 0 );

                             a = -b

act( a + b + c = 0 );

                           a + c = -b

acer

eq := (a*b+a)^n * a^(-n):

new := (b+1)^n:

eval( [eq, new], [a=-1, b=-2, n=1/2] );

                            [-I, I]
simplify(eq) assuming real, a>=0;

                                   n
                            (b + 1) 

simplify(eq) assuming n::integer;

                                   n
                            (b + 1) 

acer

Remove the inert=true option.

If you include that option then it returns an inert integral. If you don't then it tries to compute the integral.

acer

What all these do... is another question.

restart:
interface(warnlevel=0):
started := false:
T := 'T':
for i from 1 to 1000 do
  f := eval(parse(cat("proc() option builtin=",i,"; end proc")));
  p := (s->StringTools:-Take(s,StringTools:-Search(";",s)-1))(convert(eval(f),string)[26..]);
  if not type(parse(p),posint) then
    T[i] := p;
    started := true;
  else
    if started then i:=1000; next; end if;
  end if;
end do:
i;
[ entries(T,nolist) ];
nops(%);

acer

Try setting infolevel[`pdsolve/numeric`] before calling the solver.

For example,

infolevel[`pdsolve/numeric`]:=2:

At value 2 I am seeing a brief description, such as, "Deriving 3-point (space) theta scheme for input PDE". At value 3 I am seeing printout of what appear to be differencing procedure(s).

acer

One way to get that smoother is to use the `gridrefine` option of implicitplot. Eg,

plots:-implicitplot(-x^3+3*x+a = 0, a = -3 .. 3, x = -4.0 .. 4.0,
                         view = [-3 .. 3, -4 .. 4], gridrefine = 2);

acer

Try that as `Or`, rather than `OR`.

acer

Look at the help page with topic examples,Explore for the cobweb plot of the logistic map.

For the bifurcation diagram see this message threa on this site.

acer

How you go about it may depend on whether you want to be able to programmatically access any displayed values after manually updating them in the tabulated representation.

If you insert a DataTable Embedded Component from the palettes then you can associate that with a Matrix or Array. This includes the functionality that if you update the Matrix then the DataTable entry reflects that. And vice versa. Also, you can put customized row and column headers on the Component. There is no command at present to insert such a DataTable via a command. (I suspect that it might be done with some very low level XML manipulation, but it is not straightforward and the insertion may be buggy.)

If you only need to display the data and not to interact with it (as you've stated is the case) then there are some undocumented routines that can accomplish this. (These are evident by inspectng the Explore:-ModuleApply and ImageTools:-Embed library procedures.) Of course your success might be limited, with undocumented routines. For example, using Maple 18.01, with the purely numeric entries of data being represented as strings,

restart:

makegrid := proc(M::Matrix)
  uses DocumentTools:-Layout;
  local i,j,m,n,wks;
  m,n := op(1,M);
  wks := Worksheet(Table(alignment=center,width=20,
                         seq(Column(),j=1..n),
                         seq(Row(seq(Cell(Textfield(sprintf("%a",M[i,j]))),
                                     j=1..n)),i=1..m)));
  DocumentTools:-InsertContent(wks);
end proc:

f:=x->x^2:
g:=x->x^3:
data:=[seq([i,f(i),g(i)],i=0..5)]:

makegrid(<<'i'|'f(i)'|'g(i)'>,Matrix(data)>);

In Maple 17 the following seems possible. This makes a little effort at weighting the width of the columns according to string length. (That weighting will break down if the entries are long enough to line-wrap, I think.)

restart:

grid := proc(M::Matrix)
  uses DocumentTools:-Layout;
  local i,j,Ms,m,n,wks;
  m,n:=op(1,M);
  Ms:=map(convert,M,string);
  wks:=XMLTools:-ToString(
         _XML_Worksheet(Table(':-alignment'=':-center',':-width'=20,
           seq(Column(':-weight'=3+max(map(length,Ms[..,j]))),j=1..n),
           seq(Row(seq(Cell(`_XML_Text-field`("alignment"="centred",
                                              "style"="Text",Ms[i,j])),
               j=1..n)),i=1..m))));
  streamcall(INTERFACE_TASKTEMPLATE(':-insertdirect',':-content'=wks));
  NULL:
end proc:

f:=x->x^2:
g:=x->-x^13:
data:=[seq([i,f(i),f(i)/g(i)],i=1..5)]:

grid(<<'i'|'f(i)'|'f(i)/g(i)'>,Matrix(data)>);

The mechanism used above is not in Maple 16 or earlier, so this won't work there.

acer

You wrote that f(t) is a "function". It's not clear whether you mean an expression such as t*sin(t) or an operator (or procedure) such as t->t*sin(t).

Several others have show you different ways of mapping an operator/procedure `f` across a list of values. If your `f` is already a procedure or operator then Carls' and Kitonum's Answers should work fine.

However you also used the word `subs`. So it seems to me that you might possibly have an expression rather than a procedure. If that is in fact your situation then you could do one of the following:

1) Use `unapply` to obtain an operator from the expression, then follow the other suitable Answers.

or,

2) produce a sequence involving `f` with `t` taken from the list. Eg,

T := [0,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]:
f := t^2: 

[ seq( f, t=T ) ];

              [0, 0.04, 0.09, 0.16, 0.25, 0.36, 0.49, 0.64, 0.81, 1]

or,

3) (awkwardly, IMO) map 2-argument eval across the list via a custom operator, Eg,

map( x->eval(f,t=x), T );

              [0, 0.04, 0.09, 0.16, 0.25, 0.36, 0.49, 0.64, 0.81, 1]

If you already have an operator like f=t->t^2 then going the route of turning that into an expression by invoking f(t) say, and then doing 2) above, requires having a free dummy variable. (I never understand why people create operators simply to invoke then one single time. Yet it's quite common to see people start with an expression, unapply it, then apply it as the argument to `plot`, etc.)

acer

You have not indicated very clearly in your question whether you will accept F or G appearing in the representation of B/A and C/A, or not. I am supposing that it is ok for them to appear. You give only a somewhat inarticulate hint that F,G are to be treated differently than `kappa`, `k`,  and `a`, in my opinion.

You can eliminate A,B and C from the four equations. The eliminate command can so that, for this example, as well as provide an additional result (which will still hold for the remaining F and G).

restart:

eq1 := A+B=F+G:
eq2 := k*(A-B)=kappa*(F-G):
eq3 := F*exp(I*kappa*a)+G*exp(-I*kappa*a)=C*exp(I*k*a):
eq4 := kappa*F*exp(I*kappa*a)-kappa*G*exp(-I*kappa*a)=k*C*exp(I*k*a):

S := {eq1,eq2,eq3,eq4}:

Q := eliminate( S, {A,B,C} ):

B/A = eval(B/A,Q[1]);

                      B   F k - F kappa + G k + G kappa
                      - = -----------------------------
                      A   F k + F kappa + G k - G kappa

C/A = eval(C/A,Q[1]);

               C   2 (F exp(I kappa a) + G exp(-I kappa a)) k
               - = ------------------------------------------
               A   exp(I k a) (F k + F kappa + G k - G kappa)

# The second part of the result Q from `eliminate` indicates a remaining
# restriction on the remaining names F,G,a,k, and kappa. If you wish, you can solve this
# for F (or G) for this example. But you don't have to. The elements of the set
# Q[2] are implicitly equal to zero (though below I explicitly make an equation
# of it, just to make the point).

map(`=`,Q[2],0);

     {F exp(I kappa a) k - kappa F exp(I kappa a) + G exp(-I kappa a) k

        + kappa G exp(-I kappa a) = 0}

That remaining restriction on F,G,a,k, and kappa can be used to remove F and G from the representation above for B/A and C/A.

R := solve(Q[2],F);
normal( eval( eval(B/A,Q[1]), R ) );
normal( eval( eval(C/A,Q[1]), R ) );

As Carl's showed, if you don't want F and G to appear then you might as well just do a single `solve` for {A,B,C,F}. Or you could use eliminate with 4 names,

T := eliminate( S, {A,B,C,F} ):
B/A = eval(B/A,T[1]);
C/A = eval(C/A,T[1]);

In some other example it may happen than you can eliminate A,B, and C but not all other instances of some specific subset of the remaining names.

acer

First 232 233 234 235 236 237 238 Last Page 234 of 336