acer

32348 Reputation

29 Badges

19 years, 330 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

If I knew this at some point in the past then I'd forgotten it.

The plot command does not always apply evalf to the end-points, when not operating in evalhf mode.

Instead, it can try and use the exact end-points for evaluation of the expression/procedure, and only generate floating-point values from such results.

This is why, when Digits is high, the call plot( (1-x)^(10^9), x=0 .. 10^(-15) )  can goes away for a long time, or hit the stack-limit.

So perhaps the simplest successful variation here would be to use greater working precision as well as floats for the end-points, eg,

restart;
Digits:=20:
plot( (1-x)^(10^9), x=0 .. 10.0^(-15) );

That also explains why the first variant I gave in my Answer also works, since its operator turns its argument x into a float before computing the formula.

restart;
plot(x->eval(evalf[20]((1-x)^(10^9))), 0..10^(-15))

While surely it's easier just to use floating-point values in the supplied range, it's also possible to build a coercing operator from a pre-existing expression.

restart;
expr:=(1-x)^(10^9);

f := unapply( expr, [x::coerce(float, (s::realcons)->evalf(s))] ):

Digits:=20:
plot( f, 0 .. 10^(-15) );

I find it interesting that the expression b is smaller than the expression a according to some metrics, but not perhaps by that used by simplify(...,size).

restart;

a := rho^(epsilon-1)*a__01^(-k)*(N__E2/Omega+N__E1*mu)*(K+1)/(mu):
b:=rho^(epsilon-1)*a__01^(-k)*(N__E2/(Omega*mu)+N__E1)*(K+1):

length(a), `simplify/size/size`(a), MmaTranslator:-Mma:-LeafCount(a);
                            99, 60, 26

length(b), `simplify/size/size`(b), MmaTranslator:-Mma:-LeafCount(b);
                            90, 63, 24

c:=simplify(a,size):
length(c), `simplify/size/size`(c), MmaTranslator:-Mma:-LeafCount(c);
                           103, 55, 26

lprint(c);
  rho^(epsilon-1)*a__01^(-k)*(N__E1*Omega*mu+N__E2)*(K+1)/Omega/mu

I don't think that length would be a good metric, but I've wondered about how useful it might be to have simplify(...,size) optionally use LeafCount.

@John Fredsted Your suggestion to use applyop is of course simple and effective, and I apologize if I sounded at all officious. And since we only have the single example to handle then obtaining the target seems just fine.

I was mostly just wondering how "it" might be approached more generally, but in truth all I really figured out was that the single given example/target pair doesn't really specify thoroughly what "the" more general goal might be.

note: the boilerplate conditional checks in my code are somewhat mirrored, in a direct coding using say applyop or op, by the implicit assumption that the original expression is a product of terms. Again, this aspect may not matter at all to the OP with just this single example. 

Another command that you could experiment with is collect. Reading its help page is worthwhile.

@dgh So it's a Bad Idea to have both c and c[1],etc, in the same expression.

I change unindexed c to cc at the start. I inserted a multiplication symbol in the definition of EI.

I also evaluated sqrt(RRn/RRd) at the results from solving for c[0],..,c[3].

Check that it's what you intended.

Try not suppressing all output with full colons, as it's hidden clues from you (like the very presence of the indexed lam[i].)
 

restart

w := c[0]+c[1]*x+c[2]*exp(cc*x)+c[3]*exp(-cc*x)+c[4]*x^n:

dw := simplify(diff(w, x))

c[1]+c[2]*cc*exp(cc*x)-c[3]*cc*exp(-cc*x)+c[4]*x^(n-1)*n

ddw := simplify(diff(w, x, x))

c[2]*cc^2*exp(cc*x)+c[3]*cc^2*exp(-cc*x)+c[4]*x^(n-2)*n^2-c[4]*x^(n-2)*n

dddw := simplify(diff(w, x, x, x))

c[2]*cc^3*exp(cc*x)-c[3]*cc^3*exp(-cc*x)+c[4]*x^(n-3)*n^3-3*c[4]*x^(n-3)*n^2+2*c[4]*x^(n-3)*n

m := -alpha*x+1:

EI := -x^4*beta[4]-x^3*beta[3]-x^2*beta[2]-x*beta[1]+1:

T := lam^2*(int(m*(R+x), x = x .. L))/L^4+F

lam^2*(-(1/3)*alpha*(L^3-x^3)+(1/2)*(-R*alpha+1)*(L^2-x^2)+R*(L-x))/L^4+F

n := 4

4

RRn := `assuming`([simplify(int(EI*ddw^2, x = 0 .. L)+int(T*dw^2, x = 0 .. L))], [L > 0]):

RRd := `assuming`([simplify(int(m*w^2, x = 0 .. L))], [L > 0]):

NULL

alpha := 0:

Eq1 := subs(x = 0, w = 0):

Eq2 := subs(x = 0, dw = 0):

Eq3 := subs(x = L, ddw = 0):

Eq4 := subs(x = L, dddw = 0):

S := solve({Eq1, Eq2, Eq3, Eq4}, {c[0], c[1], c[2], c[3]}):

cc := `assuming`([simplify(subs(x = 0, sqrt(T/EI)))], [lam > 0])

(1/2)*lam*2^(1/2)

new := eval(sqrt(RRn/RRd), S):

RQ := evalf(subs(lam = 1, new))

3.700371506

NULL


Download Uniform_Beam_1.mw

 

@dgh Your attempt to substitute lam=1 will not make all of lam[0], lam[1],...,lam[4] take on values of 1. That's just not how it works.

Try this:

evalf(subs(lam=1,eval(RRn/RRd,{lam[0],lam[1],lam[2],lam[3],lam[4]}=~1)));

