Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

The distance function that I gave before should be modified to account for cases that require no horizontal travel. This doesn't affect the final results previously obtained because your example doesn't have any such pairs of points. The new distance function is 

dist:= proc(p::[integer,integer], q::[integer,integer])
local H;
    if p[1]=q[1] then abs(p[2]-q[2])
    else min((add@abs~)~([seq]([p[2]-H, p[1]-q[1], H-q[2]], H= [1,10])))
    fi
end proc      
:

 

@jalal In the line defining fnew, try changing ^+ to ^%T. They mean the same thing---transpose the matrix---but ^+ only works in (plaintext) 1D input.

@Teep Here is the code to highlight with arrows the direction of travel for the solution to the traveling salesman problem.

restart:
GT:= GraphTheory: Pl:= plots: Co:= combinat:
dist:= proc(p::[integer,integer], q::[integer,integer])
local H;
    min((add@abs~)~([seq]([p[2]-H, p[1]-q[1], H-q[2]], H= [1,10])))
end proc      
:
HighlightTour:= proc(    
    #edges:
    E::set([And(set({name, string, integer}), 2 &under nops), numeric]),
    #tour:
    T::list({name, string, integer}), #the  tour
    #vertices (optional, for positions only):
    V::list({name, string, integer} = [realcons,realcons]):= 0
)
uses GT= GraphTheory;
local G0,Gt;
    (G0,Gt):= GT:-Graph~(
        [selectremove](e-> e[1]::set, subs((`{}`=`[]`)~(T[..-2],T[2..]), E)),
        `if`(V=0, [][], 'vertexpositions'= rhs~(V))
    )[];
    GT:-HighlightTrail(Gt, T, _rest, 'inplace');
    G0,Gt
end proc
:
pts2 := [A = [5, 0], B = [8, 9], C = [2, 8], D = [4, 3], E = [7, 4]]:
Edgs:= {seq}([({op}@lhs~)(e), dist(rhs~(e)[])], e= Co:-choose(pts2, 2)):
G1:= GT:-Graph(Edgs):
(distance, Tour):= GT:-TravelingSalesman(G1);
            distance, Tour := 38, [A, D, C, B, E, A]
(G0,Gt):= HighlightTour(Edgs, Tour, pts2);
G0, Gt := Graph 1: an undirected weighted graph with 5 vertices 
   and 5 edge(s), 
  Graph 2: a directed weighted graph with 5 vertices and 5 arc(s)

Pl:-display(GT:-DrawGraph~([G0,Gt], style= circle, stylesheet= "legacy"));

#Using actual vertex positions:
Pl:-display(GT:-DrawGraph~([G0,Gt], stylesheet= "legacy"));

To see the tour (red) edges only, remove G0 from either of those plot commands.
 

I'm having some trouble at the moment loading the workbook format (*.maple). Would it be possible for you to duplicate the error in the worsheet (*.mw) format?

If you don't give any constraints, then obviously there's no upper bound. For example, you could make A1 any large value and make all the other variables 0.

@Vini Your new Question, which I just deleted twice, is too close to this Question. Please discuss the matter in this thread.

At this point, I don't see any mathematical difference whatsoever in the two Questions; so, please try to say more precisely what you think the difference is.   

@Carl Love The above can be improved a little. I don't like that the 17 bars are crammed into interval 0..16. The interval should be -0.5..16.5. The improvement is a command called tallyinto.

B:= 16:
plots[display]([
    stats[statplots, histogram](
        stats[transform, tallyinto](
            map(`+`@op@convert, [$0..2^B-1], base, 2),
            [seq](k-1/2..k+1/2, k= 0..B)
        ),
        area= 2^B, color= pink, thickness= 0
    ),        
    plot(binomial(B,x), x= 0..B, color= blue, thickness= 2)
]);

@logan35 Oh my, Maple 7. That's a shame. In general, it's going to be difficult for you to get usable answers here on MaplePrimes. Very few of us have versions that old (about 20 years). Luckily, I've been using Maple long enough to have some memory of the old commands. So, try this:

plots[display]([
    stats[statplots, histogram](
        map(`+`@op@convert, [$0..2^16-1], base, 2), 
        area= 2^16, numbars= 17, color= pink
    ),        
    plot(binomial(16,x), x= 0..16, color= blue, thickness= 3)
]);

 

