Using pyeda function get the following error - python-3.4

I'am a beginner on Python and i am studying Boolean Algebra, and i was testing this function:
from pyeda.inter import *
list(iter_points([z, y, x]))
[{x: 0, y: 0, z: 0},
{x: 0, y: 0, z: 1},
{x: 0, y: 1, z: 0},
{x: 0, y: 1, z: 1},
{x: 1, y: 0, z: 0},
{x: 1, y: 0, z: 1},
{x: 1, y: 1, z: 0},
{x: 1, y: 1, z: 1}]
i have already install pyeda.
When i execute file I've get the following error:
Traceback (most recent call last):
File "tabela.py", line 3, in
list(iter_points[z, y, x])
NameError: name 'z' is not defined
Any one can help me on this issue?
Thanks i lot guys.
BM

PyEDA author here:
Try this instead:
>>> from pyeda.inter import *
>>> x, y, z = map(exprvar, 'xyz')
>>> list(iter_points([z, y, x]))

x = 0
y = 0
z = 0
print(list(iter_points([z, y, x])))
Also remove the x/y/z list you show here. This is what your result should look like.

Related

rotation matrix with an abritrary rotation point

I need a rotation matrix that rotates a line about an abritrary point (its called center in the below mentioned code). I wrote a scrict but somewhere is a bug.
can you help me?
i put the center coordinates (abritrary center that replaces the origin) in the 4th column of rotational matrice. After plotting the results the line rotates about the axis, going through the origin, further on.
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
f = lambda m,n: n+2*m
A = np.fromfunction(f, (10,3), dtype=int)
def get_rotation_matrix(center, x_rot: float, y_rot: float, z_rot: float, reverse=False):
import numpy as np
import math
cx,sx = math.cos(x_rot),math.sin(x_rot)
cy,sy = math.cos(y_rot),math.sin(y_rot)
cz,sz = math.cos(z_rot),math.sin(z_rot)
Rx = np.array(
[[1, 0, 0, 0],
[0, cx, -sx, 0],
[0, sx, cx, 0],
[0, 0, 0, 1]]
)
Ry = np.array(
[[cy, 0, -sy, 0],
[0, 1, 0, 0],
[sy, 0, cy, 0],
[0, 0, 0, 1]]
)
Rz = np.array(
[[cz, -sz, 0, 0],
[sz, cz, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]]
)
T = np.array(
[[1, 0, 0, center[0]],
[0, 1, 0, center[1]],
[0, 0, 1, center[2]],
[0, 0, 0, 1]]
)
ret = T # Rx # Ry # Rz
print(ret)
At = np.c_[A,np.ones(len(A))]
k = np.dot(At,ret)
print(k.T)
return k #np.linalg.inv(ret) if reverse else ret
theta_x = 5
theta_y = 0
theta_z = 0
k = get_rotation_matrix([0,0,10],theta_x/57.4,theta_y/57.4,theta_z/57.4)
fig = plt.figure(figsize=(12,12))
ax = fig.add_subplot(111,projection='3d')
ax.plot(k[:,0],k[:,1],k[:,2])
ax.plot(A[:,0],A[:,1],A[:,2])
plt.show()

How to visualize a torch_geometric graph in Python?

Let's consider as an example that I have the following adjacence matrix in coordinate format:
> edge_index.numpy() = array([[ 0, 1, 0, 3, 2],
[ 1, 0, 3, 2, 1]], dtype=int64)
which means that the node 0 is linked toward the node 1, and vice-versa, the node 0 is linked to 3 etc...
Do you know a way to draw this graph as in networkx with nx.draw() ?
Thank you.
import networkx as nx
edge_index = torch.tensor([[0, 1, 1, 2],
[1, 0, 2, 1]], dtype=torch.long)
x = torch.tensor([[-1], [0], [1]], dtype=torch.float)
data = torch_geometric.data.Data(x=x, edge_index=edge_index)
g = torch_geometric.utils.to_networkx(data, to_undirected=True)
nx.draw(g)

Disk inside plot in mathematica

