acer

32385 Reputation

29 Badges

19 years, 335 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Your code falls into the well-known mistake sometimes called premature evaluation. The problem is that you need to guard against the evaluation of T before c gets any numeric value.

The seq command has special evaluation rules, and that's why it works when you use that as your "trick". The normal evaluation rules for Maple is that procedure calls evaluate their arguments up front.

A simple approach is to delay evaluation using single right-quotes (a.k.a. unevaluation quotes) around the calls to X,Y in the second argument passed to the animate command.   cardioidfamily_ac.mw

There are other ways to deal with this issue.

Another way is to construct the procedures so that they return unevaluated if the relevant arguments are not numeric.   cardioidfamily_ac2.mw

Yet another way to construct the animations is to use two procedures which each make a whole frame.   cardioidfamily_ac3.mw

I'll add that the collection of point-plots (for all c values) could also be constructed in a single call to pointplot. (I haven't done that.) I also didn't change the over all approaches, or put in any efficiency improvements to re-use previously computed values.

You might also see this page.

I added the missing with(plots) to all the worksheets.

[edit] Since it is only procedure T which requires any guard against unwanted evaluation at non-numeric argument, here are revised versions which do only that. I've also added option remember to T, so as to gain efficiency by avoiding duplicate fsolve work.
cardioidfamily_ac_rev.mw
cardioidfamily_ac2_rev.mw
cardioidfamily_ac3_rev.mw

So this is a followup (duplicate topic) of your earlier Question here? (If so then please, next time add your followup query to the original Question thread. That keeps the whole topic together, which helps all the readership.)

Is this what you want? This is one of the least graceful ways of doing it:  both_of_them_ac_huh.mw

If that's not what you want then please add more complete and explicit details of your query.

I tagged this Question as Maple 17, since you didn't make the effort to do that.

It is a bug that plottools:-extrude produces a VIEW substructure in its result.

A simple way to deal with it is to immediately clobber any VIEW substructure that extrude produces. Ie, something like,

    plots:-shadebetween(x^2, 2-x^2, x=-1..1, color=red, transparency=0):
    p1 := eval(plottools:-extrude(%, 0..0.3),VIEW=NULL):

Or you could use subsindets to get the same effect. It's also wrong that extrude generates any axis lablels.

restart;

plots:-shadebetween(x^2, 2-x^2, x=-1..1, color=red, transparency=0):
p1 := subsindets(plottools:-extrude(%, 0..0.3),
                 specfunc({VIEW,AXESLABELS}),()->NULL):

plottools:-sphere([1.5,0,0], 1, color="Green"):
p2 := plots:-display(%):

plots:-display([p1,p2], scaling=constrained, style=surface);

 

Download bug-in-3D-view_ac.mw

I'll submit a bug report.

sum(sin(Pi*n/2)*sin(n*Pi*(x + 1)/2)*cos(n*Pi*t/2),n=1..infinity,formal);

                0

Have you tried giving parameter t a default value which is an integer?

Eg,        t::{integer,name}:=0

This kind of optional parameter is called a positional parameter (as opposed to a keyword parameter).

restart;

graph := proc(fn::anything, t::{integer, name}:=0)
   if type(t, integer) then return fn;
   else return plot(fn, gridlines);
   end if;
end proc:

graph(x^2);

x^2

graph(x^2,g);

 

Download param_default.mw

Of course there are other ways to accomplish the same effect. You could have used it as, say,       t::{truefalse,name}:=false

restart;
graph2 := proc(fn::anything, t::{truefalse, name}:=false)
   if t=false then return fn;
   else return plot(fn, gridlines);
   end if;
end proc:
graph2(x^2);
graph2(x^2,g);
graph2(x^2,false);
graph2(x^2,true);

You could also utilize a keyword parameter.

What purpose do you want the name to serve, when you pass that instead? For example, is passing the extra name g supposed to do something different than passing the extra name w? (If not then this definition might not seem graceful to everyone...)

I supplied the missing definition of the list xx of x-values.

This also runs about 3-3.5 times faster than the original, on my machine, but requests the same accuracy for computing the two final lists.

I also fixed the operator assignment syntax so that it wouldn't pester each time about operator-definition versus remember-table.

I used Maple 18.02, since the OP's original attachment was last saved in that version. (I suspect that the OP confuses Maple 18 with Maple 2018, which are two totally different versions, with their release dates separated by four years.)

restart

Digits := 10:

with(plots):

with(CurveFitting):

with(plottools):

v := 7/10:

Disp := 15:

esp := 800000:

k := 0:

