Carl Love

Carl Love

24830 Reputation

25 Badges

10 years, 115 days
Natick, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love


cos(3*x) = 13/14:

expand(%);

4*cos(x)^3-3*cos(x) = 13/14

sol:= [solve](%, cos(x)):

simplify(fnormal(evalf(sol -~ cos(arccos(13/14)/3))), zero);

[0., -1.59744226005789, -1.37849148916767]

So the first root returned by solve is the one we want. So the final answer is

cos(arccos(13/14)/3) = sol[1];

cos((1/3)*arccos(13/14)) = (1/28)*(2548+(588*I)*3^(1/2))^(1/3)+7/(2548+(588*I)*3^(1/2))^(1/3)

 


Download trigrad1314.mw

I made a minor change to deal with some of the long display labels. Here's a repost of the worksheet with the new code and some new examples. As for colored labels, I think something may be possible along those lines: colors (and other formatting information) can be encoded into names. I'll think about it.

FunctionToTree

Carl Love 23-Mar-2013

 

A module to convert a function tree representation (such as is returned by ToInert or by various commands in XMLtools) into a tree represented in the GraphTheory package

restart;

 

(* Written by Carl Love, 23-Mar-2013.

module () description "Convert a function tree to a GraphTheory tree."; local Vertices::table, VertexLabels::table, Vertex_index::nonnegint, Edges::table, AddEdge, AddVertex, AddSubTree, Prefix::nonnegint, Labels::table, StripName, NameVertices, ModuleInits, ModuleApply; export Legend::table; end module

Example 1

F:= ToInert(x+2*y*z^2);

_Inert_SUM(_Inert_PROD(_Inert_PROD(_Inert_NAME("y"), _Inert_POWER(_Inert_NAME("z"), _Inert_INTPOS(2))), _Inert_INTPOS(2)), _Inert_NAME("x"))

I came up with a scheme to abbreviate the vertex labels. In the line below, you need to map the second part of the _Inert_ function names to displayable labels. Note that the display label can be the empty symbol ``, which is useful for the leaf nodes, whose first operand becomes part of the label. Also note that this table must map strings (things in double quotes) to symbols (things in single backquotes).

Abbrs:= table([
   "SUM"= `+`, "PROD"= `*`, "POWER"= `^`,
   "EQUATION"= `=`, "EXPSEQ"= `,`, "RANGE"= `..`,
   "INTPOS"= ``, "NAME"= ``, "ASSIGNEDNAME"= ``,
   "FUNCTION"= Func
]):

The Prefix= 7 argument tells it to strip off the first 7 characters of each function name.

G:= FunctionToTree(F, Labels= Abbrs, Prefix= 7);

GRAPHLN(directed, unweighted, [`*`, `*`, `+`, `2`, `2`, `^`, x, y, z], Array(%id = 18446744073901591718), `GRAPHLN/table/48`, 0)

For any given tree, it's hard to say which command of DrawNetwork or DrawGraph will display it better. Neither is great.

GraphTheory:-DrawNetwork(G);

Note that the edge from `*` to x is partially obscured by the edge from `*` to  `^`, which makes it look like there is an edge from `^` to x. You can tell that there isn't by looking for the arrows.

 

The circular presentation of  DrawGraph ensures against obscures edges, but it looks less tree-like.

GraphTheory:-DrawGraph(G);

The module exports a table Legend that shows the correspondence between the vertex labels and the original functional representation.

eval(FunctionToTree:-Legend);

table( [( `+` ) = _Inert_SUM(_Inert_PROD(_Inert_PROD(_Inert_NAME("y"), _Inert_POWER(_Inert_NAME("z"), _Inert_INTPOS(2))), _Inert_INTPOS(2)), _Inert_NAME("x")), ( z ) = _Inert_NAME("z"), ( `*` ) = _Inert_PROD(_Inert_PROD(_Inert_NAME("y"), _Inert_POWER(_Inert_NAME("z"), _Inert_INTPOS(2))), _Inert_INTPOS(2)), ( y ) = _Inert_NAME("y"), ( x ) = _Inert_NAME("x"), ( `*` ) = _Inert_PROD(_Inert_NAME("y"), _Inert_POWER(_Inert_NAME("z"), _Inert_INTPOS(2))), ( `2` ) = _Inert_INTPOS(2), ( `2` ) = _Inert_INTPOS(2), ( `^` ) = _Inert_POWER(_Inert_NAME("z"), _Inert_INTPOS(2)) ] )

These can be converted to their original expressional forms:

FromInert ~ (%);

table( [( `+` ) = 2*y*z^2+x, ( z ) = z, ( `*` ) = 2*y*z^2, ( y ) = y, ( x ) = x, ( `*` ) = y*z^2, ( `2` ) = 2, ( `2` ) = 2, ( `^` ) = z^2 ] )

Example 2

F:= ToInert([1,2,3,4]);

_Inert_LIST(_Inert_EXPSEQ(_Inert_INTPOS(1), _Inert_INTPOS(2), _Inert_INTPOS(3), _Inert_INTPOS(4)))

G2:= FunctionToTree(F, Labels= Abbrs, Prefix= 7);

GRAPHLN(directed, unweighted, [`,`, `1`, `2`, `3`, `4`, LIST], Array(%id = 18446744073901597270), `GRAPHLN/table/53`, 0)

GraphTheory:-DrawNetwork(G2);

eval(FunctionToTree:-Legend);

table( [( `,` ) = _Inert_EXPSEQ(_Inert_INTPOS(1), _Inert_INTPOS(2), _Inert_INTPOS(3), _Inert_INTPOS(4)), ( `4` ) = _Inert_INTPOS(4), ( `1` ) = _Inert_INTPOS(1), ( `3` ) = _Inert_INTPOS(3), ( `2` ) = _Inert_INTPOS(2), ( LIST ) = _Inert_LIST(_Inert_EXPSEQ(_Inert_INTPOS(1), _Inert_INTPOS(2), _Inert_INTPOS(3), _Inert_INTPOS(4))) ] )

FromInert ~ (%);

table( [( `,` ) = 1, 2, 3, 4, ( `4` ) = 4, ( `1` ) = 1, ( `3` ) = 3, ( `2` ) = 2, ( LIST ) = [1, 2, 3, 4] ] )

Example 3

J:= Int(x, x= 0..1);

Int(x, x = 0 .. 1)

F:= ToInert(J);

_Inert_FUNCTION(_Inert_NAME("Int", _Inert_ATTRIBUTE(_Inert_EXPSEQ(_Inert_NAME("protected", _Inert_ATTRIBUTE(_Inert_NAME("protected"))), _Inert_NAME("_syslib")))), _Inert_EXPSEQ(_Inert_NAME("x"), _Inert_EQUATION(_Inert_NAME("x"), _Inert_RANGE(_Inert_INTPOS(0), _Inert_INTPOS(1)))))

G3:= FunctionToTree(F, Labels= Abbrs, Prefix= 7);

GRAPHLN(directed, unweighted, [`,`, `..`, `0`, `1`, `=`, Func, Int, x, x], Array(%id = 18446744073901600270), `GRAPHLN/table/56`, 0)

GraphTheory:-DrawGraph(G3);

GraphTheory:-DrawNetwork(G3);

eval(FunctionToTree:-Legend);

table( [( `,` ) = _Inert_EXPSEQ(_Inert_NAME("x"), _Inert_EQUATION(_Inert_NAME("x"), _Inert_RANGE(_Inert_INTPOS(0), _Inert_INTPOS(1)))), ( `..` ) = _Inert_RANGE(_Inert_INTPOS(0), _Inert_INTPOS(1)), ( x ) = _Inert_NAME("x"), ( `1` ) = _Inert_INTPOS(1), ( `=` ) = _Inert_EQUATION(_Inert_NAME("x"), _Inert_RANGE(_Inert_INTPOS(0), _Inert_INTPOS(1))), ( x ) = _Inert_NAME("x"), ( Int ) = _Inert_NAME("Int", _Inert_ATTRIBUTE(_Inert_EXPSEQ(_Inert_NAME("protected", _Inert_ATTRIBUTE(_Inert_NAME("protected"))), _Inert_NAME("_syslib")))), ( `0` ) = _Inert_INTPOS(0), ( Func ) = _Inert_FUNCTION(_Inert_NAME("Int", _Inert_ATTRIBUTE(_Inert_EXPSEQ(_Inert_NAME("protected", _Inert_ATTRIBUTE(_Inert_NAME("protected"))), _Inert_NAME("_syslib")))), _Inert_EXPSEQ(_Inert_NAME("x"), _Inert_EQUATION(_Inert_NAME("x"), _Inert_RANGE(_Inert_INTPOS(0), _Inert_INTPOS(1))))) ] )

FromInert ~ (%);

table( [( `,` ) = x, x = 0 .. 1, ( `..` ) = 0 .. 1, ( x ) = x, ( `1` ) = 1, ( `=` ) = x = 0 .. 1, ( x ) = x, ( Int ) = Int, ( `0` ) = 0, ( Func ) = Int(x, x = 0 .. 1) ] )

Example 4

F:= cos(x+2*y)^2+1;

cos(x+2*y)^2+1

F:= ToInert(F);

_Inert_SUM(_Inert_POWER(_Inert_FUNCTION(_Inert_ASSIGNEDNAME("cos", "PROC", _Inert_ATTRIBUTE(_Inert_EXPSEQ(_Inert_NAME("protected", _Inert_ATTRIBUTE(_Inert_NAME("protected"))), _Inert_NAME("_syslib")))), _Inert_EXPSEQ(_Inert_SUM(_Inert_NAME("x"), _Inert_PROD(_Inert_NAME("y"), _Inert_INTPOS(2))))), _Inert_INTPOS(2)), _Inert_INTPOS(1))

G4:= FunctionToTree(F, Labels= Abbrs, Prefix= 7);

GRAPHLN(directed, unweighted, [`*`, `+`, `+`, `,`, `1`, `2`, `2`, Func, `^`, cos, x, y], Array(%id = 18446744073901605462), `GRAPHLN/table/61`, 0)

GraphTheory:-DrawGraph(G4);

GraphTheory:-DrawNetwork(G4);

FromInert ~ (FunctionToTree:-Legend);

table( [( cos ) = cos, ( `+` ) = cos(x+2*y)^2+1, ( `,` ) = x+2*y, ( `*` ) = 2*y, ( y ) = y, ( `1` ) = 1, ( x ) = x, ( `+` ) = x+2*y, ( `2` ) = 2, ( `^` ) = cos(x+2*y)^2, ( `2` ) = 2, ( Func ) = cos(x+2*y) ] )

 


Download FunctionTree.mw

Your expression for the integrand has unbalanced parentheses. I think you're missing a left parenthesis "(" at the very beginning. Once you repost a correction, I might be able to help you more. But I think that it's unlikely that you will get a symbolic answer.

The command is plots:-listcontplot(M, contours= [$1..20]). But you need to lay out your points in a grid form, which involves some sorting and approximating. I vaguely recall seeing a tool for this a many years ago. I will look for it.

Does the error occur in CalculateMatrix or after? Put a print statement after the CalculateMatrix call to find out.

It is a system of linear equations. It would be much more efficient to solve it with matrix operations (i.e. LinearAlgebra:-LinearSolve). Would a floating-point solution be acceptable? That would use much less memory.

You can convert the arrows, or anything else, to Cartesian coordinates, and put them on a polar plot like this:

 

N:= 12:

magnitude:= RandomTools:-Generate(list(float(range= 0..1, method= uniform), N)):

phase:= RandomTools:-Generate(list(float(range= 0..360, method= uniform), N)):

A:= < < magnitude[] > | < phase[] > >:

ExcelTools:-Export(A, "C:/Users/Carl/desktop/data.xls"):

A:= convert(ExcelTools:-Import("C:/Users/Carl/desktop/data.xls"), Matrix):

Convert to radians:

A[.., 2]:= evalf(Pi)/180 *~ A[.., 2]:

Polar to Cartesian converter:

xy:= P-> < P[1]*cos(P[2]), P[1]*sin(P[2]) >:

p1:= plots:-arrow([seq](xy(A[k,..]), k= 1..N), shape= arrow, color= red):

Dummy plot to give us the polar background:

p2:= plots:-polarplot(1.1*max(A[.., 1]), color= white, transparency= 1):

plots:-display(p1,p2);


Download polarplot.mw

Use Sum (with a capital S), instead of sum, and you will get the answer that you expect.

I have no idea what that escaped variable _O and the rest of that huge mess represents. Surely the result of differentiating the lowercase sum is a bug. However, I will note that the fault lies with sum, not diff, because you get a nearly identical mess if you just do the derivative in your head and enter

sum(sin(theta[j](t))*cos(theta[j](t))*diff(theta[j](t), t), j= 1..i-1);

It looks like your Alphabet is shifted by one. I get "Y"=58, "e"=70, "s"=84. Regardless of that, the encryption steps are the same. The essential command is the inert modular exponentiation operator x &^ e mod n. I also did the decryption, partly for to verify the encryption and partly for my own amusement.

with(StringTools):
Alphabet:=cat(Select(IsPrintable,convert([seq(i,i=1..255)],bytes))):
AlphaToNum:= table([seq](Alphabet[k] = k, k= 1..length(Alphabet))):
plaintext:= "Yes":
NumText:= [seq](AlphaToNum[c], c in plaintext);
                          [58, 70, 84]
n, e:= 119, 7:
Crypted:= (c-> c &^ e mod n) ~ (NumText);
                         [114, 77, 84]
To decrypt:
f:= ifactor(n);
                            (7) (17)
phi:= expand(map(x-> x-1, f));
                               96
d:= 1/e mod phi;
                               55
Decrypted:= (c-> c &^ d mod n) ~ (Crypted);
                          [58, 70, 84]
cat(seq(Alphabet[k], k in Decrypted));
                             "Yes"

Save your file in Excel. I think as a CSV file would be best (Comma-Separated Values). Then in Maple, give the command ImportData(); and follow the dialog. Once you get that done, post a followup to this, and we can proceed with the plotting. Also post a followup if you have any trouble with the dialog.

mrmathexpert wrote:

How can I control the specific regions that I want to highlight? For example, from pi/2 to 3pi/2: outside or the left side of the y-axis bounded; and from 3pi/2 to pi/2, outside or the right side of the y-axis bounded.

You can do the left side and the right side separately, each side consisting of two polarplot commands, and paste all four together with display. I'm not sure if this is what you were trying to describe:

p1:= plots:-polarplot(2+cos(x), x= -Pi/2..Pi/2, color= red, filled= [color= yellow]):
p2:= plots:-polarplot(2+cos(x), x= Pi/2..3*Pi/2, color= red, filled= [color= white]):
p3:= plots:-polarplot(2, x= Pi/2..3*Pi/2, color= blue, filled= [color= yellow]):
p4:= plots:-polarplot(2, x= -Pi/2..Pi/2, color= blue, filled= [color= white]):
plots:-display([p4,p2,p3,p1]);

Download polarplot.mw

Note that the order of the plots in the display command matters: They are printed in the reverse of the order that they appear in the command. I don't think this is documented.

GraphTheory:-Graph vertices need to be integers, symbols, or strings; arbitrary expressions are not allowed. So 2, `*`, function, cos, y, and z are valid; but 2*y, 3*z, and cos(x+2*y) are not.

The command that you want is subsindets (or possibly evalindets). Here's an appropriate analogy: subsindets is to indets as applyop is to op.

I think you should collect like terms with respect to the integrals, like this

collect(eq2, Int);

so that each specific integrand only occurs once.

Tell me exactly which integrands you are trying to select. You said "like" phi[i](y)*diff(w(y), y). Do you mean exactly that integrand? Or would phi[i](y)*diff(w(y), y)^2 also count as "like"?

Once you answer that, I can give you a type specification that you can use with subsindets.

Assuming that those square brackets are really there (which I find a bit strange), the command is

(op@eval)(w1(x), op ~ ([sol]));

and likewise for w2(x).

If the square brackets are not actually there, then change (op@eval) to simply eval in the above command.

If the square brackets are really there, you should post the commands that got you to that point, because there may be something wrong.

There must have been a syntax change between Maple 13 and Maple 17 that I am not aware of. So sorry about this. Try this please: Make your first command

kernelopts(opaquemodules= false);

I am not sure that will work.

Joe Riel (or any expert who can answer): Was it once true that only module exports could be accessed with thismodule, but now locals can be accessed thus also? Also, were keyword parameters introduced after MAPLE 13?

 

restart;

macro(RV= Statistics:-RandomVariable, P= Statistics:-Probability, N= Normal):

x:= RV(N(6.05, sqrt(.0004/9))):

P(x < 6.035);

HFloat(0.01222447265504615)

Z:= RV(N(0,1)):

P(Z < -2.25);

HFloat(0.012224472655044694)

 

Download StatsZ.mw

First 348 349 350 351 352 353 354 Last Page 350 of 363