Mac Dude

1496 Reputation

17 Badges

10 years, 205 days

MaplePrimes Activity


These are replies submitted by Mac Dude

@Lali_miani Note that in your example f:=n->n/n+1 is f:=n->1+1 = 2 for all n<>0. Presumably you meant f:=n->n/(n+1)

M.D.

@acer@Christian Wolinski Thanks to both of you.

I learned 2 things:

First, content(), which I have never come across in over 10 years of using Maple. Here it is the key to extracting the 1/1296 factor.

Second: the way you both use what appears to be an unnamed function to apply the inert muliplication to the original expression divided by the 1/1296 factor. Quite slick.

@acer wins by a small margin as his second solution is robust against the typesetting level whereas his first one and @Christian Wolinski's only really work for one of the two.

Thanks much

M.D.

@Preben Alsholm 

@Preben Alsholm  I just edited my reply, since I traced my problem back to the old UsehardwareFloats issue. I confused myself since I work both at home and in the lab on somewhat different setups...

But for illustration, here is what I observe. Note that it uses routines from a package I wrote.

evalf(P0__SR__source:-value(4.75854402042301)); # this works fine
                       -0.943964252157448

fsolve(evalf(P0__SR__source:-value(tt)),tt=4.75); # while technically correct the result is not what I want
                               0.

plot(evalf(P0__SR__source:-value(tt)),tt=(4.75-0.000001)..(4.75+0.000002)); # see plot below

fsolve(evalf(P0__SR__source:-value(tt)),tt=(4.75-0.000001)..(4.75+0.000002)); # trying to trick it... returns unevaluated.
fsolve(sin(6.28318530717958 Typesetting:-msubsup(

  Typesetting:-mstyle(int, mathcolor = "#909090"), 0., tt)

  (289163.632468524 - 0.000771604938271605 RfFreqApplyFunction(ti

  )) Typesetting:-mstyle(DifferentialD, mathcolor = "#909090")ti), 

  tt, 4.749999 .. 4.750002)

MaplePrimes is too fouled up to show the plot else I could show the zeros I am interested in, that are spaced by O(1e-6) about 4.75.

Thanks,

M.D.

Well, I spoke too soon. It appears that fsolve is broken, or at least behaving differently than what I am used to (and my main version of Maple has been 2015 since I had too many issues with the later ones).

The specific use case is a strongly oscillating function (a sine with some high-ish frequency) where I need to pick a specific zero crossing, which I do by giving fsolve a reasonably close initial estimate. That works fine in 2015. In 2022 it returns 0 for all my cases, which is correct but not the zero I want. So it appears fsolve is jumping ahead or back way too aggressively.

I am sure this can be prevented by using intervals and the avoid option, but it seems like a step back. Now, a comment in the Help for fsolve says it got updated in Maple 2018, so maybe that is where the problem arose.

I guess I am a little less excited now. This situation is in a part of code I am using daily right now and cannot afford not to work.

Edit: It turns out this is the old issue in fsolve when using "Usehardwarefloats:=true" (instead of the default "deduced"). So maybe it is not a new problem, although having such a bug hanging around for this long is unsettling in itself.

@nm It is kind-of off-topic, but couldn't you use the GUI components (which can update in place) to get your output per iteration of your loop(s)? Having to clean-up a worksheet manually every-so-often seems kind-of old to me, even if done while the loop is running (which does seem feasible given that the GUI runs as a separate process).

Personally, I keep all output I need from loops in the appropriate data structures for later inspection. Longer loops update a progress gauge so I can be assured things are still running.

As I say, not pertinent to the Maple 2022 release, which I just installed. At first glance it seems to run fine (which I could not say for some of the earlier 202x versions). I am actually looking forward to using it.

M.D.

@AHSAN My aologies, but I do not have time to do this, you will have to put the effort in yourself. Presumably you know what the code is doing so as you convert the statements you can verify they do the expected thing.

M.D.

Please upload your program & data using the green arrow in the editor toolbar.

In general, a fitting procedure can find parameters for a given fitting function (the model you want to validate in a statistical sense). In general a fitter cannot generate the functional form most appropriate (statistically) to describe your data. It can only give guidance (using the Chi-squared criterion) as to which function out of a number of trial functions may be the best.

M.D.