E := proc (x, t) if not [x, t]::(list(numeric)) then return ('procname')(args) end if; evalf(Int(unapply(exp((-esp*w^4+Disp*w^2+k)*t)*cos(w*(x+v*t))/Pi, w), 0 .. infinity, epsilon = 0.1e-5)) end proc:

E(x, t)

E(4000, 3600)

0.6340431462e-11

f := proc (x) options operator, arrow; 20*exp(-(1/900000)*(x-10000)^2)+17*exp(-(1/900000)*(x-12000)^2) end proc

proc (x) options operator, arrow; 20*exp(-(1/900000)*(x-10000)^2)+17*exp(-(1/900000)*(x-12000)^2) end proc

u := proc (x, t) options operator, arrow; int(E(x-xi, t)*f(xi), xi = 0. .. 15000) end proc

proc (x, t) options operator, arrow; int(E(x-xi, t)*f(xi), xi = 0. .. 15000) end proc

u(12000, 7200);

-0.3891737146e-4

xx := [seq(i, i = 0 .. 15000, 100)]:

uu3600 := CodeTools:-Usage(map(proc (i) options operator, arrow; evalf(Int(unapply(E(i-xi, 3600)*f(xi), xi), 0 .. 15000, method = _NCrule, epsilon = 1/1000000)) end proc, xx)):

memory used=0.57GiB, alloc change=0 bytes, cpu time=9.50s, real time=9.31s, gc time=622.43ms

 

uu7200 := CodeTools:-Usage(map(proc (i) options operator, arrow; evalf(Int(E(i-xi, 7200)*f(xi), xi = 0 .. 15000, method = _NCrule, epsilon = 1/1000000)) end proc, xx)):

memory used=0.59GiB, alloc change=0 bytes, cpu time=8.61s, real time=8.46s, gc time=459.57ms

p1 := plot(f(x), x = 0 .. 15000, color = blue, legend = [''t = 0'']):

p2 := plot(xx, uu3600, color = red, legend = [''t = 3600'']):

p3 := plot(xx, uu7200, color = blue, legend = [''t = 0'']):

plots[display]({p1, p2, p3})

``

 

``

Download permanouuuuuuuuuuuuuuuuuun_ac.mw

The following runs around 4 times faster than the original, as another variant. permanouuuuuuuuuuuuuuuuuun_ac2.mw

Here is interpolation by piecewise splines. Using Maple 2019.1.

The interpolated curve is red. The first derivative of that interpolated curve is black. The orange diamonds indicate interior inflection points of that interpolated curve.

If you use a different method of curve-fitting then your interpolant (and its inflection points) may not be the same. That's a mathematical consequence, not a Maple quirk.

restart;

x := [ 7.0, 7.2, 7.4 ,7.6, 8.4, 8.8, 9.2, 9.6, 10.0,10.4,10.8,11.2]:
y := [ 0.692, 0.719, 0.723, 0.732, 0.719, 0.712,
       1.407, 1.714, 1.99,2.118, 2.305, 2.711]:

F:=Interpolation:-Interpolate(x,y,method=spline,degree=3):

plots:-display(
  plot(<<x>|<y>>,style=point,color=blue),
  plot(F,x[1]..x[-1]),
  size=[600,300]
);

pts:=Student:-Calculus1:-InflectionPoints('F'(t),t=x[1]..x[-1],numeric);

[7.349175938, 7.765875858, 8.461873414, 9.031452528, 9.511908737, 9.788460565, 10.31049449]

plots:-display(
  plot(<<x>|<y>>,style=point,color=blue),
  plot(<<pts>|<map(F,pts)>>,style=point,color="Orange",
       symbol=soliddiamond,symbolsize=20),
  plot(<<pts>|<map(D[1](F),pts)>>,style=point,color="Orange",
       symbol=diamond,symbolsize=20),
  plot(D[1](F),x[1]..x[-1],color=black),
  plot(F,x[1]..x[-1]),
  size=[600,300]
);

 

Download spline_interp.mw

Assigning values to some of the variables is not necessary for your problem. It is not really "substitution", nor does it create equations. It often just gets in the way or, in your case, leads to a circular muddle.

Equations are perfectly good expressions in Maple, and very useful. For example, step by step,

restart;

eqn := totalsalesx = 60.1 + tax + profit;

totalsalesx = 60.1+tax+profit

eval(eqn, [tax=0.3*profit]);

totalsalesx = 60.1+1.3*profit

eval(%, [profit=0.1*totalsalesx]);

totalsalesx = 60.1+.13*totalsalesx

solve({%});

{totalsalesx = 69.08045977}

eval(totalsalesx, %);

69.08045977

 

Download substitutions_eval.mw

Above, I used an equation for the solving step. And the substitutions were done using the other equations (with the eval command). None of your key variables profit, tax, or totalsalesx had to be assigned. Even the result from solve is an equation, which in turn can be used in eval.

