PatrickT

Dr. Patrick T

2108 Reputation

18 Badges

16 years, 317 days

MaplePrimes Activity


These are replies submitted by PatrickT

@acer 

One more question on defining procedures based on solutions of dsolve. What about if the call to dsolve contains an unassigned parameter? Is there a quick way to do this? Thanks for suggestions.

restart:
SOL := dsolve({ diff(x(t),t) = y(t)+x(t), diff(y(t),t) = y(t)-x(t), x(0) = p, y(0) = 1},
             'type' = numeric, 'output' = listprocedure, 'parameters' = [p]):
xt := subsop(3=remember,eval( x(t), SOL )):
yt := subsop(3=remember,eval( y(t), SOL )):
f := (x,y) -> x^2+y^2:

ft := unapply( subs( X=xt(t), Y=yt(t), f(X,Y) ),
              t, 'proc_options' = ['remember','operator','arrow']):

lprint(eval(ft));

ft(0.7);
proc (t) options remember, arrow, operator; xt(t)^2+yt(t)^2 end proc
Error, (in xt) parameters must be initialized before solution can be computed
temp := subs( unassigneddummy = f(xt(t),yt(t)), t -> evalf(unassigneddummy) ):

fft := subsop(3=op({op(3,eval(temp)),'remember'}), eval(temp) ):

lprint(eval(fft));

fft(0.7);
proc (t) options remember, arrow, operator; evalf(xt(t)^2+yt(t)^2) end proc
Error, (in xt) parameters must be initialized before solution can be computed

If the parameter is assigned, as with your example, it will work:

SOL := dsolve({ diff(x(t),t) = y(t)+x(t), diff(y(t),t) = y(t)-x(t), x(0) = 1, y(0) = 1},
             'type' = numeric, 'output' = listprocedure):
xt := subsop(3=remember,eval( x(t), SOL )):
yt := subsop(3=remember,eval( y(t), SOL )):

@acer

This is very helpful acer, thanks, you solve some problems I had, which had to do with trying to define the procedures with "t ->" where the t had already been assigned (it wasn't obvious at the time, it is now).


> in general you might have to be careful about scoping, sometimes, and ensure that the names used in the unapply and function calls (eg. t) aren't assigned.

your help is very timely too, I will be able to proceed with my simulations rather quicker than I would have otherwise, thanks.

comment in passing, I noticed that the order of the options in the list is not preserved, and inferred that a set instead of a list can be used too (it seems): 'proc_options'={'remember','operator','arrow'}):

@Dave L 

I have run into a little difficulty.

How does one add the option "remember" to a function of procedures?


SYS := ...
VAR := [ u(t), r(t), q(t) ]:
INI := ...
SOL := dsolve([SYS,INI], VAR, type = numeric,  ...
   

# Define Functions of Solution
ut := t -> subsop(3=op({op(3,eval(eval(u(t),SOL))),remember}), eval(u(t),SOL)): ut(t): op(3,ut(t));
rt := t -> subsop(3=op({op(3,eval(eval(r(t),SOL))),remember}), eval(r(t),SOL)): rt(t):
qt := t -> subsop(3=op({op(3,eval(eval(q(t),SOL))),remember}), eval(q(t),SOL)): qt(t):
ct := t -> eval(Cru(r(t),u(t)),SOL):  'ct(t)' = ct(t);


remember,

  Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.

As you can see from the edited input and output above, I have used the tricks you taught me to define procedures ut(t), rt(t), qt(t). This works properly. However, I'm also interested in manipulating functions of these, as discussed in a previous comment.

The last object, named ct(t),  is a known function of the solution procedures u(t) and r(t).

How can I add the option remember to the procedure defined by the function Cru(r,u), where Cru is a known function, where r and u are procedures derived from the solution to dsolve?

many thanks Dave !

the quickest way to get an answer, post your code or better still the relevant part of it. If your problem occurs in the middle of a long worksheet, simply copy the output of the stuff just before dsolve, in particular the system, the initial conditions, the variables.

@Doug Meade 

I second Doug's suggestion for improvements in ListTools:-Search

It would be nice to be able to do things like this:

ListTools:-Search(1..3,[1,2,3]);
                              
ListTools:-Search(>2,[1,2,3]);

@Doug Meade 

I second Doug's suggestion for improvements in ListTools:-Search

It would be nice to be able to do things like this:

ListTools:-Search(1..3,[1,2,3]);
                              
ListTools:-Search(>2,[1,2,3]);

Most of the time when I google a few keywords like "maple how to do this or that" I find a link to a question I asked a few months or years ago...

maybe I do need pills  ;-)

But obviously I'm not the only one with memory problems! from 3 days ago:

http://www.mapleprimes.com/questions/121308-Min-And-Max-Of-X-Axis-When-Using-Plotspointplot#comment121312

 

I forgot about this option. Thanks Giorgios. I disabled the limitation, ran the worksheet, no warnings, no noticeable performance issue, so far so good.

Is there a way to set this option within a worksheet? via interface?

It seems that other options can be, why not this one?

http://www.maplesoft.com/support/help/Maple/view.aspx?path=interface

I forgot about this option. Thanks Giorgios. I disabled the limitation, ran the worksheet, no warnings, no noticeable performance issue, so far so good.

Is there a way to set this option within a worksheet? via interface?

It seems that other options can be, why not this one?

http://www.maplesoft.com/support/help/Maple/view.aspx?path=interface

useful fact of the day:

?proc

 

 

The Operands of a Procedure

 
• 

A Maple procedure is a valid expression like any other (e.g. integers, sums, inequalities, lists, etc.). As such, it has sub-parts that can be extracted using the op function. A procedure has eight such operands:

  

op 1 is the parameterSequence,

  

op 2 is the localSequence,

  

op 3 is the optionSequence,

  

op 4 is the remember table,

  

op 5 is the descriptionSequence,

  

op 6 is the globalSequence,

  

op 7 is the lexical table (see note below), and

  

op 8 is the returnType (if present).

• 

Any of these operands will be NULL if the corresponding sub-part of the procedure is not present.

 

@Alejandro Jakubi 

Alejandro, you are our collective memory!

(I posted on one of the two threads you link to, and I now remember reading the other one too, so that tells you how bad my memory is!!)

@Wang Gaoteng 

you can test to see where the problem comes from. For instance, open your jpg from some image viewer and print it (before you insert it into your text document). Also why don't you experiment with other formats.

I use the following irfanview (windows) and gimp (windows and linux). Irfanview is very light, so ideal for some testing.

@Wang Gaoteng 

you can test to see where the problem comes from. For instance, open your jpg from some image viewer and print it (before you insert it into your text document). Also why don't you experiment with other formats.

I use the following irfanview (windows) and gimp (windows and linux). Irfanview is very light, so ideal for some testing.

@Dave L 

that's great Dave, your explanations clarify a great deal. I'll follow up on the links you suggest, and particularly `option system,remember` because I presumably want to avoid garbage.

P.S. Your comment is not upvotable, but I would otherwise click on the button with enthusiasm.

Someone must point it out, the bright side of spam is to bring to the fore old exchanges that might otherwise have been forgotten. So thanks abraham 0, whoever you are, whomever you represent.

First 45 46 47 48 49 50 51 Last Page 47 of 93