I have a question about using plot and disk together in one manipulate function in mathematica.
I have this piece of code right now:
Plot[h[t], {t, 0, ttot}, PlotRange -> {0, 30}]
Manipulate[
Plot[
h0 + v0*t - 1/2*g*(t)^2, {t, 0, 10},
PlotRange -> {{-1, 8}, {0, 11.5}}
],
{t, 0, ttot, 0.001}, {m, 0.001, 0.1, 0.001, ImageSize -> Tiny}, {v0,
0, 5, 0.01, ImageSize -> Tiny}, {h0, 0, 10, 0.01, ImageSize -> Tiny}
]
What I want to do is display a disk inside the plot representing a flying object (its position is on the curve, according to actual time and height). How do I do it?
You should show the definitions of the symbols you use : h[t], v0, ttot etc.
My understanding of what you are after :
trajectory[p0_, v0_, a_, t_] = p0 + v0 t - 1/2 a t^2;
x0 = 3;
v0y = 1;
g = 9.81;
ttot = 3;
Manipulate[ParametricPlot[trajectory[{x0, h0}, {v0x, v0y}, {0, g}, t], {t, 0, ttot}, Epilog -> {Disk[trajectory[{x0, h0}, {v0x, v0y}, {0, g}, tcurrent], 0.5]}, PlotRange -> All], {v0x, 0, 5, 0.01}, {h0, 0, 10, 0.01}, {tcurrent, 0, ttot, 0.01}]

"3d Grid" Inside the Box in Graphics3D

