Carl Love

Carl Love

28025 Reputation

25 Badges

12 years, 307 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

@Chia

If I understand your Reply "Is it possible to realize the translation?" correctly, you want to translate (also known as "pan") and zoom without changing the viewing angle. (It's the same as doing a "fly-over" view with decreasing altitude.) The key to this is that the look be the projection into the xy plane of the location. (That is, if the location is [x,y,z], then the corresponding look is [x,y,0].) That way you're always looking straight down even if x and y are changing due to the translation. Here's an example:

(zr,zi):= (Re,Im)(Zeta(1/2+I*im)):

plots:-display(
     [
          plots:-spacecurve([im,zr,0], im= 0..60, numpoints= 1000, color= red),
          plots:-spacecurve([im,zi,0], im= 0..60, numpoints= 1000, color= blue)
     ],
     viewpoint= [
          location= [seq([k/5,0,610-2*k], k= 150..300)],
          look= [seq([k/5,0,0], k= 150..300)],
          upvector= [0,1,0]
     ],
     axes= normal, axis[1]= [tickmarks= 60],
     title= typeset("Zeros of ",zeta(1/2+i*y)), titlefont= [HELVETICA,14]             
);

Is that what you're talking about?

You can take an operation such as subtraction an append a tilde to the operator to make it into an "elementwise" operator, which means that the operation will be performed on each element in a container, such as a vector.

theta:= 90 -~ M(..,1);

A "naked" tilde can be used to apply any procedure to each element in a container:

phi:= (x-> `if`(x < 0, 360+x, x)) ~ (M(..,2));

All of the parentheses are required in the above. An alternate syntax is

phi:= map(x-> `if`(x < 0, 360+x, x), M(..,2));

See ?map and ?elementwise .

r=0 is a regular singular point of your differential equation, so you can't give initial conditions at 0.

The error arises because there is no way to compute the recursive function _C when the input is symbolic n. I recommend first using rsolve to get a nonrecursive expression for the coefficients, like this:


restart:

R1:= rsolve({_C(n) = -_C(n-2)/n/(n-1), _C(0)= C[0], _C(1)= C[1]}, {_C(n)});

((1/2)*C[0]+((1/2)*I)*C[1])*(-I)^n/GAMMA(n+1)-((1/2)*I)*(I*C[0]+C[1])*I^n/GAMMA(n+1)

convert(%, factorial);

((1/2)*C[0]+((1/2)*I)*C[1])*(-I)^n/factorial(n)-((1/2)*I)*(I*C[0]+C[1])*I^n/factorial(n)

simplify(%) assuming n::nonnegint;

-(1/2)*(I*exp(((1/2)*I)*n*Pi)*C[1]-I*exp(-((1/2)*I)*n*Pi)*C[1]-exp(((1/2)*I)*n*Pi)*C[0]-exp(-((1/2)*I)*n*Pi)*C[0])/factorial(n)

R2:= evalc(%) assuming n::nonnegint;

(cos((1/2)*n*Pi)*C[0]+sin((1/2)*n*Pi)*C[1])/factorial(n)

sum(R1*x^n, n= 0..infinity);

(1/2)*C[0]*exp(I*x)-((1/2)*I)*C[1]*exp(I*x)+(1/2)*C[0]/exp(I*x)+((1/2)*I)*C[1]/exp(I*x)

sum(R2*x^n, n= 0..infinity);

C[0]*cos(x)+C[1]*sin(x)

 


Download rsolve_sum.mw

Zooming animations are possible in a 3d plot by using the viewpoint option (see ?plot3d,viewpoint ). A 2d plot can be represented in a 3d plot by plotting only in the xy plane and setting the "camera" locations to look straight down the z axis or a line parallel to the z axis. Here's an example:

plots:-spacecurve(
     [x, sin(x), 0], x= -Pi..Pi, scaling= constrained,
     color= red,
     viewpoint= [location= [seq([0,0,10*k], k= 100..10,-1)]],
     axes= normal
);

Note that the viewpoint option is implemented in the "plot renderer" (i.e., in the GUI) rather than in Maple language itself. As such, it cannot be accessed with either of the regular animation commands: plots:-animate or plots:-display(..., insequence). It is not possible to zoom with either of these older animation commands for the reason that you noticed: The view for the whole animation is fixed to the maximal view that occurs in any of the frames.

The weight matrix completely determines the graph, so this is particularly easy.

G3:= GraphTheory:-Graph(LinearAlgebra:-Zip(max, W1, W2));

or, if you need further access to W3 (seems likely), do

W3:= LinearAlgebra:-Zip(max, W1, W2);
G3:= GraphTheory:-Graph(W3);

Try changing "times" to TIMES (all capitals, no quotes) and "roman" to ROMAN. I think that that will fix your problem, but I don't know why you are having the problem. Your original code works for me in Maple 16 on Windows 7.

The RandomMatrix is generating integers in the range -99..99 with a uniform distribution. The Generate is generating floats in the range 0..1 with a logarithmic distribution. The former is a much easier task, so the two can't really be compared. Furthermore, time[real](...) is irrelevant; you want plain time(...).

One thing you can do is use simplify with side relations. For example,

relations:= {n1+n2=1}:
expression:= n1+expand((n1+n2)^2);

simplify(expression, relations);

 

Pull down the Tools menu, and open the Options dialog. Click on the Display tab. The fifth check box is "Always insert new execution group after executing". Make sure that box is not checked. Then click Apply Globally. Let me know if that fixes your problem.

Remove the option y= 0..100.

ODE2:=(Diff(T(t), t) = 1/59*(18-T(t))):
DEtools[DEplot]( ODE2, T(t), t=-4..4, {[T(0)=88]});

Your problems are caused by your combining several with commands into one statement. You have

with(plots), with(ColorTools), with(LinearAlgebra), with(RandomTools), with(ExcelTools);

You should change that to

with(plots); with(ColorTools); with(LinearAlgebra); with(RandomTools); with(ExcelTools);

The results of chaining with statements seems unpredictable. Note the following proviso from ?with :

The with command is effective only at the top level, and intended primarily for interactive use. Because with operates by using lexical scoping, it does not work inside the bodies of procedures, module definitions, or within statements. [emphasis added]

Although I can't tell what's wrong with your code until you upload it, here's an example of correctly doing what you want to do. Maybe you'll be able to correct your code from this.

restart:
with(VectorCalculus):
SetCoordinates(cartesian[x,y]):
V:= VectorField(< x+y, x-y >):
F:= (X,Y)-> VectorCalculus:-Norm(VectorCalculus:-evalVF(V, < X,Y >)):
F(1,2);

Here's how to apply the weights from your main graphs to your subgraphs constructed from the paths.

ApplyWeights:= proc(G1::GraphTheory:-Graph, G2::GraphTheory:-Graph)
#Apply the weights from G1 to G2.
uses GT= GraphTheory;
local W:= GT:-WeightMatrix(G1, copy= false);
     GT:-Graph(
          map(e-> [e, W[e[]]], GT:-Edges(G2, weights= false))
     )
end proc:          

G4:= ApplyWeights(G1, G3);

G5:= ApplyWeights(G2, G3);

Here's how to do it. I used essentially the same example as I did for your previous question, except that I made it a directed graph instead of undirected, because I think that's more relevant to your application.


restart:

randomize(2): #Needed to get nontrivial minimal paths.

N:= 100:  #Number of vertices

E:= 2300: #Number if directed edges

CartProdSeq:= proc(L::seq(list))

local Seq,i,j;

option `Copyright (C) 2007, Joseph Riel. All rights reserved.`;

    eval({subs(Seq=seq, foldl(Seq

                              , [cat(i,1..nargs)]

                              , seq(cat(i,j)=L[j],j=nargs..1,-1)

                             ))});

end proc:


AllPossibleEdges:= [
     (CartProdSeq([$1..N], [$1..N]) minus
           {seq([k,k], k= 1..N)}
      )[]
]:

Edges:= combinat:-randcomb(AllPossibleEdges, E):

Weights1:= RandomTools:-Generate(list(float(method= uniform), E)):

WeightedEdges1:= {zip(`[]`, Edges, Weights1)[]}:

G1:= GraphTheory:-Graph(WeightedEdges1);

GRAPHLN(directed, weighted, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100], Array(%id = 18446744074187374710), `GRAPHLN/table/1`, Matrix(%id = 18446744074216096014))

