Kitonum

21530 Reputation

26 Badges

17 years, 85 days

MaplePrimes Activity


These are answers submitted by Kitonum

We can noticeably improve the perception if we emphasize the ellipse by its border and/or a color.  fieldstrength=log   option is also useful, which makes it possible to reduce the difference in the size of the arrows:

restart; 
with(plots):    
f := (x,y) -> `if`(x^2+y^2/2 <= 1, x^2+y^2, 0):     
g := (x,y) -> `if`(x^2+y^2/2 <= 1, x+y, 0):      
plots:-display(plots:-implicitplot(x^2+y^2/2-1<=0, x=-1.5..1.5,y=-1.5..1.5, thickness=0, filledregions=true, coloring=["LightYellow",white]), fieldplot( [f,g], -1.5..1.5,-1.5..1.5, arrows=SLIM, color="Red", fieldstrength=log));

 

 

Your algorithm may not provide a minimum spanning tree. You should at each step look for the nearest vertex not for the last vertex of the already constructed tree, but to search for the nearest vertex by scanning all the vertices of the already constructed tree. This will be Prim's algorithm  https://en.wikipedia.org/wiki/Prim%27s_algorithm

Here is an example where your algorithm fails (start from vertex a):

A:=plot([[0,0],[-1,-1],[0,2],[1,3]], style=point, symbol=solidcircle, color=red, symbolsize=20):
B:=plots:-textplot([[0,0,a],[-1,-1,b],[0,2,c],[1,3,d]], color=blue, align={below,right}, font=[times,bold,20]):
plots:-display(A, B, scaling=constrained, axes=none);

 

 

Addition. Prim's algorithm is easy to implement in Maple, but now I do not have time to do this (maybe tonight I'll do it)

To improve accuracy, I used timestep and spacestep options. I took the range  t=0..0.5, because already for  t = 0.5  your function is practically equal to 0 (see below). For integration, a spline of 1 order was used :

restart; 
k:=5:
EQ:=diff(u(x,t),t)=k*diff(u(x,t), x$2):
ibc:=u(0,t)=0, u(1,t)=0, u(x,0) = x:
sol:=pdsolve({EQ}, {ibc}, numeric, timestep = 0.001, spacestep = 0.005):
p1:=sol:-plot(u, x=0.5, t=0...0.5, style = line, color = "Blue", legend = "heat Plot", axes=boxed);
M:=op(1, op(1, p1)):
f:=CurveFitting:-Spline(M, t, degree=1):
int(f, t=0..0.5);  
# The area under p1
eval(f, t=0.5);  # The value of the function for t=0.5

extrema  command by  's'-option  allows you to find all the critical points (in which both partial derivatives are 0). Student[MultivariateCalculus][SecondDerivativeTest]  command allows you to classify these points (LocaMin, LocalMax, or Saddle) :


restart;

f:=(x,y)->x^3 + 3*x*y^2 - 15*x + y^3 - 15*y:
extrema(f(x,y), { }, {x,y}, 's');
 # The minimum and maximum values of the function at critical points

s;  # All critical points

for p in s do
p1:=convert(p, list);
print(Student[MultivariateCalculus][SecondDerivativeTest](f(x,y), lhs~(p1)=rhs~(p1)));
od:  
# Classification of the critical points

with(plots):
display(plot3d(f(x,y), x=-6..6, y=-6..6, view=-60..60, orientation=[145,60]), pointplot3d(map(t->[rhs~(t)[ ], f(rhs~(t)[ ])]
, s), symbol=solidcircle, color=red, symbolsize=20));  # Plot

 

Edit.

f:=x->Statistics:-PDF(Weibull(6.2, 2), x):
A:=plot(f, 0..26, color="DodgerBlue", thickness=3, tickmarks=[spacing(5), spacing(0.02)], axis[2]=[gridlines=8], view=[0..30,0..0.16], size=[600,400], legend=Series1, legendstyle=[font=[times,roman,16], location=right]):
B:=plot([seq([x,f(x)], x=0..26)], style=point, symbol=soliddiamond, symbolsize=18, color="DodgerBlue"):
plots:-display(A, B);


 

Suppose that such a function  F  exists. Then we have for  t=exp(1) :

