mmcdara

7891 Reputation

22 Badges

9 years, 64 days

MaplePrimes Activity


These are replies submitted by mmcdara

With my "old" 2015 version I use to use ImageTools as a trick to superimpose plots (for instance a plot and a zimm of some region).
Here is an example in the attached file.

It's better to have large initial plots and to use Scale to reduce the image than the opposite.
For instance plots 1 and 2 could have sizes 500X500 and img2 could be rescaled using Scale(img2, 0.2) for instance. But you can also choose to draw plot 2 with a smaller siwe and nor rescale the image.
There a a lot of parameters to plau with.
Maybe this trick could help you.


 

restart:

with(ImageTools):

f1 := cat(currentdir(), "/image1.bmp"):
f2 := cat(currentdir(), "/image2.bmp"):


plotsetup(bmp, plotoutput = f1, plotoptions = `portrait, noborder, width=500, height=500`);
  plots:-display(
    plot(sin(x)/x, x=0..10, axes=boxed, color=blue, gridlines=true),
    plots:-pointplot([[2*Pi, 0]], symbol=circle, symbolsize=50, color=red)
);
plotsetup(bmp, plotoutput = f2, plotoptions = `portrait, noborder, width=500, height=500`);
  plot(sin(x)/x, x=0.9*Pi*2..1.1*Pi*2, color=blue, thickness=4);

plotsetup(default);

img1 := Read(f1):
img2 := Read(f2):
 

py := 20:
px := 250:  ### px + s*500 must <= 500
s  := 0.4:

SetSubImage(img1, Scale(img2, s), py, px, inplace):
Embed(img1)

 

``

 

Download subplot.mw

The result:

@mehran rajabi 

Point 1
What tomleslie said is that your expression "eq" contains a variable named "MI" which doen't appear in the screen capture you give.
The fact alpha=sqrt((G*A)/(E*MI)) doesn't change anything to tomleslie's remark. Worse than that it introduces a new cariable "G" whish is not in the screen capture.

Point 2
I suspect you have written "MI" but the source this screen capture comes from uses "I" instead?
In this case, the first thing to do is to tell Maple that "I" is not the imaginary unit (a protected name in Maple).
You can do this either by declating I as local (local I;) or by redefining the imaginary unit (interface(imaginaryunit=J)).
Once done type eval(eq, MI=I).

Point 3
The expression in the screen capture is obviously an ad hoc arrangement done by someone who thought the expression was prettier written this way (the numerator is H^4*something and the denominator is H^4*something else).
Nut Maple is not an IA system who could know what "beauty" means for an equation. It uses algorithms through procedures like (look to these names in the help pages) simplify, collect, normal, expand, subs, algsubs, eval, freeze, thaw, ... and the result suits you or not. If not you will have to write the equation in the form whivh suits you the best and, as Carl Love said, verify that your expression is identical to  "eq".


 

restart

eq:= -w*z^2/(2*E*MI*alpha^2)+w*H*sinh(alpha*H)*cosh(alpha*z)/(alpha^3*E*MI*cosh(alpha*H))-w*H*sinh(alpha*H)/(alpha^3*E*MI*cosh(alpha*H))+w*cosh(alpha*z)/(alpha^4*E*MI*cosh(alpha*H))-w/(alpha^4*E*MI*cosh(alpha*H))+w*H*z/(E*MI*alpha^2)-w*H*sinh(alpha*z)/(E*MI*alpha^3);

-(1/2)*w*z^2/(E*MI*alpha^2)+w*H*sinh(alpha*H)*cosh(alpha*z)/(alpha^3*E*MI*cosh(alpha*H))-w*H*sinh(alpha*H)/(alpha^3*E*MI*cosh(alpha*H))+w*cosh(alpha*z)/(alpha^4*E*MI*cosh(alpha*H))-w/(alpha^4*E*MI*cosh(alpha*H))+w*H*z/(E*MI*alpha^2)-w*H*sinh(alpha*z)/(E*MI*alpha^3)

(1)

local  I

I

 

Warning, The imaginary unit, I, has been renamed _I

 

eq_1 := eval(eq, MI=I)

-(1/2)*w*z^2/(E*I*alpha^2)+w*H*sinh(alpha*H)*cosh(alpha*z)/(alpha^3*E*I*cosh(alpha*H))-w*H*sinh(alpha*H)/(alpha^3*E*I*cosh(alpha*H))+w*cosh(alpha*z)/(alpha^4*E*I*cosh(alpha*H))-w/(alpha^4*E*I*cosh(alpha*H))+w*H*z/(E*I*alpha^2)-w*H*sinh(alpha*z)/(E*I*alpha^3)

(2)

aH := alpha*H:
az := alpha*z:
sc := 'w*H^4/E/I*(1/aH^4*((aH*sinh(aH)+1)/cosh(aH)*(cosh(az)-1)-aH*sinh(az)+aH^2*(z/H-(1/2)*(z/H)^2)))'

w*H^4*((aH*sinh(aH)+1)*(cosh(az)-1)/cosh(aH)-aH*sinh(az)+aH^2*(z/H-(1/2)*z^2/H^2))/(E*I*aH^4)

(3)

sc_1 := expand(sc)

