tomleslie

5162 Reputation

15 Badges

9 years, 243 days

MaplePrimes Activity


These are replies submitted by tomleslie

@Carl Love 

Carl,

can you confirm that the worksheet I uploaded actually works and provides a plausible answer (without getting in to fine details like endpoint versus midpoint Riemann sums - which is why [I think] there is a slight diagonal shift between the graphs of the original function and the numerical approximation)

I may be offline for a bit because my keyboard has just died  (and it isn`t the batteries). I`ve just typed the last couple of sentences usin the on-screen keyboard utility and I have to go do some serious debugging on my system hardware :-(

Please don't retype code. Just double-click the link in my previous post and open with maple. Then just click the triple exclamation mark on the maple toolbar to execute the entire worksheet

One reason your latest code does not work is that you can't tell the difference between upper cas and lower case z

To upload code here use the big green arrow in the toolbar

My original code ran in Maple 2015, produced the correct answer, and the graph which you asked for in your original post.

The attached (slightly revised) version runs in Maple18 and Maple2015. I can't try earlier versions of Maple cos I no longer have then installed

RiSum.mw

BTW Anyone else noticed that 2.0*Pi evaluates differently in Maple18 and Maple2015??

 

Have to agree with Kitonum.

Your procedure works for me as well.

Suggests it must be assignments prior to invocation.

Working version in attached worksheet

dList.mw

Getting the correct answer is always good

It is possible to make your code a bit neater

  1. the i+di stuff within the loop can actually be shifted to the loop start/step definition
  2. type(sol1, numeric) will return either "true" or "false". Checking whether the return value equates to true is redundant

Consider the following, which produces the same answer

restart:
L:= 0.3e-1:
L1:= 0.2e-2:
epsilon:= .38:
R:= 1:
eq1:= tan(y*L) = 2*L1*y*epsilon*R/(L1^2*y^2-R^2*epsilon^2);
nLimit:= 3:
lambda:= Vector(nLimit):
di:=25:
n:=1:
for i from 0 by di while n <= nLimit do
     sol1:= fsolve(eq1, y=i..i+di):
     if     type(sol1, numeric)
     then lambda[n]:=sol1;
            n:=n+1:
     fi:
od:
lambda;

Difficult to help because

  1. there seem to be a few terminating semi-colons missing
  2. nLimit not given in your code so loop won't even start
  3. eq1 not defined so I can't try your loop. Only thing I can see is that it has to have at least nLimit solutions for the loop to have any hope of terminating
  4. Suggest you supply eq1 and value for nLimit

So much criticism for a couple of throwaway remarks.

My original solution provided a quick dirty solution which works - so I'm puzzled as to why people object at the additional comments. My justification for these is as follows

Not mixing text and integers in a Matrix:

Well I can think of (at least) four ways for the OP to represent the original data. These are Matrix, Array, table and list of lists: any of these (and there are probably more) can be made to work with minor modifications to my original solution. Since all of these options are available, I assume that it is permissible for a user to select the most appropriate - or maybe using Matrix is compulsory for some reason I have missed.

How would one select between these options??? Well, it depends very much on what one subsequently wants to do with the data (and also what one doesn't want to do!!). Maple is a reasonably strongly-typed language, which has good points and bad points: it does mean that any user should probably give careful thought to selecting the most appropriate type of data structure for the problem in question. For example, matrices come with interesting operations such as determinants, inverses (possibly), multiplication etc. Would I want to use any/all of these in this particular problem?? Then why use the Matrix data structure?

It is  suggestive that the OP uses the term "keys" for a variable (although in h[is|er] problem these are really key-prefixes). This suggests that (s)he is thinking in terms of an associative array (aka hash) which is most easily represented in Maple as a table

So if I were starting from scratch how would I code this problem ? - probably using tables and therefore something like the following. (There are many other possibilities!)

restart:
with(StringTools):
T:= table( [ foobar =  [77, 27],
                  faabar =  81,
                  foobaa =  22,
                  faabaa =  8,
                  faabian = 88,
                  fiijii =  52
              ] ):
prekeys:= [foo, faa]:
ans:= table( [ seq
                     ( j = add( `if`( Search(j, k) = 1,
                                            add(p, p in T[k]),
                                            0
                                         ),
                                    k in indices(T, 'nolist')
                                 ),
                      j in prekeys
                    )
                 ]
              ):
op(ans);

Having "keys in a set".


My only thought here was that Maple organises sets in lexical order so {"foo", "faa"} will be sorted to {"faa", "foo"}. This may or may not cause problems for the uninitiated. For example my original code produces

           [ "faa" 177 ]
           [ "foo" 126 ]

whereas the OP asked for


           [ "foo" 126 ]
           [ "faa" 177 ]

so I was incorrect! However I was aware that had I used a list rather than a set for the variable "keys" in my original response, then I would have obtained the OP's exactly specified answer - does this matter??? Only the OP knows: but (s)he really ought to be aware that any set will be sorted in lexical order, so relying on "position" can lead to great confusion

@GPY 

ListTools[Search](k, ans) looks for the first occurrence of the integer k in in the list ans, and retruns the index. So if you had some arbitryary list [1, 2 ,7, 10, 23, 8, 4],
ListTools[Search](10, ans) would return 4,
ListTools[Search](23, ans) would return 5

and so on.

There is no integer n which has 6 solutions, if all positive and negative combinations of x and y are allowed. Consider if x0>=0 and y0>=0 is a solution, then there will be three other solutions (x0, -y0), (-x0, y0), and (-x0, -y0), so solutions always come in sets of four there will be values of n with four solutions, values with 8, values with 12 etc, but none with 6.

Only way you could get 6 solutions is if you add an additional condition such as requiring x>0, y>0 - then each set of four solutions (x0, y0), (x0, -y0), (-x0, y0), and (-x0, -y0) will actually provide only one valid solution (x0, y0). Without doing any clever to the code already provided this means that you are looking for the lowest integer for which the current code provides 24 solutions - 6 sets of 4 and in each set of four, only one will have both x and y >0

You will need to execute quadsumstats(400), the ListTools[Search](24, ans) will return 325, and the six positive answers are (1, 18),  (18, 1), (6, 17), (17, 6), (10, 15), (15, 10)

Of course you might not want to allow both (1,18) and (18,1) as two separate answers, in which case you will be looking for the first number for which ListTools(48, ans) returns a value of 48. This turns out to be 5525 - although this now runs so slowly that I would probably try to come up with a more efficient way to do the problem

@GPY 

Which means that firstCount(4)=1 - which is correct because x^2+y^2=1 has 4 solutions, (x=1, y=1), (x=-1, y=1), (x=1, y=-1), (x=-1,y=-1)

Because of the symmetry of the problem - the fact that you can always interchange x and y, or plus/minus signs, firstCount(n) will only produce a non-zero answer when n is a multiple of 4. If you examine quadsumstats(100) then you will see that the only non-zero answers are 4, 8, 12, 16. You have to go up up to quadsumstats(400) to get 24 (although 20 is missing - apparently 625 is the first number with 20 solutions)


Your problem seems to be solved or am I missing something??

@Markiyan Hirnyk 

Nothing wrong with my original in Maple18. OP did not specify whether (s)he wanted a plot or points


The following minor revision of my original will do both (in Maple18)


restart;
with(Student[Calculus1]):
f:= x -> piecewise( x<0, -(x^2) ,0<=x, x^2):
MeanValueTheorem(f(x), x=-2..2);# produce a graph
MeanValueTheorem(f(x), x=-2..2, output=points);# produce the points

Don't have access to Maple 13;

Tried running your original code in Maple18 on a reasonably quick whineDoze7 machine. Gave up after about 3mins.

Looking at your code, I agree with MacDude that the procedure J uses a lot of global variables. This always makes me a bit twitchy

For comparison I ran the code on the help page

Fractals:-EscapeTime:-Julia

in Maple18.
attached code testJulia.mw

 

This produced several very nice Julia plots in ~1.3secs on my machine. Suggests that you are either doing a lot more points, or your iteration stopping criteria is lot more "aggressive"? (Or I'm missing something??)

Check my original post - why doesn't

ListTools[Search](12, ans)

work?

@GPY 

I'm running Maple19 - don't have access to Maple13

If you define the procedure as

quadsumstats:= proc(n::integer)
                               return [seq(numelems([isolve(x^2+y^2=k)]), k=1..n)]
                        end proc;

then executing

ans:=quadsumstats(100)

will assign to ans,  a 100-element list of the number of solutions to x^2+y^2=k for k =1..100.

Notice that this simple procedure will return all possible solutions and you may (or may not) regard these as exhibiting some double-counting. For example quadsumstats(4) will return the list [4, 4, 0, 4]. the first entry in this list enumerates the four (x, y) values (1, 0), (0, 1), (-1, 0), (0, -1); the second entry enumerates the four (x, y) values (1, 1), (1, -1), (-1, 1), (-1, -1), and so on. Whether you regard either of these as "double-counting" is up to you!!

I don't really uderstand the second part of your question - so I'm guessing that maybe you want to know the first occurrence of a given number of solutions: for example what is the lowest value which has say 12 solutions. You can find this using

ListTools[Search](12, ans)

which will return 25, where the 12 solutions are (0, 5), (0, -5), (5, 0), (-5, 0), (3, 4), (3, -4), (-3, 4), (-3, -4), (4, 3), (4, -3), (-4, 3), (-4, -3).

Again you may (or may not) regard this as having some element of double counting

I suggest you check the first word in my original response - ie "Assuming" - and then my answer on the basis of that assumption. You do not want to

"weight a serie of values which x1 range go from 280 to 4000 by the factors provided by another serie of values, which x2 values go from 206.6 to 12400."

What you wnat to do is

weight a serie of values which x1 range go from 280 to 4000 by the factors provided by the interpolation of another serie of values, which x2 values go from 206.6 to 12400.

In which case the first thing you have to do is perform interpolation on the weight list. As MacDude has suggested, there are several ways to do this. The starting point is probably the ArrayInterpolation command.

Since you do not not provide either the data list or the weight list, then it is difficult to supply explicit code to achieve what you want. Check out

?ArrayInterpolation.

I suggest using the option

yvalues:= ArrayInterpolation(xydata, xvalues, options)

in which xydata will be the weight list of xydata, ("t" in your example): xvalues will be the xvalues in the "S" list. The output yvalues will then be the required interpolated y-values for the weights. Having obtained the interpolated y-values, you can then use the command in my original response

 

First 143 144 145 146 147 Page 145 of 147