Carl Love

Carl Love

28035 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

I wrote a Maple solution for this using the simplest code I could, and using only simple formulas from high-school algebra and geometry---no piecewise, integrals, etc. Let me know if you can understand this better.
 

 

t1 := Matrix(14, 2, {(1, 1) = 0, (1, 2) = 0, (2, 1) = 0, (2, 2) = 4170, (3, 1) = 1, (3, 2) = 3966, (4, 1) = 1, (4, 2) = 3466, (5, 1) = 3, (5, 2) = 3058, (6, 1) = 3, (6, 2) = 3058, (7, 1) = 4, (7, 2) = 1854, (8, 1) = 4, (8, 2) = 1354, (9, 1) = 7, (9, 2) = -2258, (10, 1) = 7, (10, 2) = -2758, (11, 1) = 8, (11, 2) = -3962, (12, 1) = 8, (12, 2) = -3962, (13, 1) = 10, (13, 2) = -4370, (14, 1) = 10, (14, 2) = 0})plot(t1);  

 

The intersection of this plot with the x-axis should be ≈ 5.125 and the area from 0 to 5.125 (or from 5.125 to 10) should be ≈ 13810``       

X:= t1[..,1]:  Y:= t1[..,2]: #Separate data by columns.

n:= numelems(X):

for k from 2 to n-1 do
   if Y[k]*Y[k+1] <= 0 then #Crossed the x-axis.
      #Formula for x-intercept of a line given in two-point form:
      x0:= (X[k+1]*Y[k] - X[k]*Y[k+1])/(Y[k]-Y[k+1]);
      break #i.e., exit the loop
   end if
end do:
      

'x0' = (x0 = evalf(x0));

x0 = (3085/602 = 5.12458471760797)

k;

8

Area:= 0:

for j from 2 to k-1 do
   Area:= Area + (X[j+1]-X[j])*(Y[j]+Y[j+1])/2 #Trapezoid area formula
end do:
Area:= Area + (x0-X[k])*Y[k]/2: #Triangle area formula     

'Area' = (Area = evalf(Area));

Area = (8313225/602 = 13809.3438538206)

#Bonus: Derivation of x-intercept formula:

solve((0-y0)=(y1-y0)/(x1-x0)*(x-x0), x);

-(x0*y1-x1*y0)/(-y1+y0)

``


 

Download Trapezoids.mw

It's done like this:

addcoords(
   EEspherical,
   [rho, theta, phi],
   [rho*cos(phi)*sin(theta), rho*sin(phi)*sin(theta), rho*cos(theta)]
);

Or, you can simply replace the existing spherical coordinates by using spherical instead of EEspherical.

You can add this command to an initialization file.

Assuming that you don't want to explicitly set the vertex positions and that you'll accept any reasonanly spread-out planar representation of the graph, it can be done like this:
 

``

NULL

I want to create the above network, given the following distance matrix

restart:

dist:= Matrix(
   (7$2), shape= symmetric, scan= band[0,6],
   [[0$7], [7, 11, 7, 15, 14, 8], [4, 12, 16, 5, 6], [5, 5, 3, 9], [12, 14, 11], [7, 11], [14]]
);

dist := Matrix(7, 7, {(1, 1) = 0, (1, 2) = 7, (1, 3) = 4, (1, 4) = 5, (1, 5) = 12, (1, 6) = 7, (1, 7) = 14, (2, 2) = 0, (2, 3) = 11, (2, 4) = 12, (2, 5) = 5, (2, 6) = 14, (2, 7) = 11, (3, 3) = 0, (3, 4) = 7, (3, 5) = 16, (3, 6) = 3, (3, 7) = 11, (4, 4) = 0, (4, 5) = 15, (4, 6) = 5, (4, 7) = 9, (5, 5) = 0, (5, 6) = 14, (5, 7) = 6, (6, 6) = 0, (6, 7) = 8, (7, 7) = 0}, storage = triangular[upper], shape = [symmetric])

demand:= <100, 200, 120, 45, 250, 80, 75>:

hubs:=[seq(parse(i), i = "A" .. "G")]:

seq(assign(Index(hubs[k])= k), k= 1..nops(hubs));

seq(assign(Vlabels(v)= sprintf("%a %d", v, round(demand[Index(v)]))), v= hubs);

edges:= {{A,C},{A,D},{C,D},{C,F},{D,F},{D,G},{G,E},{E,B},{B,A}}:

subsindets(edges, set(name), e-> [e, dist[Index~(e)[]]]);

{[{A, B}, 7.0], [{A, C}, 4.0], [{A, D}, 5.0], [{B, E}, 5.0], [{C, D}, 7.0], [{C, F}, 3.0], [{D, F}, 5.0], [{D, G}, 9.0], [{E, G}, 6.0]}

edgesL:= subsindets(%, name, Vlabels);

{[{"A 100", "B 200"}, 7.0], [{"A 100", "C 120"}, 4.0], [{"A 100", "D 45"}, 5.0], [{"B 200", "E 250"}, 5.0], [{"C 120", "D 45"}, 7.0], [{"C 120", "F 80"}, 3.0], [{"D 45", "F 80"}, 5.0], [{"D 45", "G 75"}, 9.0], [{"E 250", "G 75"}, 6.0]}

macro(GT= GraphTheory):

G:= GT:-Graph(edgesL);

GRAPHLN(undirected, weighted, ["A 100", "B 200", "C 120", "D 45", "E 250", "F 80", "G 75"], Array(%id = 18446744579123119758), `GRAPHLN/table/1`, Matrix(%id = 18446744579132820806))