F(F(exp(t))) = F(t) = F(exp(1))=1  instead of  .

 

We see that these conditions (F(exp(t)) = t  and  F(F(exp(t))) = 0)

contradict one another.

y=0.0000125698-0.0000125698*cos(54*x);
a:=convert(%, fraction);
b:=content(rhs(a), cos(54*x));
c:=primpart(rhs(a), cos(54*x));
y=b*``(c);
convert(%, float, 6);

 

You just have to solve equation  g(x)=1.2*f(x) :

f:=x->75000*exp(-0.045*x)+100000:
g:=x->300000/(1+100000/3333*exp(-0.08*x)):
fsolve(g(x)=1.2*f(x), x=0..70);  
# The result
plot([f, g], 0..70, color=[red,green], legend=[urban,rural]);  # Visualization
 

Try

int(evalc(exp(I*x*(2-y))),[x=-infinity..infinity, y=0..2]);  # Or
evalf(Int(evalc(exp(I*x*(2-y))),[x=-infinity..infinity, y=0..2]));

 

The  F  procedure solves the problem:

F:=(i, x)->rand(i-x .. i+x)( );


Example of use:

seq(F(20, 5), k=1..20);

            19, 15, 16, 22, 24, 16, 19, 15, 17, 23, 16, 16, 17, 19, 18, 18, 19, 25, 22, 25


Since there are  i+x-(i-x-1)=2*x+1  numbers in total in the range  i-x .. i+x, the probability of each individual number is  1/(2*x+1) .


Edit.

Use initial conditions and  numeric  option. You can get the values of a function at individual points and plot its graph.

Example:

Sol:=dsolve({-1.699678499+diff(z(t), t, t)-3.813322790*z(t)+.6966019659*z(t)^2+0.1548004368e-1/z(t)^2 = 0, z(0)=1, D(z)(0)=0}, z(t), numeric);
Sol(1);
plots:-odeplot(Sol, [t,z(t)], t=0..10, view=0..10);

 


 

Obviously this is bug. Even if you use  RealDomain:-solve  command, the error persists :

RealDomain:-solve(-sqrt(k*x) = sqrt(k*x+k-1), {k,x});

                               {k = 1, x = x}

z:=x+I*y:
evalc(abs(z+3-2*I) + abs(z-3-8*I)) = 6*sqrt(2);

sqrt((3+x)^2+(y-2)^2)+sqrt((-3+x)^2+(y-8)^2) = 6*sqrt(2)

Geometrically, this equation defines on the plane  (x, y)  the set of such points, the sum of the distances from each of which to fixed points  A(-3, 2)  and  B(3, 8)  is equal to  6*sqrt(2) . But the distance between these points is the same number  6*sqrt(2). Therefore this set is the segment joining points  A  and  B : .  Therefore, the minimum and maximum is reached inside or at the ends of this segment:

A:=[-3,2]: B:=[3,8]:
C:=(1-t)*~A+t*~B:  
# Arbitrary point of the segment  AB
simplify([(minimize,maximize)(sqrt(C[1]^2+C[2]^2), t=0..1)]);

                        [5*sqrt(2)*(1/2), sqrt(73)]

 

Edit.


                                     

Here is another very simple way, which is even slightly more effective than  select :

CodeTools:-Usage(seq(`if`(isprime(n),n,NULL),n=10^5..10^6)):
memory used=231.00MiB, alloc change=-3.43MiB, cpu time=4.67s, real time=4.72s, gc time=296.88ms

CodeTools:-Usage(select(isprime, [$10^5..10^6])):
memory used=268.77MiB, alloc change=3.43MiB, cpu time=5.31s, real time=5.31s, gc time=687.50ms


 

I don't know such the function, but the simple procedure  PrimesInRange  solves the problem:

PrimesInRange:=proc(a, b)
local p, n;
p[1]:=nextprime(a-1); 
for n from 1 while p[n]<=b do
p[n+1]:= nextprime(p[n]) 
od:
seq(p[k], k=1..n-1);
end proc:


Example of use:

PrimesInRange(1, 100);
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97


 

First 155 156 157 158 159 160 161 Last Page 157 of 290