plot vertical line with DO - printing

i try to plot the result of this code as vertical line each one in the position of the solution of the FindRoot routine (something like that: http://www.astrobio.net/albums/xsolar/ach.sized.jpg ).
omega[a_] := 2 \[Pi] /a^(3/2);
Do[
Print[FindRoot[omega[a]/omega[5.2]==j/i+1, {a, 1}]],
{j,1,7,1},{i,1,7,1}]
Can someone help me please?

I'm part guessing, because your question isn't clear enough:
omega[a_] := 2 Pi/a^(3/2);
ListPlot[Flatten[
Table[{a /. FindRoot[omega[a]/omega[5.2] == j/i + 1, {a, 1}], i + j},
{j, 1, 7, 1}, {i, 1, 7, 1}], 1],
Filling -> Axis, PlotRange -> {{0, 6}, {0, 15}}]

Related

Erlang List Comprehension of Cartesian Product

I'm learning Erlang and have come across/trying to understand list comprehension. I've discovered that you can make Cartesian products quite easily using it.
Basically I though of a deck of cards and that if you multiply the unique values by the number of suits, you will result will every possible combination - creating a full deck of cards. However, what if I wish to add the 2 jokers to the deck - but jokers do not belong to a suit. How do we solve that issue?
The code below is what I have so far and will output the possible combinations without the jokers.
CardValues = [ace, king, queen, jack, 10, 9, 8, 7, 6, 5, 4, 3, 2],
CardSuits = [spades,hearts,clubs,diamonds],
CartesianList = [{X, Y} || X <- CardValues, Y <- CardSuits ],
io:format("\nCartesianList:~p\n",[CartesianList]).
Would there be a better way of achieving/how would you achieve this?
I expect the output for the jokers would be something like {joker, nosuit}
Thanks,
Snelly.
If you really want to get it directly from a list comprehension, you may use filters:
CardValues = [joker,joker,ace, king, queen, jack, 10, 9, 8, 7, 6, 5, 4, 3, 2],
CardSuits = [spades,hearts,clubs,diamonds,nosuit],
CartesianList = [{X, Y} || X <- CardValues, Y <- CardSuits, ((X == joker)andalso(Y==nosuit))orelse((X =/= joker)andalso(Y=/=nosuit)) ],
io:format("\nCartesianList:~p\n",[CartesianList]).
But it is really weird, artificial and inefficient, I would add them manually:
CardValues = [ace, king, queen, jack, 10, 9, 8, 7, 6, 5, 4, 3, 2],
CardSuits = [spades,hearts,clubs,diamonds],
CartesianList = [{joker,nosuit},{joker,nosuit}|[{X, Y} || X <- CardValues, Y <- CardSuits ]]],
io:format("\nCartesianList:~p\n",[CartesianList]).

How to get a list of integers from a given set of possible integers in z3?

Minimal example is the following: Given a set of possible integers [1, 2, 3] create an arbitrary list of size 5 using z3py. Duplicates are allowed.
The expected result is something like [1, 1, 1, 1, 1] or [3, 1, 2, 2, 3], etc.
How to tackle this problem and how to implement 'choosing'? Finally, I would like to find all solutions which can be done by adding additional constraints as explained in link. Any help will be very appreciated.
The following should work:
from z3 import *
def choose(elts, acceptable):
s = Solver()
s.add(And([Or([x == v for v in acceptable]) for x in Ints(elts)]))
models = []
while s.check() == sat:
m = s.model ()
if not m:
break
models.append(m)
block = Not(And([v() == m[v] for v in m]))
s.add(block)
return models
print choose('a b c d e', [1, 2, 3])

Automate creation of large symbolic matrix

Can this matrix be generated in a less manual way? It's okay for 4 x 4, but I need something larger. Thanks
--> L : matrix([L11,L12,L13,L14],[L21,L22,L23,L24],[L31,L32,L33,L34],[L41,L42,L43,L44]);
(L) matrix(
[L11, L12, L13, L14],
[L21, L22, L23, L24],
[L31, L32, L33, L34],
[L41, L42, L43, L44]
)
Answer to the question and note the noun form for L in the concat function ('L)
L:genmatrix(lambda([i,j], concat('L,i,j)), 3, 3);
(L) matrix(
[L11, L12, L13],
[L21, L22, L23],
[L31, L32, L33]
)
For a diagonal matrix
R:genmatrix(lambda([i,j], if i=j then concat('R,i) else 0), 3, 3);
(R) matrix(
[R1, 0, 0],
[0, R2, 0],
[0, 0, R3]
)

Finding the nullity and nullspace in Maxima

I was trying to get the nullity and kernel of a matrix over the complex field in Maxima.
I get strange results, though.
I can define a matrix A:
M : matrix([0, 1, 1, 0], [-1, 0, 0, 1], [0, 0, 0, 1], [0, 0, -1, 0]);
A : M + %i * ident(4);
... for reference, it looks like this:
%i 1 1 0
-1 %i 0 1
0 0 %i 1
0 0 -1 %i
If I then compute the nullity with nullity(A), I get 3.
If I compute the rank with rank(A), I also get 3.
And if I compute the nullspace with nullspace(A), I get:
span([-1, %i, 0, 0], [-%i, -1, 0, 0], [2%i, 2, 0, 0])
But this is pretty weird, because -%i * second(...) is [-1, %i, 0, 0], which is the first vector.
And indeed, when I do NullSpace[{{i, 1, 1, 0}, {-1, i, 0, 1}, {0, 0, i, 1}, {0, 0, -1, i}}] in Mathematica, I get that the nullspace has basis [%i, 1, 0, 0] and is 1-dimensional (not 3-dimensional).
What am I doing wrong?
You are doing everything right, as far as I can tell. The problem is a bug in Maxima, which I have reported: https://sourceforge.net/p/maxima/bugs/3158/
I don't see any simple way to work around it. I am working on fixing the bug.

How to convert datetime() to timestamp() in Erlang/OTP?

I need to convert {{2012, 9, 21}, {13, 21, 11}} into timestamp().
How can I do that?
Corrected version:
Seconds = calendar:datetime_to_gregorian_seconds(DateTime) - 62167219200,
%% 62167219200 == calendar:datetime_to_gregorian_seconds({{1970, 1, 1}, {0, 0, 0}})
{Seconds div 1000000, Seconds rem 1000000, 0}.
You might use this
to_timestamp({{Year,Month,Day},{Hours,Minutes,Seconds}}) ->
(calendar:datetime_to_gregorian_seconds(
{{Year,Month,Day},{Hours,Minutes,Seconds}}
) - 62167219200)*1000000;
This is part of module from this
Github/Arboreus

Resources