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 answers submitted by Carl Love

This Answer is to address the OP's followup question. There are several naive ways to implement your FirstMatch with very brief code; however, these mostly have quadratic running time. The following method avoids repeated linear searches of A by first converting it to a set.

A:= [5,10,15,20,25,30,35,40,45,50]:
B:= [7,14,21,28,35,42]:

FirstMatch:= proc(B::list, A::list)
local AS:= {A[]}, i, j;
     for i to nops(B) do if B[i] in AS then member(B[i], A, j); return i,j fi od
end proc:

FirstMatch(B,A);

     5, 7

I prefer to achieve results similar to Kitonum's simply by using the Statistics:-Histogram command. In the code below, the 10000 can be any similar large number, and the .5 in the binbounds can be adjusted as needed.

X:= [1,     3,      5,     7     ]:
P:= [1/8, 1/2, 1/4, 1/8]:
Statistics:-Histogram(
     zip(`$`, X, round~(10000*P)),
     binbounds= (x-> (x-.5, x+.5))~(X), 
     tickmarks= [X, P =~ P]
);

See ?Statistics,Histogram, ?$, ?zip, ?plot,tickmarks, and ?plot,typesetting.

There are many things that can be done. Do you want an exact result, or would a decimal result be okay? If a decimal result is okay, use evalf like this:

Ans:= dsolve([sys_ode, ics]);
evalf(Ans);

If you want to maintain the exactness of the result, do

simplify(expand(Ans), size);

These approaches can be combined in any order, but note that conversion to decimal form is essentially a one-way operation:

evalf(simplify(expand(Ans), size));

In the future, please post your code as an attached worksheet rather than an attached picture. That way we can work with it. Also do this if you want more help on this problem.

Use applyrule like this,

rule:= abs(''a''::algebraic)*abs(1,''a''::algebraic)= ''a'':

(Note that those quotes are double single quotes, not single double quotes.) Example of use:

ex:= sin(x)*abs(sin(y))*abs(1,sin(y)):
applyrule(rule, ex);

Your simplify with side relations didn't work because that only works with polynomial relations.

int(t-> N(i, n, t, T)*N(j, n, t, T), 0..1, numeric):

If Phi is your matrix, then do

subsindets(
     plots:-sparsematrixplot(Phi, 'matrixview'),
     specfunc(AXESTICKS),
     subsindets,
     list,
     L-> `if`(L::list(`=`), [seq(lhs(E) = Eq||(rhs(E)), E= L)], L =~ [q||(L[])])
);

This'll produce decent results even if the matrix is large. If you try to explicitly set the tickmarks (as in Kitonum's solution) for a large matrix, they may be too crowded to view. My solution modifies the tickmarks that are already in the plot rather than creating new tickmarks.

indets(eq, function(identical(t)));

The lhs and rhs are superfluous.

It's fairly straightforward:

f:= cos(2*t/m) + cos(2*(t+5)/m):
plot('maximize'(f), m= 1..10);

It's quite an interesting function! I wouldn't have expected the points of nondifferentiability (one is at m=Pi I believe).

Note that the command plot('maximize(f)', m= 1..10) won't work because that makes it treat f as unassigned.

Yes, it is easy to use a color gradient in a 2D point plot. In the following, assume that

  • XY is a list of pairs of (x,y)-values (each pair itself being a list), 
  • f is a function of two variables that returns your f-value for any point as a floating-point number (force it to floating point with evalf if you need to),
  • Mf is the maximum value of f,
  • mf is the minimum value of f.

Then do

R:= Mf - mf:
plot(`[]`~(XY), style= point, color= [seq(COLOR(HUE, (f(xy[]) - mf)/R), xy= XY)]);

For example, here I take 2^12 random points in [-9,9] x [-9,9] and color them based on the sine of the x-coordinate:

XY:= RandomTools:-Generate(list(list(float(range= -9..9), 2), 2^12)):
plot(`[]`~(XY), style= point, color= [seq(COLOR(HUE, (1+sin(xy[1]))/2), xy= XY)]);

 It is also possible to do a gradient between any two given colors.

Here is the command to create the graph, where and are the vertices of degree 2 that I added.

K:= GraphTheory:-Graph({{1,A},{1,2},{1,4},{1,B},{2,3},{3,4},{2,A},{4,B}, {1,3}}):

Now you can work with the graph object using other commands in the GraphTheory package. For example, you can display it:

GraphTheory:-DrawGraph(K, style= planar);

You can't (safely) use implied multiplication, and you need parentheses for all function calls. So, you need to change your definition of r to

r:= t-> <4*cos(2*t)+4*sin(t), 5*cos(3*t)+4*cos(t),(sin(3*t)+2*sin(t))^2>;

Then your spacecurve command will work.

I have a vague feeling that I may be missing something important in this discussion (especially since I would've expected Acer to come up with this also), but doesn't the following simple code, which uses no unapply and no quotes, do what you want?

G:= [seq(subs(_u= u, theta-> x-> _u*theta*x), u in [v1,v2])];

Many commands (perhaps most) don't automatically map themselves over container objects such as Vectors, lists, and sets. This can often be achieved by appending ~ to the command name, making it into an elementwise command. In your case, this works:

A:= Vector([1, 2, 3]):
solve~(2*A =~ 5+x);

Note also the use of the in =~. See ?elementwise.

 

 

If you're willing to change Matrix itself, you can perform the operation in place, which saves time, memory, and typing:

A[.., 1]:= b;

Matrix, in addition to being a type, is also a procedure. It's the constructor procedure for matrices that you just used. When you use print, it forces the expansion of the name Matrix into its underlying procedure. You'd get the same thing if you'd executed print(Matrix) at the top level (i.e., outside a procedure). The solution to your problem is to simply not use print. A procedure's return value is simply the result of its last executed statement; there's no need to use print to see a procedure's result. Indeed, it is a bad practice to use print in this way. It should only be used to display supplementary information, not the procedure's return value.

First 234 235 236 237 238 239 240 Last Page 236 of 395