There are lots of ways to do this. Here's another variant.

restart;

eqn1 := totalsalesx = 60.1 + tax + profit;

totalsalesx = 60.1+tax+profit

eqn2 := tax=0.3*profit;

tax = .3*profit

eqn3 := profit=0.1*totalsalesx;

profit = .1*totalsalesx

neweqn := eval(eqn1, eqn2);

totalsalesx = 60.1+1.3*profit

eval(neweqn, eqn3);

totalsalesx = 60.1+.13*totalsalesx

solve({%});

{totalsalesx = 69.08045977}

eval(totalsalesx, %);

69.08045977

 

Download substitutions_eval2.mw

This is not expert stuff. It is basic Maple praxis, worth learning.

 

If you want the same color scheme for both, and if you're willing to accept more of a density-plot style, then here is an easy way.

You could, of course, also merge the bottom 2D layer with contour lines, and also raise that to the height of the surface. (Neither of those is especially complicated -- Kitonum's shown you that way.)

restart;

lambda := 2*(1/10):

mu := -1:

beta := 10:

alpha := -25:

C := 1:

k := (1/12)*sqrt(6)/sqrt(beta*lambda*mu):

w := alpha/((10*sqrt(-lambda*mu))*beta):

A[0] := (1/2)*alpha/((10*sqrt(-lambda*mu))
                     *((1/12)*beta*sqrt(6)/sqrt(beta*lambda*mu))):

A[1] := -(1/10)*alpha/((1/12)*beta*mu*sqrt(6)
                       /sqrt(beta*lambda*mu)):

A[2] := -(12*((1/12)*sqrt(6)/sqrt(beta*lambda*mu)))
        *lambda^2*alpha/(10*sqrt(-lambda*mu)):

H := ln(sqrt(lambda/(-mu))*tanh(sqrt(-lambda*mu)*(xi+C))):

xi := k*x-t*w:

u[0] := A[0]+A[1]*exp(-H)+A[2]*exp(-H)*exp(-H):

scheme1 := ["zgradient",["Blue","Cyan","Green","Yellow","Orange","Red"]]:

P3:=plot3d(min(40,max(-40,Im(u[0]))), x=-10..10, t=-4..1,
            grid=[201,201], colorscheme=scheme1, style=surface):

plots:-display(P3,plottools:-transform((x,y,z)->[x,y,-50])(P3),
               view=-50..39, orientation=[30,75,0]);

 

Download denseasy.mw

Some other, fancier alternatives are here.

The taylor command produces the same sort of beast as the series command, and returns a special structure (which merely pretty-prints as you see it).

You can utilize the convert command to turn the result from taylor (or series) into simple sum of terms.

You can also use the series command to merge the difference into a new series structure.

restart;

E1 := taylor(ln(1+x),x=0,4);

series(x-(1/2)*x^2+(1/3)*x^3+O(x^4),x,4)

E2 := taylor(ln(1+sin(x)),x=0,4);

series(x-(1/2)*x^2+(1/6)*x^3+O(x^4),x,4)

convert(E1,polynom);

x-(1/2)*x^2+(1/3)*x^3

convert(E1,polynom)-convert(E2,polynom);

(1/6)*x^3

series(E1-E2,x);

series((1/6)*x^3+O(x^4),x,4)

 

Download seriesconvert.mw

Another way to get a simlar effect is to call   taylor(E1-E2,x) . Christian's Answer did that last call with the option 4 passed for the order. But that 3rd argument may be omitted on the comparison; you can compare the difference between E1 generated with 6 as third argument, and E2 generated with as 3rd argument).

E1 := taylor(ln(1+x),x=0,6);

series(x-(1/2)*x^2+(1/3)*x^3-(1/4)*x^4+(1/5)*x^5+O(x^6),x,6)

E2 := taylor(ln(1+sin(x)),x=0,5);

series(x-(1/2)*x^2+(1/6)*x^3-(1/12)*x^4+O(x^5),x,5)

series(E1-E2,x);

series((1/6)*x^3-(1/6)*x^4+O(x^5),x,5)

taylor(E1-E2,x);

series((1/6)*x^3-(1/6)*x^4+O(x^5),x,5)

Download seriesconvert2.mw

plots:-animate(plot, [[cos(x+2*a), cos(x-2*a)], x = 0 .. 4*Pi],
               a = 1 .. 10, frames=117);

You have used the syntax for function application, rather than multiplication.

You are missing multiplication symbols between your brackets, if your code was entered as (plaintext) 1D Maple Notation.

Even in 2D Input mode you'd still need either explicit multiplication symbols or spaces between the brackets to denote multiplication implicitly.

S := Sum(1/i(i + 1)(i + 2)(i + 3), i = 1 .. infinity);
evalf(S);

Sum(1/((i(i+1))(i+2))(i+3), i = 1 .. infinity)

Float(-infinity)

S2 := Sum(1/(i*(i + 1)*(i + 2)*(i + 3)), i = 1 .. infinity);
evalf(S2);

Sum(1/(i*(i+1)*(i+2)*(i+3)), i = 1 .. infinity)

0.5555555556e-1

sum(1/(i*(i + 1)*(i + 2)*(i + 3)), i = 1 .. infinity);

1/18

evalf(%);

0.5555555556e-1

restart

S := Sum(1/((i(i+1))(i+2))(i+3), i = 1 .. infinity); evalf(S)

Sum(1/((i(i+1))(i+2))(i+3), i = 1 .. infinity)

Float(-infinity)

restart

S := Sum(1/(i*(i+1)*(i+2)*(i+3)), i = 1 .. infinity); evalf(S)

Sum(1/(i*(i+1)*(i+2)*(i+3)), i = 1 .. infinity)

0.5555555556e-1

``

Download syntaxmult.mw

Perhaps it will help you a little to go through it a step at a time.

Notice that I'm only using the formula on the right hand side of each equation returned by solve. (There are other ways to accomplish the goal, but this might make it a little more clear.)

restart;

g := z -> (a + b*z + c*z^2)/(d + e*z + f*z^2):

eqn := y = g(z);

y = (c*z^2+b*z+a)/(f*z^2+e*z+d)

sols := solve({eqn}, {z});

{z = (1/2)*(e*y-b+(-4*d*f*y^2+e^2*y^2+4*a*f*y-2*b*e*y+4*c*d*y-4*a*c+b^2)^(1/2))/(-f*y+c)}, {z = -(1/2)*(-e*y+(-4*d*f*y^2+e^2*y^2+4*a*f*y-2*b*e*y+4*c*d*y-4*a*c+b^2)^(1/2)+b)/(-f*y+c)}

expr1 := eval(z, sols[1]);

(1/2)*(e*y-b+(-4*d*f*y^2+e^2*y^2+4*a*f*y-2*b*e*y+4*c*d*y-4*a*c+b^2)^(1/2))/(-f*y+c)

f1 := unapply(expr1, y);

proc (y) options operator, arrow; (1/2)*(e*y-b+(-4*d*f*y^2+e^2*y^2+4*a*f*y-2*b*e*y+4*c*d*y-4*a*c+b^2)^(1/2))/(-f*y+c) end proc

simplify( (g@f1)(y) );

y

expr2 := eval(z, sols[2]);

-(1/2)*(-e*y+(-4*d*f*y^2+e^2*y^2+4*a*f*y-2*b*e*y+4*c*d*y-4*a*c+b^2)^(1/2)+b)/(-f*y+c)

f2 := unapply(expr2, y);

proc (y) options operator, arrow; -(1/2)*(-e*y+(-4*d*f*y^2+e^2*y^2+4*a*f*y-2*b*e*y+4*c*d*y-4*a*c+b^2)^(1/2)+b)/(-f*y+c) end proc

simplify( (g@f2)(y) );

y

 

Download tima_inv.mw

This question is vague and underspecified, because it only gives two examples, which both happen to have 1 nonzero digit on the left of the decimal point in the input as well as the output under default display.

So about the only way that I can make sense of the request is that the OP wants 1 leading nonzero digits to the left of the decimal place, and no trailing zeros after the right-most nonzero digit.

restart;

H:=proc(x::float) local s;
  uses StringTools;
  s:=CharacterMap("0"," ",sprintf("%ld",abs(op(1,x))));
  s:=CharacterMap(" ","0",TrimRight(s));
  `if`(s="",0.,signum(op(1,x))*parse(cat(s[1],".",s[2..])));
end proc:

H( 2.55 *10^(-90) );

2.55

H( 2.22 *10^(-87) );

2.22

H( -0.0000045600060000 *10^(-87) );

-4.560006

H( 617.123789 );

6.17123789

 

Download leaddig.mw

The RiemannSum command accepts an option partition which can be used to specify the partition values as a list.

For example,

restart;

f := x^2:

P := [-1, -1/4, 1/4, 3/4, 1]:

Student:-Calculus1:-RiemannSum(f, x=-1..1,
                               method=lower, partition=P);

               0.2187500000

For this example it's easy enough to check that result,

add(minimize(f,x=P[i]..P[i+1])*(P[i+1]-P[i]), i=1..nops(P)-1);

                  7 
                  --
                  32
evalf(%);

               0.2187500000
First 139 140 141 142 143 144 145 Last Page 141 of 336