mmcdara

1042 Reputation

13 Badges

4 years, 1 days

MaplePrimes Activity


These are replies submitted by mmcdara

@naili @Carl Love

Sorry Carl if I take the liberty to respond

If you use  PolynomialInterpolation don't even have to use a list of lists.
If you got an error it comes probably from a misconstruction of this latter:

with(CurveFitting):
PolynomialInterpolation([[0,0],[1,3],[2,1],[3,3]], z);
PolynomialInterpolation([0, 1, 2, 3], [0, 3, 1, 3], z);

 

@Carl Love @nm

Thanks to both of us.
In fact all of this comes from the fact that indets recursively searches for all the occurences of the selected typename.

Carl Love showed you how to built the list you can use in pointplot.
But if you are only interested in ploting, this command seems simpler (the options are the same as for a classic "plot")
Statistics:-ScatterPlot(List1, List2)

@acer 

 

(I suspect that was just an oversight or a typo on your part.) :
Right, I first put the column of row names on the left "as usual", with the same kind of collor filling you used.  But when I saw that the OP had put this same column in the right most osition I just moved without redefining the color filling strategy.
I didn't even realize of awfull the result was.
Thanks for correcting all of this
 

 

@vv 

Thank you

@acer

I didn't doubt you knew that.
I was just giving the "no dataframe" solution (which has, I repeat,the advantage to out the column and row titles on either side of the matrix).

In desperation there is also the possibility of making a plot, as in the old days.

@Carl Love

You're right, I wrote my question without paying attention to what I was writing.
So, Is it possible to define an involution in Maple ?

@acer  @lmbs

Hi, 
I don't think it's necessary to built a DataFrame (a structure which was introduced in Maple 2018 I think).
For older Maple's versions you can call Tabulate with a Matrix instead (I guess it works the same with Maple 2020)

More than this th column of rox names is meant to be on the left of the matrix S, which is not possible with DataFrames


 

restart:

interface(version)

`Standard Worksheet Interface, Maple 2015.2, Mac OS X, December 21 2015 Build ID 1097895`

(1)

S        := Matrix([[0,9,8,0,7],[3,5,6,5,1],[1,0,0,3,2]]):

RowNames := Vector(3, ["small","medium","large"]):
ColNames := Vector[row](6, ["Rose","Teal","Plum","Sand","Peach", ""]):

M        := < ColNames, < S | RowNames >>:

DocumentTools:-Tabulate(
      M,
      color=((T,i,j)->`if`(i=1 and j=1, "0000FF", `if`(i>1 and j>=i, "#000000", "#0000FF"))),
      fillcolor=((T,i,j)->`if`(i=1 or j=1, "HTML NavajoWhite", white)),
      width=40, weights=[1, 1$5]
)

 


 

restart:

interface(version)

`Standard Worksheet Interface, Maple 2015.2, Mac OS X, December 21 2015 Build ID 1097895`

(1)

S        := Matrix([[0,9,8,0,7],[3,5,6,5,1],[1,0,0,3,2]]):

RowNames := Vector(3, ["small","medium","large"]):
ColNames := Vector[row](6, ["Rose","Teal","Plum","Sand","Peach", ""]):

M        := < ColNames, < S | RowNames >>:

DocumentTools:-Tabulate(
      M,
      color=((T,i,j)->`if`(i=1 and j=1, "0000FF", `if`(i>1 and j>=i, "#000000", "#0000FF"))),
      fillcolor=((T,i,j)->`if`(i=1 or j=1, "HTML NavajoWhite", white)),
      width=40, weights=[1, 1$5]
)

 


 

Download Tabulate.mw

@JAMET 

Ok, I didn't think it was a constraint of yours.
Could you download your worksheet code by using the big green up arrow? It would be easier for anyone to work on it, thanks.

@vv 

Hi, 
I didn't pay attention to the end of the question "as close as possible to optimize the selection".
Good point...and pretty solution

An improved version of my previous reply

 

restart:

randomize():

M    := 10.:
roll := rand(0. .. M):
N    := 10:
L    := [seq(roll(), k=1..N)]

[4.642947111, 3.799964258, 8.312019404, 2.745959356, 7.617268886, 2.643016721, 7.560355187, 8.427926897, 8.209026733, 6.182349681]

(1)

ROLL := rand(0..N*M):
S    := ROLL();  # target sum

19.20858495

(2)

R := 10:
AllSets := NULL:
for r from 1 to R do
  rL := combinat:-randperm(L):
  c := Statistics:-CumulativeSum(rL):
  if c[-1] < S then
    printf("The sum of all the numbers (%a) is less than rge desired sum (%a)\n", c[-1], S)
  else
    select[flatten](`<`, c, S);
    AllSets := AllSets, convert(rL[1..numelems(%)+1], set);
  end if;
end do:

AllSets := { AllSets }: # remove replicated sets

for r in sort(AllSets) do  # display sets in increasing number of members
  printf("%a\n", r);
end do:

{3.799964258, 7.560355187, 8.209026733}
{6.182349681, 7.560355187, 7.617268886}
{6.182349681, 8.209026733, 8.312019404}
{2.643016721, 3.799964258, 6.182349681, 8.312019404}
{2.643016721, 7.617268886, 8.312019404, 8.427926897}
{2.745959356, 3.799964258, 6.182349681, 8.312019404}
{2.745959356, 3.799964258, 7.617268886, 8.312019404}
{2.745959356, 6.182349681, 7.560355187, 8.209026733}
{3.799964258, 4.642947111, 7.617268886, 8.209026733}
{2.643016721, 2.745959356, 4.642947111, 7.560355187, 8.209026733}

 

 


 

Download search_improved.mw

@Carl Love 

Thanks, 
I hadn't paid attention that e mod m do the job even if e is a list

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)

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