Somewhere in the middle of that long thread @Carl Love  wrote this:

SumList:= proc(L::list)
local S:= 0, i;
    for i to nops(L) do
        S:= S + L[i]
    od;
    S
end proc;

Here S is the variable that the elements of the list L get summed up in. i is the index that addresses each element in the list L when the loop executes. S and i are declared local to SumList so they are not visible outside SumList. S is initialized to 0.

In the for loop, i begins at 1, this is a Maple default when the beginning value is not given. nops(L) is one way in Maple to get the number of elements in the list.

The single S before end proc causes S to be returned to the caller. Again, that is a feature of Maple.

This fulfills your assignment.

M.D.

@nm To close the loop here: You can mimic type extension by, in module dog, setting it manually:

dog:=proc()

     return module()
       export data1:=Animal:-data1;

       export move:=proc(_self,$)
         print("In dog class. moving ....");
         print("data1 = ",data1,"  data2 = ",data2);
       end proc; 

    end module;

  end proc;
 

Now both Animal:-data1 and Buster:-data1 evaluate to whatever Animal:-data1 is set to. But I don't think you can set Buster:-data1 to something and expect Animal:-data1 to follow since assigning something to Buster:-data1 will break the linkage. So it is a one-way mechanism.

M.D.

Animal.mw

@nm I agree with most of what you say, except I would not say returns "just" a module. In fact I cousider the ability of treating procs and modules in the way Maple does it (where they can be handled just like any other data structure) quite cool and useful.

Members of a module do have access to the data structures (or procs, or whatever) of the parent module (Animal in this case), via the lexical scoping mechanism in Maple. I don't have time right now to construct a MWE (work beckons), but I do this all the time (if maybe not in a true OO fashion). It does require some amount of manual work, however. As we agreed, Maple is not an OO language...

M.D.

@ivanwolodin Well, if the sequence I wrote does what you need for one dimension then the extension to two dimensions is trivial: you just wrap a second seq around the first one:

seq(seq(evalf(b*cos(n*Pi/10)),n=0..20,0.1),b=-1..1,0.5);

I hope it is clear that the third argument to the seq() is the stepsize & you need to adjust that to your needs.

Seq() returns a sequence, a comma-separated series of values. Depending on what you do with the result you may need to cast the result as a list or something else, e.g. by applying the suitable delimiters ([] for a list, <> for a Vector). You will need to familiarize yourself with these data structures (RTFM).

It remains as an exercise for you to switch the order of the seq()'s if you need that.

M.D.

@acer Nice, had not thought about that.

M.D.

@acer @Rouben Rostamian ,

Thanks for your replies. Rouben's suggestion is something I shall look into more as it may be the right thing to do. Esp. as @acer indicates that I cannot get what I want using the assign mechanism as it will create  global variables (I did not know that).

Since @acer was looking for context I am attaching the code in which I wanted to use this assign contruct. Note that this is not a complete program, it is the early part of a package I want to write to read data files written in a so-called "SnP" format by some network analyzers (aka Touchstone format). So I write a module that has a proc "Read(filename)" to pull in the data. I eventually want to assign the read-in data to module-specific variables that I can access from the program using this package. (And yes, to do that my Sij actually need to be exports, but I wanted to debug this without having to unprotect all of these guys). Note that the code as attached does not work (yet) since I still need to work on the Read proc which I initially wrote outside of the module (and which does decode the file the way I want it to).

Once I have this part working routines for plotting & other stuff will be added as I have the need.

So, as I am typing this the merits of Rouben's suggestion appear even stronger since I only have the variable "S" to worry about. The fly in the ointment is that the caller (me) has to access the content like S[2,1][index] rather than S21[index], the latter being a more natural way. But I may be able to live with this. Or I can write 99 explicit variables; once I have them defined I assume I can set them using assign(), although now I am no longer sure about that. Note that when reading the files one would not usually have to bulk process all these vectors, often focusing on a small subset (like one or two).

Thanks much for your comments

M.D.

Touchstone.mw

It has changed, but I think it was earlier than Maple 2021. I think add and friends behave the same way now.

M.D.

I suggest you consult @dohashi's Parallel Programmimg Content page, with links to various posts of his.

M.D.

1 2 3 4 5 6 7 Last Page 1 of 42