-(1/2)*w*z^2/(E*I*alpha^2)+w*H*sinh(alpha*H)*cosh(alpha*z)/(alpha^3*E*I*cosh(alpha*H))-w*H*sinh(alpha*H)/(alpha^3*E*I*cosh(alpha*H))+w*cosh(alpha*z)/(alpha^4*E*I*cosh(alpha*H))-w/(alpha^4*E*I*cosh(alpha*H))+w*H*z/(E*I*alpha^2)-w*H*sinh(alpha*z)/(E*I*alpha^3)

(4)

ver := simplify(eq_1-sc_1)

0

(5)

 

 

Download verify.mw

 

To give you an hint how complicated it would be to transform "eq" into the pretty form you want, jist look to this very simple exemple which concern the last [...] term in this latter form:

restart

local  I

I

 

Warning, The imaginary unit, I, has been renamed _I

 

exemple := H^2*(z/H-(1/2)*(z/H)^2)

H^2*(z/H-(1/2)*z^2/H^2)

(1)

normal(exemple);
T := simplify(exemple);

(1/2)*z*(2*H-z)

 

(1/2)*z*(2*H-z)

(2)

# How to go back from these expression back to "exemple"?

expand(T);
subs(z=xi*H, expand(T));
collect(%, H);
subs(xi=z/H, %);
is(%=exemple);

z*H-(1/2)*z^2

 

xi*H^2-(1/2)*xi^2*H^2

 

(xi-(1/2)*xi^2)*H^2

 

H^2*(z/H-(1/2)*z^2/H^2)

 

true

(3)

 



Download reverse_simplification.mw

@acer @Carl Love

Could it be possible to use define to construct this g function?
(I guess define must be useful but I often failed to work correctly with this procedure)

To complete Axel's reply: you can also use add(L) 

@Carl Love 

Thanks.
I found strange that irem requires the "~" symbol and not mod.

Concerning your last remark "There's no need fo..." I guess it concerns Maple's versions more recent than 2015 (for wich mod(e,m) doesn't work)

@rachel2332

Some extras

The procedure F takes as inputs the list and the modulus and return two lists :

  • the first is of the form [1=[...],..., k=[..], ..., m-1=[...] ] where each [...] is the list of prime numbers congruent to k modulo m
  • the second is of the form [1=n1..., k=nk, ..., m-1=nm-1 ] where each nk is the number of prime numbers congruent to k modulo m

The performances are given for a list of length 10^6 and a modulus of 8.

These performances are rather closed to the ones obtained with the function G (essentially the same in my previous reply) which only returns the second list above. 
 


 

restart:

F := proc(L::list, m::posint)
  local Lp, Who, HowMany:
  Lp := select(isprime, L);
  Who := map(n -> n=Lp[[ListTools:-SearchAll(n, `mod`(Lp, m))]], [seq(1..m-1, 2)]):
  HowMany := lhs~(Who) =~ numelems~(rhs~(Who)):
  return Who, HowMany
end proc:

F([$1..10^2], 8)

[1 = [17, 41, 73, 89, 97], 3 = [3, 11, 19, 43, 59, 67, 83], 5 = [5, 13, 29, 37, 53, 61], 7 = [7, 23, 31, 47, 71, 79]], [1 = 5, 3 = 7, 5 = 6, 7 = 6]

(1)

CodeTools:-Usage( F([$1..10^6], 8) ):

memory used=470.98MiB, alloc change=27.27MiB, cpu time=4.10s, real time=3.77s, gc time=709.88ms

 

G := (L, m) -> Statistics:-Tally(`mod`(select(isprime, L[3..-1]), m))

proc (L, m) options operator, arrow; Statistics:-Tally(`mod`(select(isprime, L[3 .. -1]), m)) end proc

(2)

G([$1..10^2], 8)

[1 = 5, 3 = 7, 5 = 6, 7 = 6]

(3)

CodeTools:-Usage( G([$1..10^6], 8) );

memory used=441.94MiB, alloc change=271.27MiB, cpu time=4.20s, real time=3.56s, gc time=955.44ms

 

[1 = 19552, 3 = 19653, 5 = 19623, 7 = 19669]

(4)

 


 

Download ModPrime_lists.mw

@Carl Love 

Hi,
in my reply to rachel2332 I used `mod`(some_list, 8).
Why does this work? Why isn't the tilde sign after `mod` necessary?

@Axel Vogt 
Thank you Axel

@Carl Love 
I was joking; no offence

@Carl Love 

Very good answer !!! 
It is also a good argument for preferring {1..n} minus {i} to [1..i-1,$i+1..n]. 

 

@Carl Love 

It always seemed me more natural to write such things in the form mul(lambda[i] - lambda[k], k in {$1..n} minus {i}) .
Is there some specific reason why you used = instead?

@Axel Vogt 

Elegant, I vote up.

By the way, why is it that convert(%,polynom)does not automatically simplify the expression as it would have been the case when using P polynomials from the orthopoly package?
(type for instance
with(orthopoly):in canonical basiswith canonical monomials
)

Perhaps you should re-read your own remark  before asking such a question The mathematical definition of a PRNG is clear.... 

@Kitonum 

Don't pay too much attention to the original figure: the vertical scale is whimsical.

I'm sorry, i've just realized you wrote "What do I need to do to have the lines drawn to the correct length?" while I read "... correct thickness"
(so Carl's remark)

If it is really the  length you are interested on, please do not waste time with  my previous reply

First 109 110 111 112 113 114 115 Last Page 111 of 154