@logan35 The entire program is simply the one line that I gave:

Statistics:-Histogram((`+`@op@Bits:-Split)~([$0..2^16]), binwidth= 1);

@Teep Sorry, that was my fault. Try again; I just edited the code.

@acer Here is the OP's original attached worksheet:
 

VectorCalculus[Nabla] := 5

Error, attempting to assign to `VectorCalculus:-Nabla` which is protected

 

Delta := k

k

(1)

y := c+Delta

c+k

(2)

c := 2

2

(3)

"y:="

Error, invalid assignment

"y:="

 

y

2+k

(4)

restart

R := 1511.6

1511.6

(5)

t := 25.4

25.4

(6)

Rrt := R/t

59.51181102

(7)

E := 200*10^9

200000000000

(8)

nu := .29

.29

(9)

Ea := E/(-nu^2+1)

0.2183644503e12

(10)

F := 221*10^6

221000000

(11)

eq1 := sqrt((9*PI^2/(4*beta^2)-1)*(PI-alpha+beta*(sin(alpha)/sin(beta))^2)/(12*(sin(alpha)/sin(beta))^3*(alpha-0.4e-3*PI-beta(sin(alpha)/sin(beta))*(1+(1/4)*tan(alpha-beta)^2))))-Rrt = 0

(1/6)*3^(1/2)*(((9/4)*PI^2/beta^2-1)*(PI-alpha+beta*sin(alpha)^2/sin(beta)^2)*sin(beta)^3/(sin(alpha)^3*(alpha-0.4e-3*PI-beta(sin(alpha)/sin(beta))*(1+(1/4)*tan(alpha-beta)^2))))^(1/2)-59.51181102 = 0

(12)

eq2 := (9*PI^2/(4*beta^2)-1)/(sin(alpha)/sin(beta))^3-12*P*Rrt^3/Ea = 0

((9/4)*PI^2/beta^2-1)*sin(beta)^3/sin(alpha)^3-0.1158267336e-4*P = 0

(13)

eq3 := 1000*((1-sin(beta)/sin(alpha))/(2*Rrt)+P*Rrt*sin(alpha)/(Ea*sin(beta))+12*P*Rrt^2*beta*sin(alpha)^2*tan(alpha-beta)/(3*PI*Ea*sin(beta)^2)-F/Ea) = 0

7.389624070-8.401693570*sin(beta)/sin(alpha)+0.2725343385e-6*P*sin(alpha)/sin(beta)+0.6487604820e-4*P*beta*sin(alpha)^2*tan(alpha-beta)/(PI*sin(beta)^2) = 0

(14)

PI := 3.1415

3.1415

(15)

solve({eq1, eq2, eq3})

``


 

Download critical_pressure_calculation.mw

@madhav123 I wasn't suggesting that the solutions were non-real. I said "You can ignore the imaginary parts" because they are truly 0, and the solutions are truly real. The imaginary parts are just decimal rounding errors essentially past the 20th decimal place.

However, I have found a typo in your coding of the equations, which was the cause of your troubles. See my 2nd Answer.

@ContrapuntoBrowniano You wrote:

  • Both "add" commands need two arguments (maybe it's my version, Maplesoft 18)!

Yes, it's a version issue; the ability to call addseq, and mul with one argument (that argument usually being a "container" (set, list, array, etc.)) was added after Maple 18. As you've probably figured out by now, add(A) is equivalent  to add(x, x= A) in older versions.

  • i tried "add(x[ ],x=S)" and i got a more satisfactory answer, though.

That will only work if all the sets in S have the same number of elements. But this will work in your version regardless of sizes:

`+`(seq(x[], x= S))

@Preben Alsholm Note that the in the help-page passage that you quoted is defined earlier on that page: It's the sum of the squared residuals. So, for the case at hand, SolveEquations is finding minima of (cos(x) - 0.001*x^2)^2, and the first column of the returned matrix is that expression evaluated at the given in the third column.

@Shashwata Chowdhury Thank you. I coded the above so that L3 could be created from L1 and L2. The only good reason to do it that way is if L1 and L2 are going to be used later. If, on the other hand, L1 and L2 are only being used as building blocks for L3, then it's easier to not create them at all. Rather create L3 directly as

L3:= [seq]([seq](seq1[j]+i, j= 1..7), i= 0..23);

First 92 93 94 95 96 97 98 Last Page 94 of 708