Please Consider :
cAxes = {{{0, 0, 0}, {0, 0, 1}}, {{0, 0, 0}, {0, 1, 0}}, {{0, 0,0}, {1, 0, 0}}};
Graphics3D[{Line /# cAxes}, Boxed -> False]
Is it possible to have Grids inside the Box ? I guess "3D Grid"
Here is a reworked version of what I believe Verbeia was attempting:
cAxes = {{{0, 0, 0}, {0, 0, 1}}, {{0, 0, 0}, {0, 1, 0}}, {{0, 0,
0}, {1, 0, 0}}};
a = Graphics3D[{Line /# cAxes}, Boxed -> False];
b = Graphics3D[{
GrayLevel[0.5],
Table[Line /# {{{x, y, 0}, {x, y, 1}},
{{x, 0, y}, {x, 1, y}},
{{0, x, y}, {1, x, y}}},
{x, 0, 1, 0.25},
{y, 0, 1, 0.25}
]
}];
Show[a, b]

Upgrade from Mathematica 5 to Mathematica 7

I am trying to upgrade some equations that currently are written against Mathematica 5 to get them to work in Mathematica 7.
F = Graphics[
ContourPlot[
x^2 + (2)*y^2 + (-1)*((1)/(3))*x, {x, -1, 1}, {y, -1, 1},
ContourShading -> False, ContourStyle -> {RGBColor[1, 0, 1]},
Contours -> 20, PlotPoints -> 100]];
G = ParametricPlot[{Cos[u], Sin[u]}, {u, 0, 2*Pi},
PlotStyle -> {RGBColor[0, 174/255, 239/255]}];
H = DeleteCases[F, {x_, y_} /; (x^2 + y^2 > 1), 5];
Show[{H, G}, AspectRatio -> Automatic, Frame -> False, Axes -> True,
AxesOrigin -> {0, 0}, AxesLabel -> {x, y}, Ticks -> None]
It should look like this:
, but id does look like this:
and it gives the following error:
Thread::tdlen: Objects of unequal length in
{{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}}+{{},<<21>>,{}}
cannot be combined. >>
and if you hover over the image you get the following in a tooltip:
The specified setting for the option GraphicsBoxOptions, PlotRange cannot be used.
Coordinate index X is out of range for the enclosing GraphicsComplex
there are a lot of those Coordinate ones all with different coordinates.
And the second one I'm having difficulty with is:
P1 = {{(5)/10*Cos[u]*Cos[v], (5)/10*Sin[u]*Cos[v], (5)/10*Sin[v]}, {u,
0, 2*Pi}, {v, -Pi/2, Pi/2}};
P2 = {{(5)/10*Cos[u], 0, (5)/10*Sin[u]}, {u, 0, 2*Pi}};
P3 = {{(5)/10*Cos[u], (5)/10*Sin[u], 0}, {u, 0, 2*Pi}};
P4 = {{0, (5)/10*Cos[u], (5)/10*Sin[u]}, {u, 0, 2*Pi}};
U = {P1, P2, P3, P4};
XL = {{-1, 1}, {-1, 1}, {-1, 1}};
XV = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
XS = {"x", "y", "z"};
f[a_, b_, c_] := {a, 1.1*b[[2]]*c};
g[a_, b_] := {(b*# &) /# a};
T = Text ### MapThread[f, {XS, XL, XV}];
A = Line ### MapThread[g, {XL, XV}];
F = (ParametricPlot3D[Evaluate[Evaluate ## #]][[1]] &) /# U;
OPT = {Boxed -> False, Axes -> False, BoxRatios -> {1, 1, 1}, PlotRange -> XL,
ViewPoint -> {2.4, 1.3, 2},
DisplayFunction ->
Identity};
L = {LightSources -> {{{0.1, 0, 1}, RGBColor[0.68, 0.88, 0.96]}}};
gr1 = (Show[Graphics3D[#], OPT, L] &) /# {{EdgeForm[], F}, {Dashing[{0.03, 0.03}],
GrayLevel[0.7], A}, {T}};
gr2 = DeleteCases[Graphics[Show[Graphics3D[{A, EdgeForm[], F}], OPT,
RenderAll -> False]], {__, _Polygon}, 3];
Show[{gr1, gr2}, AspectRatio -> Automatic]
This one should look like: , but does look like:
which and it gives these errors:
ParametricPlot3D::write: Tag Plus in x^2+y^2 is Protected. >>
Graphics3D::optx : Unknown option RenderAll
Graphics3D::optx : Unknown option LightSources
If I then remove the Unknown options, those errors disappear but it still looks wrong:
Also, if you hover over the last image in mathematica you get the following message repeated several times in a tooltip
Times is not a Graphics3D primitive or directive
Second one, great circles partly hidden, axes partly dashed:
r = 1.01/2; d = 1/(100 r);
v1 = Riffle[
Table[r { Cos[\[Phi]], Sin[\[Phi]], -d}, {\[Phi], 0, 2 \[Pi], (
2 \[Pi])/40.}],
Table[r { Cos[\[Phi]], Sin[\[Phi]], d}, {\[Phi], 0, 2 \[Pi], (
2 \[Pi])/40.}]];
v2 = Riffle[
Table[-r { Cos[\[Phi]], -d, Sin[\[Phi]]}, {\[Phi], 0, 2 \[Pi], (
2 \[Pi])/40.}],
Table[-r { Cos[\[Phi]], d, Sin[\[Phi]]}, {\[Phi], 0, 2 \[Pi], (
2 \[Pi])/40.}]];
v3 = Riffle[
Table[r { -d, Cos[\[Phi]], Sin[\[Phi]]}, {\[Phi], 0, 2 \[Pi], (
2 \[Pi])/40.}],
Table[r { d, Cos[\[Phi]], Sin[\[Phi]]}, {\[Phi], 0, 2 \[Pi], (
2 \[Pi])/40.}]];
lx = {{{1, 0, 0}, {2, 0, 0}}}/2;
ly = {{{0, 1, 0}, {0, 2, 0}}}/2;
lz = {{{0, 0, 1}, {0, 0, 2}}}/2;
A2 = Line ### {lx, ly, lz, -lx, -ly, -lz};
Graphics3D[
{
FaceForm[None, Black], EdgeForm[],
GraphicsComplex[#,
Table[Polygon[Mod[{i, i + 1, i + 3, i + 2}, Length[v], 1]], {i,
1, Length[v] - 1, 2}]] & /# {v1, v2, v3}, {Opacity[0.75],
RGBColor[0.68`, 0.88`, 0.96`], Sphere[{0, 0, 0}, 1/2]},
{Dashing[{0.02, 0.02}], Black, A}, T, A2
},
Boxed -> False,
Lighting -> {{"Directional", RGBColor[0.68`, 0.88`, 0.96`],
ImageScaled#{0.1, 0, 1}}}, BoxRatios -> {1, 1, 1},
PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}},
BaseStyle -> FontSize -> 14, ViewPoint -> {2.4`, 1.3`, 2},
ViewVertical -> {0, 0, 1}
]
It is a little hard to tell from the picture what you want for the second graphic. Please try this and tell me what is right and what is lacking.
P1 = {{(5)/10*Cos[u]*Cos[v], (5)/10*Sin[u]*Cos[v], (5)/10*Sin[v]}, {u,
0, 2*Pi}, {v, -Pi/2, Pi/2}};
P2 = {{(5)/10*Cos[u], 0, (5)/10*Sin[u]}, {u, 0, 2*Pi}};
P3 = {{(5)/10*Cos[u], (5)/10*Sin[u], 0}, {u, 0, 2*Pi}};
P4 = {{0, (5)/10*Cos[u], (5)/10*Sin[u]}, {u, 0, 2*Pi}};
U = {P1, P2, P3, P4};
XL = {{-1, 1}, {-1, 1}, {-1, 1}};
XV = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
XS = {"x", "y", "z"};
f[a_, b_, c_] := {a, 1.1*b[[2]]*c};
g[a_, b_] := {(b*# &) /# a};
T = Text ### MapThread[f, {XS, XL, XV}];
A = Line ### MapThread[g, {XL, XV}];
F = ParametricPlot3D[##, Mesh -> False][[1]] & ### U;
OPT = {Boxed -> False, Axes -> False, BoxRatios -> {1, 1, 1},
PlotRange -> XL, ViewPoint -> {2.4, 1.3, 2}};
L = Lighting -> {{"Directional",
RGBColor[0.68, 0.88, 0.96], {{5, 5, 4}, {5, 5, 0}}}};
gr1 = Graphics3D[#, OPT, L] & /# {{Opacity[0.5], F},
{Dashing[{0.03, 0.03}], GrayLevel[0.7], A},
{T}};
Show[gr1]
Here is another take that may be closer to the original. You lose the v7 ability to rotate the graphic with this.
gr1 = Rasterize[Graphics3D[#, OPT, L],
Background -> None] & /# {F, {Dashing[{0.03, 0.03}],
GrayLevel[0.7], A}, T};
Show[gr1]
First one:
ContourPlot[x^2 + (2)*y^2 + (-1)*((1)/(3))*x, {x, -1, 1}, {y, -1, 1},
ContourShading -> False, ContourStyle -> {RGBColor[1, 0, 1]},
Contours -> 20, RegionFunction -> (#1^2 + #2^2 <= 1 &),
BoundaryStyle -> Blue]
[Edit]
Second one, using the given values for A and T:
Show[
ParametricPlot3D[{(5)/10*Cos[u]*Cos[v], (5)/10*Sin[u]*Cos[v], (5)/10*
Sin[v]}, {u, 0, 2*Pi}, {v, -Pi/2, Pi/2},
MeshFunctions -> {#1 &, #2 &, #3 &}, PlotStyle -> Opacity[0.75],
Mesh -> {{0}, {0}, {0}}, MeshStyle -> Black, BoundaryStyle -> Black,
Boxed -> False, Axes -> False, BoxRatios -> {1, 1, 1},
PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}},
ViewPoint -> {2.4`, 1.3`, 2},
Lighting -> {{"Directional", RGBColor[0.68`, 0.88`, 0.96`],
ImageScaled#{0.1, 0, 1}}}],
Graphics3D[{{Dashing[{0.03, 0.03}], Black, A}, {T}}]
]
I think the axes will need to be done as separate interior/exterior segments.
The great circles show through in this version; preventing that will require drawn partial curves instead of mesh lines, if that's required.

Resources