Weights2:= RandomTools:-Generate(list(float(method= uniform), E)):

WeightedEdges2:= {zip(`[]`, Edges, Weights2)[]}:

G2:= GraphTheory:-Graph(WeightedEdges2);

GRAPHLN(directed, weighted, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100], Array(%id = 18446744074187375070), `GRAPHLN/table/2`, Matrix(%id = 18446744074198802974))

(Path1,Cost1):= GraphTheory:-DijkstrasAlgorithm(G1, 1, N)[];

[1, 31, 52, 58, 54, 14, 100], .199037223686419

(Path2,Cost2):= GraphTheory:-DijkstrasAlgorithm(G2, 1, N)[];

[1, 49, 24, 5, 14, 100], .418737682605255

Path_to_Edges:= proc(P::list)
local k;
     {seq([P[k], P[k+1]], k= 1..nops(P)-1)}
end proc:


PPath1:= Path_to_Edges(Path1);

{[1, 31], [14, 100], [31, 52], [52, 58], [54, 14], [58, 54]}

PPath2:= Path_to_Edges(Path2);

{[1, 49], [5, 14], [14, 100], [24, 5], [49, 24]}

G3:= GraphTheory:-Graph(PPath1 union PPath2);

GRAPHLN(directed, unweighted, [1, 5, 14, 24, 31, 49, 52, 54, 58, 100], Array(%id = 18446744074187376150), `GRAPHLN/table/3`, 0)

WeightOfPath:= proc(G::GraphTheory:-Graph, P::list)
local
     e,
     W:= GraphTheory:-WeightMatrix(G, copy= false)
;
     add(W[e[]], e in Path_to_Edges(P))
end proc:


WeightOfPath(G1, Path1);

.199037223686419

WeightOfPath(G2, Path2);

.418737682605255

 


Download Two_Paths.mw

First 298 299 300 301 302 303 304 Last Page 300 of 395