Also, it's a Bad Idea to use both a name like lam and indexed names like lam[0], lam[4] in the same expression.

@dgh When you are composing your Reply you should see a green up-arrow in the Mapleprimes editor. Use it to upload your worksheet (and insert a link to that).

@mapleatha You write, "For the last time, I have never used the cat command anywhere."

But the red input Maple code in this very Question, submitted by you, is:

The call to the cat command appears twice in that code, posted here by you. It's use is the central issue in your Question.

You are wrong also about what you claimed the || means in the output in your Question.

@mapleatha You wrote, "|| || is a symbol for a norm on a normed space. It has no business
in what I am doing for my DE classes. It appeared when I asked up here: `Why is this happenning in Maple?'"

In the Maple language || is a command that can be used as an infix concatenation operator. That's how it appears in the results in your Question's output above. (The example in your Question shows version specific behavior, related to how mixes of names and rationals were treated by the cat command.)

The || appearances in the output in your Question have nothing to do with norms.

 

@mapleatha You wrote in a Comment above, "I have never used the cat command anywhere." But in fact you used the cat command in the code in this very Question!

In your other, earlier Question you also had a rational value. I asked in my Answer there whether you needed that to be typeset (pretty-printed) in 2-D Math, rather than like "1/2" in 1-D text. You didn't confirm there. And now here you suddenly say that aspect is key.

It's not helpful if you don't give a complete description of what your trying to accomplish, at the start.

I'm not trying to berate you. It's a very common  situation on Mapleprimes. People ask about a technical difficulty in an approach they've decided is good for some goal, without telling us all the requirements. Then there's a big circus as we try and dig down to get the true requirements out of them, so that we could suggest a quite different but better overall approach.

This current Question has turned out to be simply a duplicate of another two Questions asked by you, asked close together. Please don't submit three duplicates like that because it splits the value, confuses readers, and separates detail unnecessarily. Please just ask followups details/comments/subcases to Replies/Comments on the original.

You have deleted a comment to which I had responded above. Now my response looks out of context. Please don't remove comments. (I'm trying to ask nicely. Some others here take that kind of thing very personally..)

[The Original Poster made an earlier Comment/Reply, to which I am responding below. The OP has since deleted that Comment, which makes the following look out of place and senseless.]

@mapleatha You claimed that I suggested you use printf, amongst other things. I have not once suggested that you use printf.

I know that you want normally printed output, centred with default blue.

The nprintf command works just like the printf command, the difference being that printf immediately line-prints (gray, left-aligned) while nprintf returns an actual name.

The name constructed by nprintf can be printed just like anything else, centred and in blue. 

So the result from nprintf will work just like your results from cat (when successful).

The result from nprintf can be assigned to a variable, just like the result from cat. The result from nprintf can be used with the actual `print` command, just like you can with the result from the cat command.

But nprintf is easier to use than cat, especially in your situation that not all the blobs are already names, and when there's lots of punctuation to stick in.

So go back and look at Rouben's Answer to your earlier Question, which used printf. But just change the command to nprintf.

That will give an easier way than using the cat command. And results will print in blue, centered.

 

@Christopher2222 In general (outside this context of using the `convert` command) symbol and name cannot be used interchangeably.

For example not everything of type name is of type symbol.

I don't understand why you would make such a potentially confusing and generally untrue statement in a clause that reads ambiguously (and could be easily interpreted as a general claim).

I messed around with code (originally from someone I know) to do that in Maple, about 5-8 years ago. It did wireframe 3-D plots, and relied on having those 3-D cinema glasses that filtered the two colors. The hard part to using that would be to find the worksheet...

But if I recall it was not very involved code. I'm sure several people here could implement the basic idea quite quickly.

@wilk007 That functionality to embed and automatically start playing relies on use of a PlotComponent, which only supports a pair of integers (pixel counts), and not the "golden" ratio.

A simple adjustment of the code allows the integer dimensions to be passed in.

I'll approximate using the golden ratio by obtaining the height as a suitable multiple of the width.

restart;

wave := (x,t) -> 12*(3+4*cosh(2*x-8*t)+cosh(4*x-64*t))/(3*cosh(x-28*t)+cosh(3*x-36*t))^2:

autoplay := proc( anim, {continuous::truefalse:=false},
                        {size::[posint,posint]:=[400,400]} )
  local P, T;
  uses DocumentTools, DocumentTools:-Layout,
       DocumentTools:-Components;
  P := Plot(':-identity' = "Plot0", anim,
            ':-continuous'=continuous,
            'pixelwidth'=size[1], 'pixelheight'=size[2]);
  T:=InsertContent(Worksheet(Group(Input(Textfield(P)))),
                   ':-output'=':-table');
  DocumentTools:-SetProperty(T["Plot0"],':-play',true);
  NULL:
end proc:

aniplot := plots:-animate( plot,[wave(x,t),x=-20..20],t=-1..1,frames=45,thickness=3 ):

autoplay( aniplot, size=[1500, floor(1500*0.61)] );

I wrote a fancier version of the "autoplay" procedure above. It came up recently in another thread. I'll try and find the link for you.

NB. Several of your Mapleprimes posts contain images (pictures) of code. Nobody enjoys having to retype stuff out. Please use the green up-arrow in the editor to upload worksheet attachments, or inline your complete code as plaintext, moving forwards. Thanks.

@mapleatha You can simply change the printf to nprintf in Rouben's suggestion.

The result would then be a name, similar to the concatenation you asked about your related Question. And it would then print in the usual way (centered, and in blue or according to the style).

The mimicing of a sentence by multiplication is somewhat dubious and awkward, in comparison. If you don't need 2D pretty-printing of any portions then using nprintf is so much more straightforward.

First 267 268 269 270 271 272 273 Last Page 269 of 592