GT:-SetVertexPositions(G, GT:-GetVertexPositions(G, style= spring));

GraphTheory:-DrawGraph(G, font= [HELVETICA,BOLD,10]);


 

Download DrawnGraph.mw

PolyhedralSets:-Plot(
   PolyhedralSets:-PolyhedralSet(
      {-x-y+3*z >= 0, -x+2*y >= 0, 3*x-2*y-z >= 0}
   )
);

Good Question; Vote Up.  You should do it like this:

Package:= module()
option package;
export 
   Output:= proc(Input)
      Record(
         'o1'= f1(Input)
         'o2'= f2(Input)
         'o3'= f3(Input)
      )
   end proc
;
end module:         

A Record is just a special simple type of module that only has exports, and there's no interaction amongst them. So, you would still access this as Output(Input):-o1.

Your stepsize is too large to get accurate results. Try this instead:

DEtools[DEplot](
   sys, {x(t), xdot(t)}, t= 0..200, {[x(0)=3, xdot(0)=4]}, 
   stepsize= 0.01, linecolour= blue, thickness= 0, 
   view= [-4..4, -3..3]
);

convert(F, set);
convert(G, list);

I prefer these more-efficient variants:

{F[ ]};
[G[ ]];

Note that it is impossible to control the order that items appear in a set. Maple uses an order that makes lookup efficient and is consistent across sessions.

The area of any non-self-intersecting polygon in the coordinate plane can be found very easily with the shoelace formula (Wikipedia link).

I don't understand your second question.

The derivative of a curve is the tangent of the angle that the tangent line makes with the positive x-axis. You need to find the points where the curves intersect, and find the difference of the arctans of the derivatives at those points. It is not clear whether your g should be cos(x^2) or cos(x)^2. I'll use the latter; the solution process is identical for either.

f:= x-> sqrt(x^4+5)/(sin(x)+5):
g:= x-> cos(x)^2:
plot(f-g);

r:= map2(fsolve, f-g, [-2..0, 0..2]): #Ranges determined from plot.
`-`(arctan@~(D(f),D(g)))~(r);

[-.958033052751182, .830203838366253]

That gives you the two angles in radians.

Those last two lines of code in expanded and perhaps more-readable form are:

r1:= fsolve(f-g, -2..0);
r2:= fsolve(f-g, 0..2);
arctan(D(f)(r1)) - arctan(D(g)(r1));
arctan(D(f)(r2)) - arctan(D(g)(r2));

But I write the way that I do because I disdain repetitive code.

Edit: Corrected "arctan of difference" to "difference of arctans".

Edit: Added code expansion, following VV's suggestion.

I believe that the interrupt button may only work when executing Maple-level code. That means that it doesn't work while kernel code is executing or while results are displaying after the computation is finished.

You shouldn't kill the Java process in Task Manager---that is a huge waste of time---plus you'll need to recover your unsaved worksheets (and those recoveries are not always complete). Instead, using the "More details" view of Task Manager, find the mserver.exe process that is running. It'll be the one with a larger number in the CPU column. You can click on the column header to sort by CPU. Kill that mserver.exe. Your worksheet will now have a "Kernel connection has been lost" pop-up. Ignore what the pop-up says---it is incorrect (and BS). Dismiss the pop-up. Save your worksheet. Close your worksheet. Reopen your worksheet (using the Recent Documents menu item). You're done.

That may sound like a lot of steps, but once you learn them, they'll save you much time over killing the Java process, especially if you have multiple worksheets open. It is just generally a good idea, not just with respect to Maple, to have Task Manager running at all times, in the "More details" view, sorted by the CPU column.

In the definition of Gr you use square brackets [ ]. In Maple, you can't use square brackets for algebraic grouping; you must use parentheses ( ). Square brackets have many uses in Maple, mostly dealing with indexable structures.

Here's an example:
 

f:= randpoly(x):

Student:-Calculus1:-FunctionChart(f, -2..2, pointoptions= [symbolsize= 24, color= red]);

#These are the x-coords of the red circles on the graph (roots or x-intercepts):
fsolve(f, x= -2..2);

-1., .918559742308401

#This is the x-coord of the interior red diamond on the graph (extremum):
fsolve(diff(f,x), x= -2..2);

.233921026056907

#These are the x-coords of the red crosses on the graph (inflection points):
fsolve(diff(f,x,x), x= -2..2);

-.297635283207037, -.101434768857792, 1.54573671873150


 

Download FunctionChart.mw

This is exactly what Records are for.

MyCars:= {
   Record('make'= Honda, 'color'= green, year= 2008),
   Record('make'= Honda, 'color'= red, 'model'= Civic, 'year'= 2004),
   etc.
};

See ?Record.

Then you can do things like

select(C-> C:-color = red, MyCars);

Here's a procedure to handle this which behaves correctly when there are multiple distinct names beginning with _. The key is the use of type suffixed.

Change_:= proc(e, new::name)
local 
   N:= indets(e, suffixed(_)),
   n:= nops(N), k
;
   subs(N=~ `if`(n=1, new, {new||(1..n)}), e)
end proc:  

Usage:

Change_(symbolic, n);

The direct answer to your Question is to execute this after the loop:

Result_Eva_GB_X2:= (x-> `if`(x=[], [0], x))~(Result_Eva_GB_X2);

However, pedagogically, I don't think that this is a good thing to do. The answer is not 0. One possibility is to use undefined instead of 0.

First 200 201 202 203 204 205 206 Last Page 202 of 395