Community RSS Feed
https://community.wolfram.com
RSS Feed for Wolfram Community showing any discussions from all groups sorted by activeExact and approximate fluxonium array modes
https://community.wolfram.com/groups/-/m/t/3277880
![enter image description here][1]
&[Wolfram Notebook][2]
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=2661Main19092024.png&userId=20103
[2]: https://www.wolframcloud.com/obj/b1ecd1ea-d73f-4f1b-b38f-685017f6eb87Stephen Sorokanich2024-09-19T19:50:40Z[WSG24] Daily Study Group: Elementary Introduction to Wolfram Language
https://community.wolfram.com/groups/-/m/t/3270548
![enter image description here][1]
A Wolfram U Daily Study Group on Elementary Introduction to Wolfram Language begins on Monday, September 16.
Join me and [Eryn Gillam][2] and a group of fellow learners to learn about programming in Wolfram Language. Our topics for the study group include list manipulation, using and making functions, using dynamic functionality, and working with images, sounds, shapes, and colors.
No prior Wolfram Language experience is required.
Please feel free to use this thread to collaborate and share ideas, materials and links to other resources with fellow learners.
#Dates and Times:#
September 16th-October 4th,
11am-12pm CT (4-5pm GMT)
#[Register Here][3]#
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=wolframubanner.jpeg&userId=1835305
[2]: https://community.wolfram.com/web/eryng
[3]: https://www.bigmarker.com/series/an-elementary-introduction-to-wl-wsg57/series_details?utm_bmcr_source=communityRory Foulger2024-09-09T17:24:27ZMathematical Games: ordering and canonical forms
https://community.wolfram.com/groups/-/m/t/3277858
![Mathematical Games: ordering and canonical forms][1]
&[Wolfram Notebook][2]
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=10404Main19092024.png&userId=20103
[2]: https://www.wolframcloud.com/obj/60f7ec51-dad7-40e0-aeb0-c9ad70b93459Ed Pegg2024-09-19T18:47:51ZConstraints on patterns with a pure function with two parameters
https://community.wolfram.com/groups/-/m/t/3277817
This question arised after reading the almost-last example appearing in the technote on Patterns, in section [Putting Constraints on Patterns][1].
Why the following function doesn't work?
q[x_Integer, y_Integer?(Function[{v, u}, v + u < 8])] := qp[x + y]
That is, I want the function `q` to be evaluated only if `x+y<8`, by using a pure function, so that, for example,
{q[{3, 4}], q[{1, 1}], q[{-5, -7}]}
would return
(*{qp[7],qp[2],q[{-5,-7}]}*)
Note that the following works:
q[{x_Integer, y_Integer}?(Function[v, v[[1]] + v[[2]] < 8])] := qp[x + y]
But I want the function `q` to accept two separate arguments `x` and `y`, and not a list of two arguments `{x,y}`.
[1]: https://reference.wolfram.com/language/tutorial/Patterns.html#1615Ehud Behar2024-09-19T15:35:57ZCSockets and LTP: Creating custom communication protocol
https://community.wolfram.com/groups/-/m/t/3277715
![enter image description here][1]
&[Wolfram Notebook][2]
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Main19092024.png&userId=20103
[2]: https://www.wolframcloud.com/obj/4f3e5b7e-e1ee-4e54-9f83-498f89fbbeefKirill Belov2024-09-19T13:04:09ZSource notebook for Introduction to Linear Algebra course
https://community.wolfram.com/groups/-/m/t/3277729
Could someone point me to the latest version of the notebook used in the Wolfram Course "Introduction to Linear Algebra"?
Many thanks in advance.Aldo Salzberg2024-09-19T16:01:01ZRunning the Wolfram Engine from Python
https://community.wolfram.com/groups/-/m/t/3277453
Hi Guys
There seemed to be some interest in my last post which was a general question which I inevitably developed a solution for.
The below is basic example of writing a Mathematica script and solving it in Python, thereafter the data is extracted and plotted in Python using Matplotlib. This example can be expanded to more complex problems allowing one to get the best of both worlds.
from wolframclient.evaluation import WolframLanguageSession
from wolframclient.language import wl, wlexpr
import matplotlib.pyplot as plt
import numpy as np
session = WolframLanguageSession()
wolfram_code = """
s = NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}];
Table[{x, y[x] /. s}, {x, 0, 30, 0.1}]
"""
# Evaluate the Wolfram code
result = session.evaluate(wlexpr(wolfram_code))
# Terminate the Wolfram session
session.terminate()
# Extract x and y values from the result
x_vals = [pair[0] for pair in result]
y_vals = [pair[1] for pair in result]
# Plot the solution using matplotlib
plt.plot(x_vals, y_vals, label='y(x)')
plt.xlabel('x')
plt.ylabel('y(x)')
plt.title('Solution of y\'[x] = y[x] Cos[x + y[x]]')
plt.grid(True)
plt.legend()
# Show the plot
plt.show()Mishal Mohanlal2024-09-19T07:44:18Z[WSC19] Differential Equation and Chaos Theory
https://community.wolfram.com/groups/-/m/t/1731808
![enter image description here][1]
Overview
--------
Differential equations are very useful in modelling complex systems that change with time. For this exploration, the differential equation we are looking at has a particular form: x''[t]+x'[t]==f[x[t]], where f is a real-valued function. The goal of this project is to investigate different behavior of these equations and to be able to classify them using supervised machine learning to classify different behaviors.
Chaotic Behaviours of Differential Equations
--------------------------------------------
One way to visualize this chaotic behavior is to use phase portrait. Phase portraits show how a function, its derivative, and its second derivative are changing. Here is an example: the solution to x[t]+x[t]==Sin[Exp[x[t]] seems to exhibit chaotic behavior in range {t,0,15}:
![enter image description here][2]
Euclidean Distance Test
-----------------------
We can calculate the distances between two points in phase portrait. With a successive collection of sample points, the result is a series of distances. If a graph converges, the sequence will converge to zero. The successive differences of the sequence will also go to zero. Note it is necessary to divide the terms by their distance to the origin in case the point is far away from origin.
Here is one example of the output, which is the plot of a list of differences of distance sequence/distance from origin, as compared to its behavior.
![enter image description here][3]
![enter image description here][4]
Classify and Machine Learning
-----------------------------
The following graphs are the result extracted from one thousand differential equations with the form x''[t]+x'[t]==f[x[t]]. These graphs are divided into 9 classes representing different behaviors.
![enter image description here][5]
Under the assumption that changing the initial condition of the differential equation just slightly will result plots in same classes, 700 random training data are generated to train the machine. Each data is scaled by a random amount to avoid bias.The result shows that this algorithm has an accuracy of 99.0%+/- 1.6%.
![enter image description here][6]
Conclusion
----------
Throughout this project, I successfully detected the chaotic behavior of different differential equations and classified them. The output includes a function that generate the phase portrait of some differential equations, a function that tells the interval in which the function is chaotic for input function continuous on the input interval. Finally, there is a machine learning classification that can classify different behaviors of chaotic functions with accuracy about 99%.
[Github Link][7]
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=1.png&userId=1726008
[2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=3.png&userId=1726008
[3]: https://community.wolfram.com//c/portal/getImageAttachment?filename=4.png&userId=1726008
[4]: https://community.wolfram.com//c/portal/getImageAttachment?filename=5.png&userId=1726008
[5]: https://community.wolfram.com//c/portal/getImageAttachment?filename=6.png&userId=1726008
[6]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Screenshot2019-07-11at2.27.44PM.png&userId=1726008
[7]: https://github.com/WangTianyi919/WSS-Template/tree/master/Final%20Project/Final%20SubmissionTianyi Wang2019-07-11T18:32:59ZHow to use tensors in Mathematica?
https://community.wolfram.com/groups/-/m/t/142857
Hello everybody,
I am beginner in Mathematica. I would like to know how to use tensors in Mathematica in general relativity, i.e. when i have defined metric tensor, how to compute tensors that appear in Einstein and Maxwell equations and get exact form of both sides; lowering/uppering four-vectors, covariant derivate etc. Is it built in or is some package needed?
Thank you for any answer.Ji?í Ryzner2013-10-22T21:44:31ZFrom simple waves to complex behavior: the unpredictability of sine and cosine transformations
https://community.wolfram.com/groups/-/m/t/3276382
&[Wolfram Notebook][1]
[1]: https://www.wolframcloud.com/obj/fbfbc4b6-1184-49e4-a41c-f051215ae565Jesús Adrián Montesinos Correa2024-09-18T03:13:44ZNumerical Integration of interpolated function returning a list
https://community.wolfram.com/groups/-/m/t/3275920
I am encoutering a problem when trying to perform the numerical integration of a function I have obtained from interpolation that returns a list. The problem is just with NIntegrate, because Plot works well.
dataX = Table[{n, {n, 2 n}}, {n, 0, 10}];
dataF = Interpolation[dataX, InterpolationOrder -> 1];
dataFi[x_?NumericQ, i_] := dataF[x][[i]];
Plot[dataF[x], {x, 0, 10}]
NIntegrate[dataF[x], {x, 0, 10}] (*Returns NIntegrate::inum*)
NIntegrate[Table[dataFi[x, i], {i, 1, 2}], {x, 0, 10}] (*Returns result with several Part::partw warnings*)
Table[NIntegrate[dataFi[x, i], {x, 0, 10}], {i, 1, 2}] (*Returns result and one Part::partw warning*)
I think I have done this in the past with previous versions and it was working, now with 13.3 it does not. Is it a bug or is this intended? Possible workarounds?Giorgio Busoni2024-09-17T07:04:21ZWould anyone help/guide how to solve the following system
https://community.wolfram.com/groups/-/m/t/3276487
Hello everyone. I am new in MATHEMATICA. Would anyone help/guide how to solve the following system of coupled PDE’s with time.? I have tried to solve but did not get the desire results (there is no smoothness in the graph). Firstly, I want to draw the fig 10 a in paper. Then fig 8 etc. The code has been attached. The following system got from this paper with DOI, (DOI: 10.1017/S0022112003003835) Thank you.
G_t-H^'/H*η*G_η-1/H*F*G_η+1/H*F_η*G+(2*F*G)/(η*H)=1/(H^2*R) [G_ηη+G_η/η-G/η^2 ]
F_ηη+F_η/η-F/η^2 =-H^2*G
With:
Initial conditions
F(η,0)=0, G(η,0)=0
Boundary conditions
F(0,t)=0 G(0,t)=0,
F(1,t)=-H' F_η (1,0)=H'
H(t)=1+Δ*cos(2t)
Where 0<Δ<1
Attributes[MakeVariables] = {Listable};
MakeVariables[var_, n_] := Table[Unique[var], {n}];
soln[delta_, Renolds_] :=
Module[{fvar0, gvar0, fvar1, gvar1, dy1, dy2, ny, ygrid,
R = Renolds, dt = 1, nmax = 8201, dy = 1/10, yTarget = 1/4,
gAtTarget, gValues = {}}, \[CapitalDelta] = delta;
H[t_] := 1 + \[CapitalDelta]*Cos[2*t];
dH[t_] := -2*\[CapitalDelta]*Sin[2*t];
(*R=100;*)
(*Create the grid and differentiation matrices*)
ygrid = Range[0, 1, dy];
ny = Length[ygrid];
dy2 = NDSolve`FiniteDifferenceDerivative[Derivative[2], ygrid,
DifferenceOrder -> 4]@"DifferentiationMatrix";
dy1 = NDSolve`FiniteDifferenceDerivative[Derivative[1], ygrid,
DifferenceOrder -> 4]@"DifferentiationMatrix";
(*Initialize variables for F and G*){fvar1, gvar1} =
MakeVariables[{ff, gg}, ny];
fvar0 = ConstantArray[0, {ny, nmax}];
gvar0 = ConstantArray[0, {ny, nmax}];
(*Time-stepping loop*)
Do[(*Update variables for F and G at the current time step*){fvar,
gvar} = {fvar0[[All, i]], gvar0[[All, i]]};
(*Define the equations*)
eqf = dy2.fvar1 + (dy1.fvar1)/ygrid - fvar1/ygrid^2 +
gvar1 H[(i + 1) dt]^2 // Quiet;
eqg = (gvar1 - gvar)/dt -
dH[(i + 1) dt]/
H[(i + 1) dt] ygrid (dy1.gvar1) - (dy1.gvar1) fvar/
H[(i + 1) dt] + 1/H[(i + 1) dt] (dy1.fvar) gvar1 +
2/(ygrid H[(i + 1) dt]) fvar*
gvar1 - (1/(R H[(i + 1) dt]^2))*((dy2.gvar1) + (dy1.gvar1)/
ygrid - gvar1/ygrid^2) // Quiet;
(*Apply boundary conditions*)
eqf[[1]] = fvar1[[1]];(*ensures that F(0,t)=0 at y=0*)
eqf[[-1]] = fvar1[[-1]] + dH[(i + 1) dt];(*ensures that F(1,
t)=-H'[t] at y=1*)eqg[[1]] = gvar1[[1]];(*ensures that G(0,t)=
0 at t=0*)
eqg[[-1]] = (dy1.fvar1)[[-1]] -
dH[(i + 1) dt];(*ensures that F'(1,t)=H'[t] at y=
1*)(*Solve the system*)eqns = Join[eqf, eqg];
var = Join[fvar1, gvar1];
{vec, mat} = CoefficientArrays[eqns, var];
sol = LinearSolve[mat, -vec];
(*Extract solutions for F and G at the next time step*)
{fvar0[[All, i + 1]], gvar0[[All, i + 1]]} = Partition[sol, ny];
(*Interpolate G(y,t) and store G(1/4,t)*)
gAtTarget = Interpolation[Transpose[{ygrid, gvar0[[All, i + 1]]}]];
(*Store G(1/4,t) only for t from 8100 to 8200*)
If[i >= 8100 && i <= 8201,
AppendTo[gValues, {i, gAtTarget[yTarget]}];];, {i, 1, nmax - 1}];
(*Return the solutions for F,G and the stored G values*)
{fvar0, gvar0, gValues}];
(*Call the function for delta=0.2 and store G(1/4,t) from 8100 to \
8200*)
{fSol, gSol, gValues} = soln[.2, 2050]; // AbsoluteTiming;
gValues;
(*Plot the values of G(1/4,t)*)
sajjad = ListLinePlot[gValues, GridLines -> Automatic,
ImageSize -> Large, Frame -> AllTrue,
FrameLabel -> {"t", "G(1/4,t)"}, PlotStyle -> {Red, Thick}]
&[Wolfram Notebook][1]
[1]: https://www.wolframcloud.com/obj/fb03acaf-31df-467d-acee-c48c651a95dcSajjad Ahmad2024-09-18T18:37:28ZHow do dogs see colors? Exploring canine vision with Ishihara color blindness tests.
https://community.wolfram.com/groups/-/m/t/3276647
![enter image description here][1]
&[Wolfram Notebook][2]
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=humanToDogVisionLoop-ezgif.com-optimize.gif&userId=11733
[2]: https://www.wolframcloud.com/obj/ca5253ff-b684-47db-89b4-0892f40e0186Phileas Dazeley-Gaist2024-09-18T14:34:01ZMathematica code to extract tabulated data after conversion from pdf to text
https://community.wolfram.com/groups/-/m/t/3275361
I've written the following code to extract the data I need from invoices which are in pdf format but can vary in terms of layout and terminology:
(*Step 1:Prepare Training Data*)
trainingDataItemDesc = {
"Description" -> "SimilarString", "DESCRIPTION" -> "SimilarString",
"Product Name" -> "SimilarString",
"Product Details" -> "SimilarString", "Products" -> "SimilarString",
"Product" -> "SimilarString", "Details" -> "SimilarString",
"Desc" -> "SimilarString", "ITEM" -> "SimilarString",
"Product Description" -> "SimilarString", "" -> "SimilarString",
"Item Description" -> "SimilarString", "ITEMS" -> "SimilarString",
"Description of Goods Sold" -> "SimilarString",
"Part Number/Description" -> "SimilarString",
"PRODUCT NAME" -> "SimilarString",
"PRODUCT DETAILS" -> "SimilarString", "PRODUCTS" -> "SimilarString",
"PRODUCT" -> "SimilarString", "DETAILS" -> "SimilarString",
"DESC" -> "SimilarString", "PRODUCT DESCRIPTION" -> "SimilarString",
"ITEM DESCRIPTION" -> "SimilarString",
"DESCRIPTION OF GOODS SOLD" -> "SimilarString",
"PART NUMBER/DESCRIPTION" -> "SimilarString",
"description" -> "SimilarString", "product name" -> "SimilarString",
"product details" -> "SimilarString",
"products" -> "SimilarString", "product" -> "SimilarString",
"details" -> "SimilarString", "desc" -> "SimilarString",
"item" -> "SimilarString", "product description" -> "SimilarString",
"item description" -> "SimilarString", "items" -> "SimilarString",
"description of goods sold" -> "SimilarString",
"part number/description" -> "SimilarString",
"Description:" -> "SimilarString",
"DESCRIPTION:" -> "SimilarString",
"Product Name:" -> "SimilarString",
"Product Details:" -> "SimilarString",
"Products:" -> "SimilarString", "Product:" -> "SimilarString",
"Details:" -> "SimilarString", "Desc:" -> "SimilarString",
"ITEM:" -> "SimilarString",
"Product Description:" -> "SimilarString",
"Item Description:" -> "SimilarString", "ITEMS:" -> "SimilarString",
"Description of Goods Sold:" -> "SimilarString",
"Part Number/Description:" -> "SimilarString",
"Total" -> "NotSimilar", "TOTAL REMITTANCE:" -> "NotSimilar",
"[GBP] TOTAL" -> "NotSimilar", "Total:" -> "NotSimilar",
"Grand Total:" -> "NotSimilar", "Invoice total" -> "NotSimilar",
"Total VAT" -> "NotSimilar", "Total Paid" -> "NotSimilar",
"Amount Due:" -> "NotSimilar", "AMOUNT (USD)" -> "NotSimilar",
"Order Total" -> "NotSimilar", "" -> "NotSimilar",
"Invoice Total:" -> "NotSimilar", "Gross Total" -> "NotSimilar",
"Net Price (per unit)" -> "NotSimilar", "TOTAL" -> "NotSimilar",
"Total paid" -> "NotSimilar", "Invoice Total" -> "NotSimilar",
"TOTAL INC. VAT:" -> "NotSimilar",
"Total Amount Due" -> "NotSimilar", "TOTAL:" -> "NotSimilar",
"GRAND TOTAL:" -> "NotSimilar", "INVOICE TOTAL" -> "NotSimilar",
"TOTAL VAT" -> "NotSimilar", "TOTAL PAID" -> "NotSimilar",
"AMOUNT DUE:" -> "NotSimilar", "ORDER TOTAL" -> "NotSimilar",
"INVOICE TOTAL:" -> "NotSimilar", "GROSS TOTAL" -> "NotSimilar",
"NET PRICE (PER UNIT)" -> "NotSimilar",
"TOTAL AMOUNT DUE" -> "NotSimilar", "total" -> "NotSimilar",
"total remittance:" -> "NotSimilar", "[gbp] total" -> "NotSimilar",
"total:" -> "NotSimilar", "grand total:" -> "NotSimilar",
"invoice total" -> "NotSimilar", "total vat" -> "NotSimilar",
"total paid" -> "NotSimilar", "amount due:" -> "NotSimilar",
"amount (usd)" -> "NotSimilar", "order total" -> "NotSimilar",
"invoice total:" -> "NotSimilar", "gross total" -> "NotSimilar",
"net price (per unit)" -> "NotSimilar",
"total inc. vat:" -> "NotSimilar",
"total amount due" -> "NotSimilar", "[GBP] TOTAL:" -> "NotSimilar",
"Invoice total:" -> "NotSimilar", "Total VAT:" -> "NotSimilar",
"Total Paid:" -> "NotSimilar", "AMOUNT (USD):" -> "NotSimilar",
"Order Total:" -> "NotSimilar", "Gross Total:" -> "NotSimilar",
"Net Price (per unit):" -> "NotSimilar",
"Total paid:" -> "NotSimilar",
"Total Amount Due:" -> "NotSimilar"}; trainingDataSubtot = {
"Subtotal" -> "SimilarString", "Nett Total:" -> "SimilarString",
"COMPONENT TOTAL" -> "SimilarString",
"Sub-Total:" -> "SimilarString", "Sub Total" -> "SimilarString",
"Subtotal:" -> "SimilarString", "" -> "SimilarString",
"Total goods ex VAT" -> "SimilarString",
"Sub-Total" -> "SimilarString",
"Net value of goods" -> "SimilarString",
"Total Net Amount" -> "SimilarString",
"Net Total:" -> "SimilarString", "Sub-total" -> "SimilarString",
"Goods Value" -> "SimilarString", "Products" -> "SimilarString",
"SUB-TOTAL:" -> "SimilarString", "Net Amount" -> "SimilarString",
"Nett Total" -> "SimilarString",
"Total Nett Goods" -> "SimilarString",
"Invoice Total" -> "SimilarString", "SUBTOTAL" -> "SimilarString",
"Net total" -> "SimilarString", "NETT TOTAL:" -> "SimilarString",
"SUB TOTAL" -> "SimilarString", "SUBTOTAL:" -> "SimilarString",
"TOTAL GOODS EX VAT" -> "SimilarString",
"SUB-TOTAL" -> "SimilarString",
"NET VALUE OF GOODS" -> "SimilarString",
"TOTAL NET AMOUNT" -> "SimilarString",
"NET TOTAL:" -> "SimilarString", "GOODS VALUE" -> "SimilarString",
"PRODUCTS" -> "SimilarString", "NET AMOUNT" -> "SimilarString",
"NETT TOTAL" -> "SimilarString",
"TOTAL NETT GOODS" -> "SimilarString",
"INVOICE TOTAL" -> "SimilarString", "NET TOTAL" -> "SimilarString",
"subtotal" -> "SimilarString", "nett total:" -> "SimilarString",
"component total" -> "SimilarString",
"sub-total:" -> "SimilarString", "sub total" -> "SimilarString",
"subtotal:" -> "SimilarString",
"total goods ex vat" -> "SimilarString",
"sub-total" -> "SimilarString",
"net value of goods" -> "SimilarString",
"total net amount" -> "SimilarString",
"net total:" -> "SimilarString", "goods value" -> "SimilarString",
"products" -> "SimilarString", "net amount" -> "SimilarString",
"nett total" -> "SimilarString",
"total nett goods" -> "SimilarString",
"invoice total" -> "SimilarString", "net total" -> "SimilarString",
"COMPONENT TOTAL:" -> "SimilarString",
"Sub Total:" -> "SimilarString",
"Total goods ex VAT:" -> "SimilarString",
"Net value of goods:" -> "SimilarString",
"Total Net Amount:" -> "SimilarString",
"Sub-total:" -> "SimilarString", "Goods Value:" -> "SimilarString",
"Products:" -> "SimilarString", "Net Amount:" -> "SimilarString",
"Total Nett Goods:" -> "SimilarString",
"Invoice Total:" -> "SimilarString", "Net total:" -> "SimilarString",
"Total" -> "NotSimilar", "TOTAL REMITTANCE:" -> "NotSimilar",
"[GBP] TOTAL" -> "NotSimilar", "Total:" -> "NotSimilar",
"Grand Total:" -> "NotSimilar", "Invoice total" -> "NotSimilar",
"Total VAT" -> "NotSimilar", "Total Paid" -> "NotSimilar",
"Amount Due:" -> "NotSimilar", "AMOUNT (USD)" -> "NotSimilar",
"Order Total" -> "NotSimilar", "" -> "NotSimilar",
"Invoice Total:" -> "NotSimilar", "Gross Total" -> "NotSimilar",
"Net Price (per unit)" -> "NotSimilar", "TOTAL" -> "NotSimilar",
"Total paid" -> "NotSimilar", "Invoice Total" -> "NotSimilar",
"TOTAL INC. VAT:" -> "NotSimilar",
"Total Amount Due" -> "NotSimilar", "TOTAL:" -> "NotSimilar",
"GRAND TOTAL:" -> "NotSimilar", "INVOICE TOTAL" -> "NotSimilar",
"TOTAL VAT" -> "NotSimilar", "TOTAL PAID" -> "NotSimilar",
"AMOUNT DUE:" -> "NotSimilar", "ORDER TOTAL" -> "NotSimilar",
"INVOICE TOTAL:" -> "NotSimilar", "GROSS TOTAL" -> "NotSimilar",
"NET PRICE (PER UNIT)" -> "NotSimilar",
"TOTAL AMOUNT DUE" -> "NotSimilar", "total" -> "NotSimilar",
"total remittance:" -> "NotSimilar", "[gbp] total" -> "NotSimilar",
"total:" -> "NotSimilar", "grand total:" -> "NotSimilar",
"invoice total" -> "NotSimilar", "total vat" -> "NotSimilar",
"total paid" -> "NotSimilar", "amount due:" -> "NotSimilar",
"amount (usd)" -> "NotSimilar", "order total" -> "NotSimilar",
"invoice total:" -> "NotSimilar", "gross total" -> "NotSimilar",
"net price (per unit)" -> "NotSimilar",
"total inc. vat:" -> "NotSimilar",
"total amount due" -> "NotSimilar", "[GBP] TOTAL:" -> "NotSimilar",
"Invoice total:" -> "NotSimilar", "Total VAT:" -> "NotSimilar",
"Total Paid:" -> "NotSimilar", "AMOUNT (USD):" -> "NotSimilar",
"Order Total:" -> "NotSimilar", "Gross Total:" -> "NotSimilar",
"Net Price (per unit):" -> "NotSimilar",
"Total paid:" -> "NotSimilar", "Total Amount Due:" -> "NotSimilar"};
trainingDataVAT = {
"Tax" -> "SimilarString", "VAT 20.0 - 20%:" -> "SimilarString",
"TOTAL TAX" -> "SimilarString", "VAT (20%):" -> "SimilarString",
"Tax:" -> "SimilarString", "" -> "SimilarString",
"VAT @ 20.00%" -> "SimilarString", "VAT (20%)" -> "SimilarString",
"Total Vat:" -> "SimilarString", "20 % VAT" -> "SimilarString",
"Total VAT" -> "SimilarString", "VAT:" -> "SimilarString",
"VAT" -> "SimilarString", "VAT Value" -> "SimilarString",
"Total Tax paid" -> "SimilarString",
"Total VAT Amount" -> "SimilarString",
"VAT 20%:" -> "SimilarString", "VAT Amount" -> "SimilarString",
"VAT Total" -> "SimilarString", "Invoice Total" -> "SimilarString",
"VAT TOTAL" -> "SimilarString", "V.A.T" -> "SimilarString",
"TAX" -> "SimilarString", "TAX:" -> "SimilarString",
"TOTAL VAT:" -> "SimilarString", "TOTAL VAT" -> "SimilarString",
"VAT VALUE" -> "SimilarString",
"TOTAL TAX PAID" -> "SimilarString",
"TOTAL VAT AMOUNT" -> "SimilarString",
"VAT AMOUNT" -> "SimilarString",
"INVOICE TOTAL" -> "SimilarString", "tax" -> "SimilarString",
"vat 20.0 - 20%:" -> "SimilarString",
"total tax" -> "SimilarString", "vat (20%):" -> "SimilarString",
"tax:" -> "SimilarString", "vat @ 20.00%" -> "SimilarString",
"vat (20%)" -> "SimilarString", "total vat:" -> "SimilarString",
"20 % vat" -> "SimilarString", "total vat" -> "SimilarString",
"vat:" -> "SimilarString", "vat" -> "SimilarString",
"vat value" -> "SimilarString",
"total tax paid" -> "SimilarString",
"total vat amount" -> "SimilarString",
"vat 20%:" -> "SimilarString", "vat amount" -> "SimilarString",
"vat total" -> "SimilarString", "invoice total" -> "SimilarString",
"v.a.t" -> "SimilarString", "TOTAL TAX:" -> "SimilarString",
"VAT @ 20.00%:" -> "SimilarString", "20 % VAT:" -> "SimilarString",
"Total VAT:" -> "SimilarString", "VAT Value:" -> "SimilarString",
"Total Tax paid:" -> "SimilarString",
"Total VAT Amount:" -> "SimilarString",
"VAT Amount:" -> "SimilarString", "VAT Total:" -> "SimilarString",
"Invoice Total:" -> "SimilarString",
"VAT TOTAL:" -> "SimilarString", "V.A.T:" -> "SimilarString",
"Subtotal" -> "NotSimilar", "Nett Total:" -> "NotSimilar",
"COMPONENT TOTAL" -> "NotSimilar", "Sub-Total:" -> "NotSimilar",
"Sub Total" -> "NotSimilar", "Subtotal:" -> "NotSimilar",
"" -> "NotSimilar", "Total goods ex VAT" -> "NotSimilar",
"Sub-Total" -> "NotSimilar", "Net value of goods" -> "NotSimilar",
"Total Net Amount" -> "NotSimilar", "Net Total:" -> "NotSimilar",
"Sub-total" -> "NotSimilar", "Goods Value" -> "NotSimilar",
"Products" -> "NotSimilar", "SUB-TOTAL:" -> "NotSimilar",
"Net Amount" -> "NotSimilar", "Nett Total" -> "NotSimilar",
"Total Nett Goods" -> "NotSimilar",
"Invoice Total" -> "NotSimilar", "SUBTOTAL" -> "NotSimilar",
"Net total" -> "NotSimilar", "NETT TOTAL:" -> "NotSimilar",
"SUB TOTAL" -> "NotSimilar", "SUBTOTAL:" -> "NotSimilar",
"TOTAL GOODS EX VAT" -> "NotSimilar", "SUB-TOTAL" -> "NotSimilar",
"NET VALUE OF GOODS" -> "NotSimilar",
"TOTAL NET AMOUNT" -> "NotSimilar", "NET TOTAL:" -> "NotSimilar",
"GOODS VALUE" -> "NotSimilar", "PRODUCTS" -> "NotSimilar",
"NET AMOUNT" -> "NotSimilar", "NETT TOTAL" -> "NotSimilar",
"TOTAL NETT GOODS" -> "NotSimilar",
"INVOICE TOTAL" -> "NotSimilar", "NET TOTAL" -> "NotSimilar",
"subtotal" -> "NotSimilar", "nett total:" -> "NotSimilar",
"component total" -> "NotSimilar", "sub-total:" -> "NotSimilar",
"sub total" -> "NotSimilar", "subtotal:" -> "NotSimilar",
"total goods ex vat" -> "NotSimilar", "sub-total" -> "NotSimilar",
"net value of goods" -> "NotSimilar",
"total net amount" -> "NotSimilar", "net total:" -> "NotSimilar",
"goods value" -> "NotSimilar", "products" -> "NotSimilar",
"net amount" -> "NotSimilar", "nett total" -> "NotSimilar",
"total nett goods" -> "NotSimilar",
"invoice total" -> "NotSimilar", "net total" -> "NotSimilar",
"COMPONENT TOTAL:" -> "NotSimilar", "Sub Total:" -> "NotSimilar",
"Total goods ex VAT:" -> "NotSimilar",
"Net value of goods:" -> "NotSimilar",
"Total Net Amount:" -> "NotSimilar", "Sub-total:" -> "NotSimilar",
"Goods Value:" -> "NotSimilar", "Products:" -> "NotSimilar",
"Net Amount:" -> "NotSimilar", "Total Nett Goods:" -> "NotSimilar",
"Invoice Total:" -> "NotSimilar", "Net total:" -> "NotSimilar"};
trainingDataTotal = {
"Total" -> "SimilarString", "TOTAL REMITTANCE:" -> "SimilarString",
"[GBP] TOTAL" -> "SimilarString", "Total:" -> "SimilarString",
"Grand Total:" -> "SimilarString",
"Invoice total" -> "SimilarString", "Total VAT" -> "SimilarString",
"Total Paid" -> "SimilarString", "Amount Due:" -> "SimilarString",
"AMOUNT (USD)" -> "SimilarString",
"Order Total" -> "SimilarString", "" -> "SimilarString",
"Invoice Total:" -> "SimilarString",
"Gross Total" -> "SimilarString",
"Net Price (per unit)" -> "SimilarString",
"TOTAL" -> "SimilarString", "Total paid" -> "SimilarString",
"Invoice Total" -> "SimilarString",
"TOTAL INC. VAT:" -> "SimilarString",
"Total Amount Due" -> "SimilarString", "TOTAL:" -> "SimilarString",
"GRAND TOTAL:" -> "SimilarString",
"INVOICE TOTAL" -> "SimilarString", "TOTAL VAT" -> "SimilarString",
"TOTAL PAID" -> "SimilarString", "AMOUNT DUE:" -> "SimilarString",
"ORDER TOTAL" -> "SimilarString",
"INVOICE TOTAL:" -> "SimilarString",
"GROSS TOTAL" -> "SimilarString",
"NET PRICE (PER UNIT)" -> "SimilarString",
"TOTAL AMOUNT DUE" -> "SimilarString", "total" -> "SimilarString",
"total remittance:" -> "SimilarString",
"[gbp] total" -> "SimilarString", "total:" -> "SimilarString",
"grand total:" -> "SimilarString",
"invoice total" -> "SimilarString", "total vat" -> "SimilarString",
"total paid" -> "SimilarString", "amount due:" -> "SimilarString",
"amount (usd)" -> "SimilarString",
"order total" -> "SimilarString",
"invoice total:" -> "SimilarString",
"gross total" -> "SimilarString",
"net price (per unit)" -> "SimilarString",
"total inc. vat:" -> "SimilarString",
"total amount due" -> "SimilarString",
"[GBP] TOTAL:" -> "SimilarString",
"Invoice total:" -> "SimilarString",
"Total VAT:" -> "SimilarString", "Total Paid:" -> "SimilarString",
"AMOUNT (USD):" -> "SimilarString",
"Order Total:" -> "SimilarString",
"Gross Total:" -> "SimilarString",
"Net Price (per unit):" -> "SimilarString",
"Total paid:" -> "SimilarString",
"Total Amount Due:" -> "SimilarString", "Subtotal" -> "NotSimilar",
"Nett Total:" -> "NotSimilar", "COMPONENT TOTAL" -> "NotSimilar",
"Sub-Total:" -> "NotSimilar", "Sub Total" -> "NotSimilar",
"Subtotal:" -> "NotSimilar", "" -> "NotSimilar",
"Total goods ex VAT" -> "NotSimilar", "Sub-Total" -> "NotSimilar",
"Net value of goods" -> "NotSimilar",
"Total Net Amount" -> "NotSimilar", "Net Total:" -> "NotSimilar",
"Sub-total" -> "NotSimilar", "Goods Value" -> "NotSimilar",
"Products" -> "NotSimilar", "SUB-TOTAL:" -> "NotSimilar",
"Net Amount" -> "NotSimilar", "Nett Total" -> "NotSimilar",
"Total Nett Goods" -> "NotSimilar",
"Invoice Total" -> "NotSimilar", "SUBTOTAL" -> "NotSimilar",
"Net total" -> "NotSimilar", "NETT TOTAL:" -> "NotSimilar",
"SUB TOTAL" -> "NotSimilar", "SUBTOTAL:" -> "NotSimilar",
"TOTAL GOODS EX VAT" -> "NotSimilar", "SUB-TOTAL" -> "NotSimilar",
"NET VALUE OF GOODS" -> "NotSimilar",
"TOTAL NET AMOUNT" -> "NotSimilar", "NET TOTAL:" -> "NotSimilar",
"GOODS VALUE" -> "NotSimilar", "PRODUCTS" -> "NotSimilar",
"NET AMOUNT" -> "NotSimilar", "NETT TOTAL" -> "NotSimilar",
"TOTAL NETT GOODS" -> "NotSimilar",
"INVOICE TOTAL" -> "NotSimilar", "NET TOTAL" -> "NotSimilar",
"subtotal" -> "NotSimilar", "nett total:" -> "NotSimilar",
"component total" -> "NotSimilar", "sub-total:" -> "NotSimilar",
"sub total" -> "NotSimilar", "subtotal:" -> "NotSimilar",
"total goods ex vat" -> "NotSimilar", "sub-total" -> "NotSimilar",
"net value of goods" -> "NotSimilar",
"total net amount" -> "NotSimilar", "net total:" -> "NotSimilar",
"goods value" -> "NotSimilar", "products" -> "NotSimilar",
"net amount" -> "NotSimilar", "nett total" -> "NotSimilar",
"total nett goods" -> "NotSimilar",
"invoice total" -> "NotSimilar", "net total" -> "NotSimilar",
"COMPONENT TOTAL:" -> "NotSimilar", "Sub Total:" -> "NotSimilar",
"Total goods ex VAT:" -> "NotSimilar",
"Net value of goods:" -> "NotSimilar",
"Total Net Amount:" -> "NotSimilar", "Sub-total:" -> "NotSimilar",
"Goods Value:" -> "NotSimilar", "Products:" -> "NotSimilar",
"Net Amount:" -> "NotSimilar", "Total Nett Goods:" -> "NotSimilar",
"Invoice Total:" -> "NotSimilar", "Net total:" -> "NotSimilar"};
(*Step 2:Train a Machine Learning Classifier*)
modelItemDesc = Classify[trainingDataItemDesc];
modelSubtot = Classify[trainingDataSubtot];
modelShip = Classify[trainingDataShip];
modelVAT = Classify[trainingDataVAT];
modelTotal = Classify[trainingDataTotal];
(*testPhrase="Another Random Example";
Print["Test phrase classification: ",modelSubtot[testPhrase]];*)
(*Step 1:Set Up the Word COM Interface*)
extractTextFromPDFUsingPDFtoText[pdfPath_String] :=
Module[{outputPath, result},
outputPath =
FileNameJoin[{DirectoryName[pdfPath],
FileBaseName[pdfPath] <> ".txt"}];
RunProcess[{"C:\\Poppler\\Library\\bin\\pdftotext.exe", "-layout",
pdfPath, outputPath}];
result = Import[outputPath, "Text"];
If[result === "", extractTextWithOCR[pdfPath], result]]
(*Step 2:Determine If OCR Is Required*)
requiresOCR[text_String] :=
StringLength[text] < 50 ||
StringMatchQ[text, RegularExpression["[^a-zA-Z0-9]+"],
IgnoreCase -> True]
(*Step 3:OCR Extraction Function*)
extractTextWithOCR[filename_String] := Module[{pages, ocrText},
(*Try to import the PDF as individual images*)
pages = Import[filename, {"PDF", "Pages"}];
(*If import fails,return a failure message*)
If[pages === $Failed, Return["$Failed"]];
(*Apply OCR to each page*)ocrText = TextRecognize /@ pages;
(*Combine the recognized text from all pages*)StringJoin[ocrText]]
(*Step 4:Combined Text Extraction Function*)
extractTextFromPDF[filename_String] :=
Module[{text},(*First,try to extract text using Microsoft Word*)
Print[filename];
text = Quiet[Check[extractTextFromPDFUsingPDFtoText[filename], ""]];
(*If the extracted text is empty or looks like gibberish,apply OCR*)
If[requiresOCR[text], Print["Requires OCR"];
text = extractTextWithOCR[filename]];
text]
(*Step 5:Search through all subfolders in a folder and extract \
all.pdf filenames*)
getAllPDFs[folder_String] := FileNames["*.pdf", folder, Infinity];
(*Specify the training and main folders where the PDFs are located*)
mainFolder =
"Z:\\Shared\\03 - Operations\\06 - Supply Chain\\Invoice Data \
Extraction\\Test";
Print["Getting a list of all PDF files in the folder and its \
subfolders..."];
(*Get a list of all PDF files in the folder and its subfolders*)
pdfFiles = getAllPDFs[mainFolder];
(*Step 5:Initialize a list to store the first entries in \
extractedNumbersSubtot for each file*)
firstEntriesItemDesc = {};
firstEntriesSubtot = {};
firstEntriesShip = {};
firstEntriesVAT = {};
firstEntriesTotal = {};
(*Step 6:Process each file in the folder*)
Do[
(*Load the file content*)
invoiceText = extractTextFromPDF[pdfFiles[[i]]];
(*Step 4:
Find positionsSubtot of phrases in the file content that match \
similar strings*)
allPositionsItemDesc = {};
allPositionsSubtot = {};
allPositionsShip = {};
allPositionsVAT = {};
allPositionsTotal = {};
Do[
(*Find positionsItemDesc of the current phrase in the file content*)
positionsItemDesc = StringPosition[invoiceText, phrase];
(*Classify the phrase if it's found in the text*)
If[Length[positionsItemDesc] > 0 &&
modelItemDesc[phrase] === "SimilarString",
(*Add all positionsItemDesc of this phrase to the list*)
allPositionsItemDesc =
Join[allPositionsItemDesc, positionsItemDesc]
],
{phrase, Keys[trainingDataItemDesc]}
];
Print[allPositionsItemDesc];
Do[
(*Find positionsSubtot of the current phrase in the file content*)
positionsSubtot = StringPosition[invoiceText, phrase];
(*Classify the phrase if it's found in the text*)
If[Length[positionsSubtot] > 0 &&
modelSubtot[phrase] === "SimilarString",
(*Add all positionsSubtot of this phrase to the list*)
allPositionsSubtot = Join[allPositionsSubtot, positionsSubtot]
],
{phrase, Keys[trainingDataSubtot]}
];
Do[
(*Find positionsSubtot of the current phrase in the file content*)
positionsShip = StringPosition[invoiceText, phrase];
(*Classify the phrase if it's found in the text*)
If[Length[positionsShip] > 0 &&
modelShip[phrase] === "SimilarString",
(*Add all positionsSubtot of this phrase to the list*)
allPositionsShip = Join[allPositionsShip, positionsShip]
],
{phrase, Keys[trainingDataShip]}
];
Do[
(*Find positionsVAT of the current phrase in the file content*)
positionsVAT = StringPosition[invoiceText, phrase];
(*Classify the phrase if it's found in the text*)
If[Length[positionsVAT] > 0 && modelVAT[phrase] === "SimilarString",
(*Add all positionsVAT of this phrase to the list*)
allPositionsVAT = Join[allPositionsVAT, positionsVAT]
],
{phrase, Keys[trainingDataVAT]}
];
Do[
(*Find positionsSubtot of the current phrase in the file content*)
positionsTotal = StringPosition[invoiceText, phrase];
(*Classify the phrase if it's found in the text*)
If[Length[positionsTotal] > 0 &&
modelTotal[phrase] === "SimilarString",
(*Add all positionsSubtot of this phrase to the list*)
allPositionsTotal = Join[allPositionsTotal, positionsTotal]
],
{phrase, Keys[trainingDataTotal]}
];
(*Step 4:Extract Numbers Next to Similar Strings*)
allItemDescriptions = {};
itemDescriptions = {};
extractedNumbersSubtot = {};
extractedNumbersShip = {};
extractedNumbersVAT = {};
extractedNumbersTotal = {};
numberPattern = RegularExpression["\\d{1,3}(,\\d{3})*(\\.\\d+)?"];
Do[
(*Print["positionsItemDesc dims = ",Dimensions[
positionsItemDesc]];*)
If[
Dimensions[positionsItemDesc] =!= {0},
pos =
Flatten[positionsItemDesc][[2]];(*Get the end positionsItemDesc \
of the match*)
(*Extract lines of text directly below the item description \
header*)
itemLines = StringSplit[StringDrop[invoiceText, pos], "\n"];
Print["itemLines Dims = ", Dimensions[itemLines]];
Print["Length[itemLines] = ", Length[itemLines]];
Print["Min[Length[itemLines]] = ", Min[Length[itemLines]]];
(*Ensure we handle empty lines*)
itemIndex = 1;
qtyIndex = 1;
(*Match the lines that are under the headers and collect them*)
Do[
If[StringLength[itemLines[[i]]] > 0,
Print["i = ", i];
itemLine = StringTrim[itemLines[[i]]];
Print["itemLine = ", itemLine];
AppendTo[itemDescriptions, itemLine];
],
{i, 1, Min[Length[itemLines]]}]
],
{positionsItemDesc, allPositionsItemDesc}
];
Do[
(*Print["positionSubtot dims = ",Dimensions[positionSubtot]];*)
If[
Dimensions[positionSubtot] =!= {0},
pos =
Flatten[positionSubtot][[2]];(*Get the end positionSubtot of the \
match*)
(*Extract the text after the similar string's positionSubtot*)
afterText = StringDrop[invoiceText, pos];
(*Find the first number following the similar string*)
number = StringCases[afterText, numberPattern, 1];
(*If a number is found,add it to the list of extracted numbers*)
If[number =!= {},
AppendTo[extractedNumbersSubtot, number[[1]]]
(*Print["No number found after positionSubtot: ",pos]*)
];
],
{positionSubtot, allPositionsSubtot}
];
Do[
If[
Dimensions[positionShip] =!= {0},
pos =
Flatten[positionShip][[2]];(*Get the end positionShip of the \
match*)
(*Extract the text after the similar string's positionShip*)
afterText = StringDrop[invoiceText, pos];
(*Find the first number following the similar string*)
number = StringCases[afterText, numberPattern, 1];
(*If a number is found,add it to the list of extracted numbers*)
If[number =!= {},
AppendTo[extractedNumbersShip, number[[1]]]
(*Print["No number found after positionShip: ",pos]*)
];
],
{positionShip, allPositionsShip}
];
Do[
If[
Dimensions[positionVAT] =!= {0},
pos =
Flatten[positionVAT][[2]];(*Get the end positionVAT of the match*)
\
(*Extract the text after the similar string's positionVAT*)
afterText = StringDrop[invoiceText, pos];
(*Find the first number following the similar string*)
number = StringCases[afterText, numberPattern, 1];
(*If a number is found,add it to the list of extracted numbers*)
If[number =!= {},
AppendTo[extractedNumbersVAT, number[[1]]]
(*Print["No number found after positionVAT: ",pos]*)
];
],
{positionVAT, allPositionsVAT}
];
Do[
If[
Dimensions[positionTotal] =!= {0},
pos =
Flatten[positionTotal][[2]];(*Get the end positionTotal of the \
match*)
(*Extract the text after the similar string's positionTotal*)
afterText = StringDrop[invoiceText, pos];
(*Find the first number following the similar string*)
number = StringCases[afterText, numberPattern, 1];
(*If a number is found,add it to the list of extracted numbers*)
If[number =!= {},
AppendTo[extractedNumbersTotal, number[[1]]]
(*Print["No number found after positionSubtot: ",pos]*)
];
],
{positionTotal, allPositionsTotal}
];
(*Step 6:
Flatten the list to handle any nested structure and get the first \
number*)
firstExtractedNumberSubtot =
If[Length[extractedNumbersSubtot] > 0,
Flatten[extractedNumbersSubtot][[1]], "No numbers found"];
firstExtractedNumberShip =
If[Length[extractedNumbersShip] > 0,
Flatten[extractedNumbersShip][[1]], "No numbers found"];
firstExtractedNumberVAT =
If[Length[extractedNumbersVAT] > 0,
Flatten[extractedNumbersVAT][[1]], "No numbers found"];
firstExtractedNumberTotal =
If[Length[extractedNumbersTotal] > 0,
Flatten[extractedNumbersTotal][[1]], "No numbers found"];
(*Step 10:Add the result to the firstEntriesSubtot list*)
AppendTo[allItemDescriptions, Flatten[itemDescriptions]];
AppendTo[firstEntriesSubtot, firstExtractedNumberSubtot];
AppendTo[firstEntriesShip, firstExtractedNumberShip];
AppendTo[firstEntriesVAT, firstExtractedNumberVAT];
AppendTo[firstEntriesTotal, firstExtractedNumberTotal],
{i, Length[pdfFiles]}
];
(*Final output:List of first extracted numbers for each file*)
Print["All item descriptions for each file: ", allItemDescriptions];
Print["First entries in extractedNumbersSubtot for each file: ",
firstEntriesSubtot];
Print["First entries in extractedNumbersShip for each file: ",
firstEntriesShip];
Print["First entries in extractedNumbersShip for each file: ",
firstEntriesVAT];
Print["First entries in extractedNumbersTotal for each file: ",
firstEntriesTotal];
The code is working well for the search strings which have the desired corresponding data to their right (trainingDataShip, trainingDataVAT, trainingDataTotal). The problems arise for the tabulated items where the desired data are below the search string headers (trainingDataItemDesc). After the invoices are converted to text format, the tables are lost so it is then not possible to extract all the data in the table cells below each header.
How to go about this?Archie Watts-Farmer2024-09-17T05:43:06ZReproducing strong visual effect of the rotating cube illusion
https://community.wolfram.com/groups/-/m/t/3276071
*EDITORIAL TEAM NOTE: The first section of this post is the original question that appeared on [Mathematica Stack Exchange][1]. It puts in context the winning Akishi Kato answer found in the second section.*
---
## 1) Original question
A very "strong" visual effect illusion was posted recently [HERE][2]. Here are a few frames of it at low resolution. The cubes are NOT rotating in reality. Curious: to see cube NOT moving use "cross-eyed viewing" as you would do for a stereogram and a static cube will appear in the middle.
![enter image description here][3]
Notice, cubes rotate in different directions. If you look at it at high resolution screenshot (click to zoom on the image below) you will see the difference at the edges of cube frames - different colors, different sides - that's probably the source of the illusion:
![enter image description here][4]
Here is a starter code to implement a cube with rotating background. Define half-disk:
halfDisk[angle_:0,color_:Black,radius_:.5,center_:{.5,.5}]:=
{color,DiskSegment[center,radius,{angle+0,angle+Pi}]}
The rest is pretty easy. The control of Manipulate is the angle of rotation:
Manipulate[Graphics3D[
{EdgeForm[Directive[Thickness[.03],Orange]],FaceForm[None],Cube[]},
Prolog->{halfDisk[-a],halfDisk[Pi-a,White]},
ViewPoint->5.{Sin[2],Cos[2],.4},
Boxed->False,SphericalRegion->True,Background->Gray]
,{a,0,2Pi}]
You can generate a .GIF or .MP4 by replacing **Manipulate** with a **Table** and using **Export** to the corresponding file format. Or use any other method, the above code is not necessarily the best idea to start from, up to you.
Obviously this minimal rotation is not enough to create the visual effect. Probably something close to things discussed here is happening:
- [Visual motion illusions][5]
- [More about visual motion illusions][6]
- [Optical illusion of motion based on change of colors][7]
I am looking for any (but desirably minimal and clear) implementation that reproduces this strong visual effect.
## 2) The winning Akishi Kato answer
&[Wolfram Notebook][8]
[1]: https://mathematica.stackexchange.com/q/306655
[2]: https://x.com/jitanpon/status/1828425924490207629
[3]: https://community.wolfram.com//c/portal/getImageAttachment?filename=XIm3Eidc.gif&userId=20103
[4]: https://community.wolfram.com//c/portal/getImageAttachment?filename=trkkVp0y.png&userId=20103
[5]: https://community.wolfram.com/groups/-/m/t/2567382
[6]: https://community.wolfram.com/groups/-/m/t/2608592
[7]: https://community.wolfram.com/groups/-/m/t/2542031
[8]: https://www.wolframcloud.com/obj/13d2e9cf-4084-47ba-b1b6-7b977caf50b8Akishi Kato2024-09-17T17:27:44ZSimulating random hand-twirling for 3D digital objects with spherical splines
https://community.wolfram.com/groups/-/m/t/3276392
![Simulating random hand-twirling for 3D digital objects with spherical splines][1]
&[Wolfram Notebook][2]
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=8693Heroimage.gif&userId=20103
[2]: https://www.wolframcloud.com/obj/36c66b2c-606a-4a5b-b3d8-82e7f60b563aVitaliy Kaurov2024-09-18T05:36:25Z⭐ [R&DL] Wolfram R&D Developers on LIVE Stream
https://community.wolfram.com/groups/-/m/t/2593151
**Introducing our brand new YouTube channel, [Wolfram R&D][1]! Our channel features livestreams, behind-the-scenes creator presentations, insider videos, and more.**
----------
Join us for the unique Wolfram R&D livestreams on [Twitch][2] and [YouTube][3] led by our developers!
You will see **LIVE** stream indicators on these channels on the dates listed below. The live streams provide tutorials and behind the scenes look at Mathematica and the Wolfram Language directly from developers.
Join our livestreams every Wednesday at 11 AM CST and interact with developers who work on data science, machine learning, image processing, visualization, geometry, and other areas.
----------
⭕ **UPCOMING** EVENTS
- April 24 -- FeynCalc with [Vladyslav Shtabovenko][60]
----------
✅ **PAST** EVENTS
- April 3 -- [Explore the Total Solar Eclipse of April 2024][59]
- Mar 22 -- [20 Years of xAct Tensor Computer Algebra][58]
- Feb 28 -- [Zero Knowledge Authentication][57]
- Jan 17 -- [Nutrients by the Numbers][56]
- Dec 13 -- [Understanding Graphics][55]
- Oct 18 -- [Overview of Number Theory][54]
- Sep 27 -- [QMRITools: Processing Quantitative MRI Data][52]
- Sep 13 -- [Make High Quality Graph Visualization][51]
- Sep 6 -- [Insider's View of Graphs & Networks][53]
- Aug 30 -- [Labeling Everywhere][49]
- Aug 22 -- [Equation Generator for Equation-of-Motion Coupled Cluster Assisted by CAS][48]
- Aug 16 -- [Foreign Function Interface][4]
- July 26 -- [Modeling Fluid Circuits][6]
- July 19 -- [Geocomputation][5]
- July 5 -- [Protein Visualization][7]
- Jun 14 -- [Chat Notebooks bring the power of Notebooks to LLMs][8]
- May 31-- [Probability and Statistics: Random Sampling][9]
- May 24 -- [Problem Solving][10]
- May 17 -- [The state of Optimization][11]
- May 10 -- [Building a video game with Wolfram notebooks][12]
- April 26 -- [Control Systems: An Overview][13]
- April 19 -- [MaXrd: A crystallography package developed for research support][14]
- April 5th -- [Relational database in the Wolfram Language][15]
- Mar 29th -- [Build your first game in the Wolfram Language with Unity game engine] [16]
- Mar 22nd -- [Everything to know about Mellin-Barnes Integrals - Part II][17]
- Mar 15th -- [Building your own Shakespearean GPT - a ChatGPT like GPT model][18]
- Mar 8th -- [Understand Time, Date and Calendars][19]
- Mar 1st -- [Introducing Astro Computation][20]
- Feb 22nd -- [Latest features in System Modeler][21]
- Feb 15th -- [Everything to know about Mellin-Barnes Integrals][22]
- Feb 8th -- [Dive into Video Processing][23]
- Feb 1st -- [PDE Modeling][24]
- Jan. 25th -- [Ask Integration Questions to Oleg Marichev][25]
- Jan. 18th -- [My Developer Tools][26]
- Jan. 11th -- [Principles of Dynamic Interfaces][27]
- Dec. 14th -- [Wolfram Resource System: Repositories & Archives][28]
- Dec. 7th -- [Inner Workings of ImageStitch: Image Registration, Projection and Blending][29]
- Nov. 30th -- [Q&A for Calculus and Algebra][30]
- Nov. 23rd -- [xAct: Efficient Tensor Computer Algebra][31]
- Nov. 16th -- [Latest in Machine Learning][32]
- Nov. 9th -- [Computational Geology][33]
- Nov. 2nd -- [Behind the Scenes at the Wolfram Technology Conference 2022][34]
- Oct 26th -- [Group Theory Package (GTPack) and Symmetry Principles in Condensed Matter][35]
- Oct 12th -- [Tree Representation for XML, JSON and Symbolic Expressions][36]
- Oct. 5th -- [A Computational Exploration of Alcoholic Beverages][37]
- Sept. 28th -- [Q&A with Visualization & Graphics Developers][38]
- Sept. 14th -- [Paclet Development][39]
- Sept. 7th -- [Overview of Chemistry][40]
- Aug. 24th -- [Dive into Visualization][41]
- Aug. 17th -- [Latest in Graphics & Shaders][42]
- Aug. 10th -- [What's new in Calculus & Algebra][43]
> **What are your interests? Leave a comment here on this post to share your favorite topic suggestions for our livestreams.**
**Follow us on our live broadcasting channels [Twitch][44] and [YouTube][45] and for the up-to-date announcements on our social media: [Facebook][46] and [Twitter][47].**
[1]: https://wolfr.am/1eatWLcDA
[2]: https://www.twitch.tv/wolfram
[3]: https://wolfr.am/1eatWLcDA
[4]: https://www.youtube.com/watch?v=C82NHpy7D6k
[5]: https://community.wolfram.com/groups/-/m/t/2985580
[6]: https://community.wolfram.com/groups/-/m/t/2982197
[7]: https://community.wolfram.com/groups/-/m/t/2982114
[8]: https://youtu.be/ZqawtrWwE0c
[9]: https://community.wolfram.com/groups/-/m/t/2946101
[10]: https://community.wolfram.com/groups/-/m/t/2925156
[11]: https://community.wolfram.com/groups/-/m/t/2921756
[12]: https://community.wolfram.com/groups/-/m/t/2918746
[13]: https://community.wolfram.com/groups/-/m/t/2917597
[14]: https://community.wolfram.com/groups/-/m/t/2911327
[15]: https://community.wolfram.com/groups/-/m/t/2907390
[16]: https://community.wolfram.com/groups/-/m/t/2921593
[17]: https://community.wolfram.com/groups/-/m/t/2861119
[18]: https://community.wolfram.com/groups/-/m/t/2847286
[19]: https://community.wolfram.com/groups/-/m/t/2851575
[20]: https://community.wolfram.com/groups/-/m/t/2852934
[21]: https://community.wolfram.com/groups/-/m/t/2842136
[22]: https://community.wolfram.com/groups/-/m/t/2838335
[23]: https://community.wolfram.com/groups/-/m/t/2827166
[24]: https://community.wolfram.com/groups/-/m/t/2823264
[25]: https://community.wolfram.com/groups/-/m/t/2821053
[26]: https://youtu.be/istKGqpDUsw
[27]: https://community.wolfram.com/groups/-/m/t/2777853
[28]: https://youtu.be/roCkXVkDuLA
[29]: https://youtu.be/pYHAz-NatXI
[30]: https://youtu.be/r7Hjdr_D7c4
[31]: https://community.wolfram.com/groups/-/m/t/2713818
[32]: https://community.wolfram.com/groups/-/m/t/2705779
[33]: https://community.wolfram.com/groups/-/m/t/2701172
[34]: https://youtu.be/UrM-OBu3H9o
[35]: https://community.wolfram.com/groups/-/m/t/2678940
[36]: https://community.wolfram.com/groups/-/m/t/2649407
[37]: https://community.wolfram.com/groups/-/m/t/2635049
[38]: https://community.wolfram.com/groups/-/m/t/2618033
[39]: https://community.wolfram.com/groups/-/m/t/2616863
[40]: https://community.wolfram.com/groups/-/m/t/2613617
[41]: https://community.wolfram.com/groups/-/m/t/2605432
[42]: https://community.wolfram.com/groups/-/m/t/2600997
[43]: https://community.wolfram.com/groups/-/m/t/2596451
[44]: https://www.twitch.tv/wolfram
[45]: https://wolfr.am/1eatWLcDA
[46]: https://www.facebook.com/wolframresearch
[47]: https://twitter.com/WolframResearch
[48]: https://www.youtube.com/live/ElP55ZILxPw?si=nsAPOQ3u-RbvuGKX
[49]: https://community.wolfram.com/groups/-/m/t/3007543
[50]: https://community.wolfram.com/web/charlesp
[51]: https://community.wolfram.com/groups/-/m/t/3019288
[52]: https://www.youtube.com/live/KM1yWHRrF2k?si=g2R7rHB2IinVRpo6
[53]: https://community.wolfram.com/groups/-/m/t/3009184
[54]: https://community.wolfram.com/groups/-/m/t/3064700
[55]: https://community.wolfram.com/groups/-/m/t/3084291
[56]: https://community.wolfram.com/groups/-/m/t/3104670
[57]: https://community.wolfram.com/groups/-/m/t/3164204
[58]: https://youtube.com/playlist?list=PLdIcYTEZ4S8TSEk7YmJMvyECtF-KA1SQ2&si=paXZHs0ZzGdB7y1y
[59]: https://youtube.com/playlist?list=PLdIcYTEZ4S8RyjEB7JSAsGerbYHl5xXeJ&si=xkNtkIDvKHFWHVmD
[60]: https://community.wolfram.com/web/vshtabovenkoCharles Pooh2022-08-05T21:37:19ZPhysical plucked string modeling using the Karplus-Strong algorithm
https://community.wolfram.com/groups/-/m/t/3275610
![enter image description here][1]
&[Wolfram Notebook][2]
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=kssynth.gif&userId=3211209
[2]: https://www.wolframcloud.com/obj/2f2bb43a-95e9-4674-940b-ba2974bd9e92William Choi-Kim2024-09-17T05:34:13ZFogler's adiabatic laminar flow reactor
https://community.wolfram.com/groups/-/m/t/3274313
![Fogler's adiabatic laminar flow reactor][1]
&[Wolfram Notebook][2]
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=3979Hero.jpg&userId=20103
[2]: https://www.wolframcloud.com/obj/e3f385fc-61b1-47f3-bc1c-ac941c95e1fcHousam Binous2024-09-14T16:25:38Z[WSG24] Daily Study Group: What is ChatGPT Doing... and Why Does It Work?
https://community.wolfram.com/groups/-/m/t/3265066
A one-week Wolfram U Daily Study Group covering Stephen Wolfram's [best-selling book][1] [What is ChatGPT Doing... and Why Does It Work?][2] begins on Monday, September 9, 2024.
![enter image description here][3]
Join a cohort of fellow learners to discover the principles that underly ChatGPT and other LLMs. I have adapted the material from the aforementioned book into a series of four notebooks covering topics ranging from probabilistic text generation to neural nets, machine learning, embeddings and even transformer models.
Giulio Alessandrini, our manager of machine learning at Wolfram, will join to answer your questions on the day we cover neural networks. On the final day of the study group, Alan Joyce—who directs content development at Wolfram|Alpha—will join us to explain how the computational powers of Wolfram Language can be integrated with ChatGPT, and why this integration is much more than the sum of its parts.
Stephen Wolfram's book is aimed at anybody who is curious about these ideas, and this study group follows the book's lead. Therefore, **no prior Wolfram Language, machine learning, or even coding experience is necessary** to attend this study group.
Please feel free to post any questions, ideas and/or useful links in this thread between sessions—we always love to continue the discussion here on Community!
This is a one-week study group that will run from September 9 through September 13, 2024 at 11:00am Central US Time each day.
> [**REGISTER HERE**][4]
![enter image description here][5]
[1]: https://www.wolfram-media.com/products/what-is-chatgpt-doing-and-why-does-it-work/
[2]: https://www.bigmarker.com/series/what-is-chatgpt-doing-wsg58/series_details?utm_bmcr_source=community
[3]: https://community.wolfram.com//c/portal/getImageAttachment?filename=WSG58Banner.png&userId=1711324
[4]: https://www.bigmarker.com/series/what-is-chatgpt-doing-wsg58/series_details?utm_bmcr_source=community
[5]: https://community.wolfram.com//c/portal/getImageAttachment?filename=WolframUBanner.jpeg&userId=1711324Arben Kalziqi2024-09-03T20:24:31ZInvestigate the complete integrability, solitary wave solutions and solitons of the Gardner equation
https://community.wolfram.com/groups/-/m/t/3275100
![2D and 3D graphs of solutions. Using Symmetries to Investigate the Complete Integrability, Solitary Wave Solutions and Solitons of the Gardner Equation][1]
&[Wolfram Notebook][2]
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=4979Hero.png&userId=20103
[2]: https://www.wolframcloud.com/obj/f5ee122e-2f37-42a2-bd65-109284417b7eWilly Hereman2024-09-16T17:51:37ZAn attempt to use Wolfram's graph rewriting model as a base for machine learning
https://community.wolfram.com/groups/-/m/t/3274891
![enter image description here][1]
&[Wolfram Notebook][2]
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=WLML.png&userId=20103
[2]: https://www.wolframcloud.com/obj/640de84f-14a9-406a-9300-50454708c994Eric Parfitt2024-09-16T14:48:30ZFeynman's solution to the Gaussian integral
https://community.wolfram.com/groups/-/m/t/3274410
&[Wolfram Notebook][1]
[1]: https://www.wolframcloud.com/obj/8ede4243-bd1f-4fed-84d0-10118b956228Roger J Brown2024-09-14T23:12:08ZNumerical solution to Euler Lagrange equation
https://community.wolfram.com/groups/-/m/t/3273996
Hello. I am quite new to wolfram. would anyone mind sharing how to solve the euler lagrange equation (lowest equation), by inputting relevant unknowns from the equations above. Thank you.
![enter image description here][1]
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Screenshot2024-09-14201400.png&userId=3273964Ee Kin Chan2024-09-14T12:26:23Z[GIF] Throw (Hamiltonian cycle on the 120-cell)
https://community.wolfram.com/groups/-/m/t/1273027
![Hamiltonian cycle on the 120-cell][1]
**Throw**
Once again, a Hamiltonian cycle on the vertices of a convex regular 4-polytope, stereographically projected to 3-dimensiona space. This time, it's the 120-cell, which has 600 vertices, which makes for a very long wait if you want to watch the entire cycle.
As usual, we need `ProjectedSphere[]`, which stereographically projects a sphere inside the 3-sphere to 3-space; see [_Inside_][2] for the (long) definition of this function.
Now, inputting all 600 vertices is fairly annoying (**Update:** See [@Ed Pegg][at0]’s reply below for a much cleaner solution). First of all, the vertices of the 24-cell are also vertices of the 120-cell:
twenty4cellvertices =
Normalize /@
DeleteDuplicates[
Flatten[Permutations /@ ({-1, -1, 0, 0}^Join[#, {1, 1}] & /@ Tuples[{0, 1}, 2]), 1]];
Aside from that, there are six other classes of vertices (this was cribbed from the [Wikipedia entry][3] a couple of years ago, and could definitely be re-written in a nicer way):
one20cellvertices1 =
DeleteDuplicates[
Flatten[
Permutations /@ ({1, 1, 1, Sqrt[5]}*{-1, -1, -1, -1}^# & /@
Tuples[{0, 1}, 4]), 1]];
one20cellvertices2 =
DeleteDuplicates[
Flatten[
Permutations /@ ({GoldenRatio^(-2), GoldenRatio, GoldenRatio,
GoldenRatio}*{-1, -1, -1, -1}^# & /@ Tuples[{0, 1}, 4]), 1]];
one20cellvertices3 =
DeleteDuplicates[
Flatten[
Permutations /@ ({GoldenRatio^(-1), GoldenRatio^(-1),
GoldenRatio^(-1), GoldenRatio^2}*{-1, -1, -1, -1}^# & /@
Tuples[{0, 1}, 4]), 1]];
one20cellvertices4 =
DeleteDuplicates[
Flatten[
Outer[
Permute, ({0, GoldenRatio^(-2), 1, GoldenRatio^2}*{-1, -1, -1, -1}^# & /@ Tuples[{0, 1}, 4]),
GroupElements[AlternatingGroup[4]], 1], 1]];
one20cellvertices5 =
DeleteDuplicates[
Flatten[
Outer[
Permute, ({0, GoldenRatio^(-1), GoldenRatio, Sqrt[5]}*{-1, -1, -1, -1}^# & /@ Tuples[{0, 1}, 4]),
GroupElements[AlternatingGroup[4]], 1], 1]];
one20cellvertices6 =
Flatten[
Outer[Permute, ({GoldenRatio^(-1), 1, GoldenRatio, 2}*{-1, -1, -1, -1}^# & /@ Tuples[{0, 1}, 4]),
GroupElements[AlternatingGroup[4]], 1], 1];
And so we combine them all into one long list:
one20cellvertices =
Join[2 Sqrt[2] twenty4cellvertices, one20cellvertices1,
one20cellvertices2, one20cellvertices3, one20cellvertices4,
one20cellvertices5, one20cellvertices6];
Now, as in the case of [_Touch ’Em All_][4] and [_All Day_][5], the idea is to use `FindHamiltonianCycle[]` to find a Hamiltonian cycle. Unfortunately, if you just plug in the `one20cellvertices` without modification, this will just run for hours and never terminate. However, randomly permuting `one20cellvertices` and *then* running `FindHamiltonianCycle[]` seems to almost always work. Here's the code (of course, if you evaluate this, you will get a your own unique cycle, almost certainly different from the one shown in the animation):
sorted120CellVertices =
Module[{v = RandomSample[one20cellvertices], M, g,
cycle},
M = ParallelTable[
If[N[EuclideanDistance[v[[i]], v[[j]]]] == N[3 - Sqrt[5]], 1, 0],
{i, 1, Length[v]}, {j, 1, Length[v]}];
g = AdjacencyGraph[M];
cycle = FindHamiltonianCycle[g];
v[[#[[1]] & /@ (cycle[[1]] /. UndirectedEdge -> List)]]
];
Next, I wanted the motion to be not quite linear, but much closer to linear than what you get by applying [Smoothstep][6] or one of its variants. Of course, $\text{Smoothstep}(t) = a + bt + ct^2 + dt^2$, where the parameters $a,b,c,d$ are given by
Block[{f},
f[t_] := a + b t + c t^2 + d t^3;
Solve[f[0] == 0 && f[1] == 1 && f'[0] == 0 && f[1/2] == 1/2, {a, b, c, d}]
]
So for a less smooth function I just used the parameters which solve the similar system
Block[{f},
f[t_] := a + b t + c t^2 + d t^3;
Solve[f[0] == 0 && f[1] == 1 && f'[0] == 2/3 && f[1/2] == 1/2, {a, b, c, d}]
]
This gives my function `unsmoothstep[]`:
unsmoothstep[t_] := (2 t)/3 + t^2 - (2 t^3)/3;
Finally, then, we can put it all together (notice that `Lighting` is just the standard lighting, but with ambient light which isn't so dark):
DynamicModule[{n = 3, θ, viewpoint = 1/2 {-1, 1, 1},
pts = N[Normalize /@ sorted120CellVertices],
cols = RGBColor /@ {"#06BC40", "#F8B619", "#880085", "#E4F4FD"}},
Manipulate[θ =
ArcCos[1/8 (1 + 3 Sqrt[5])] unsmoothstep[Mod[t, 1]];
Graphics3D[
{Specularity[.8, 30],
Table[
{cols[[Mod[i - Floor[t], n, 1]]],
ProjectedSphere[
RotationMatrix[θ, {pts[[i]], pts[[Mod[i + 1, Length[pts], 1]]]}].pts[[i]], .06]},
{i, 1, Length[pts]}]},
ViewPoint -> {Sin[(
ArcCos[Sqrt[1/6 (3 - Sqrt[5])]] ArcCos[
2 Sqrt[6/(27 + Sqrt[5])]])/
ArcCos[Root[841 - 3512 #1^2 + 2896 #1^4 &, 3]]], 0,
Cos[(ArcCos[Sqrt[1/6 (3 - Sqrt[5])]] ArcCos[
2 Sqrt[6/(27 + Sqrt[5])]])/
ArcCos[Root[841 - 3512 #1^2 + 2896 #1^4 &, 3]]]},
ViewVertical -> {1, 0, 0}, PlotRange -> 10,
SphericalRegion -> True, ViewAngle -> 2 Pi/9, Boxed -> False,
Background -> cols[[-1]], ImageSize -> 500,
Lighting -> {{"Ambient", RGBColor[0.52, 0.36, 0.36]},
{"Directional", RGBColor[0, 0.18, 0.5], ImageScaled[{2, 0, 2}]},
{"Directional", RGBColor[0.18, 0.5, 0.18], ImageScaled[{2, 2, 3}]},
{"Directional", RGBColor[0.5, 0.18, 0], ImageScaled[{0, 2, 2}]},
{"Directional", RGBColor[0, 0, 0.18], ImageScaled[{0, 0, 2}]}}],
{t, 0, n}]
]
The coefficient of `unsmoothstep[t]` in the definition of `θ` is just the angle between adjacent vertices of the 120-cell.
It's easy to use a different number of colors by adjusting `n` to be another divisor of 600 (and of course by adding more colors to `cols`).
[1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=proj45s3hq.gif&userId=610054
[2]: http://community.wolfram.com/groups/-/m/t/1260753
[3]: https://en.wikipedia.org/wiki/120-cell
[4]: http://community.wolfram.com/groups/-/m/t/1263478
[5]: http://community.wolfram.com/groups/-/m/t/1265322
[6]: https://en.wikipedia.org/wiki/Smoothstep
[at0]: https://community.wolfram.com/web/edpClayton Shonkwiler2018-01-27T01:07:16ZMathematica meets the Drake equation
https://community.wolfram.com/groups/-/m/t/3274323
9-14-2024
Wolfram Mathematica applied to the Drake Equation
This equation, first published by Professor Drake, in about 1962, predicts the number of civilizations in our galaxy, the Milky Way, which can communicate using electromagnetic means.
Comments will be appreciated.
After this, I'll introduce sliders and calculate results under different numerical models.
(PS - this was done with help from AI ChatGPT)
(PS - although a molecular biologist, I did my first post-doc work with Drake, Sagan, and Gold at the Cornell space center 1969-1971).
(* Define the variables *)
Rstar = 1.5; (* Star formation rate per year *)
fp = 0.2; (* Fraction of stars with planets *)
ne = 0.1; (* Number of planets capable of supporting life *)
fl = 0.13; (* Fraction of planets where life appears *)
fi = 0.1; (* Fraction of planets with intelligent life *)
fc = 0.1; (* Fraction of civilizations that can communicate *)
L = 1000; (* Length of time in years that civilizations release signals *)
(* Calculate the Drake Equation *)
N = Rstar * fp * ne * fl * fi * fc * L
(* Output the result *)
N
This worked and gave an answer of 0.039Paul Shapshak, PhD2024-09-14T16:49:10ZQuest for improved runtime in searches of primer sequences in whole DNA chromosomes
https://community.wolfram.com/groups/-/m/t/3265520
&[Wolfram Notebook][1]
[1]: https://www.wolframcloud.com/obj/036ab205-9c8b-47a7-8700-48135bd9afcbRichard Frost2024-09-04T05:29:39ZUse different magnetic model
https://community.wolfram.com/groups/-/m/t/3274221
How to specify that I want to use IGRF model instead of automatic when calling GeomagneticModelData ? The help is not clear and it is missing example. I tried various options like following but none of them is correct.
geomagneticNorth = GeomagneticModelData["NorthGeomagneticPole", dates, Method->"IGRF"];
geomagneticNorth = GeomagneticModelData["NorthGeomagneticPole", dates, Method->IGRF];Ján Kolár2024-09-14T12:46:14ZWhy an exported animation is played forward and then backward?
https://community.wolfram.com/groups/-/m/t/3273653
&[Wolfram Notebook][1]
This is the resulting gif image: ![a.gif][2]
[1]: https://www.wolframcloud.com/obj/d7058889-ebe4-440b-aa0d-8e4a87174c54
[2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=a.gif&userId=949223Vladimir Ivanov2024-09-13T19:49:57ZImplementing process algebra: recursive concurrent agents
https://community.wolfram.com/groups/-/m/t/3273073
&[Wolfram Notebook][1]
[1]: https://www.wolframcloud.com/obj/3f8454c1-d4fe-454f-8615-ecc5a5ced4d6Matthew Fairtlough2024-09-12T21:57:07ZHomsy's isothermal laminar flow reactor with power-law fluids
https://community.wolfram.com/groups/-/m/t/3273698
&[Wolfram Notebook][1]
[1]: https://www.wolframcloud.com/obj/60eca957-763f-443c-9a0e-724772d49765Housam Binous2024-09-14T15:13:54ZHomsy's isothermal laminar flow reactor with Prandtl-Eyring fluid
https://community.wolfram.com/groups/-/m/t/3274265
&[Wolfram Notebook][1]
[1]: https://www.wolframcloud.com/obj/114d77f3-bb6a-4e44-bde8-131c6b4011a6Housam Binous2024-09-14T13:39:25ZIssue with solving an optimization model using FindMaximum and mismatch the result from a paper
https://community.wolfram.com/groups/-/m/t/3273919
Hello,
I’m trying to solve an optimization model for growing items based on a paper that uses Excel Solver to obtain the optimal solution. The model has two decision variables: n (frequency of shipments) and T (retailer's replenishment cycle). The paper provides the following equations and parameter values:
![Equation of Total profit][1]
![Parameter Value][2]
![Parameter value Cont.][3]
The optimal values from the paper are:
- n(shipment frequency) = 20
- T(retailer's replenishment cycle) = 1.62 days
- Total profit = 421.14 ($/day)
Right now, I am attempting to solve the same problem in Mathematica, but I’m encountering an issue when using FindMaximum to determine the optimal values for both n and T. Here is the code I am using to find the optimal solution of both n and T
Clear["Global`*"]
L = 4;
w = 0.064;
ww = 2;
R = 250;
Kf = 750;
cf = 0.1;
m = 0.2;
Kp = 500;
hp = 0.05;
Kd = 100;
h = 0.1;
g = 6.87;
q = 0.12;
a = 80;
b = 0.2;
pv = 1;
pf = 2;
pr = 5;
z = 120;
x = 0.9;
s = 0.2;
Tf = - (Log[1/z (k/ww - 1)]/q);
F[d_, n_] =
pr/d ((a (1 - b) (2 L d - d^2))/(2 L))^(1/(1 - b)) - (pv w)/(
d x ww) ((a (1 - b) (2 L d - d^2))/(2 L))^(1/(1 - b)) - Kd/d -
Kp/(n d) - Kf/(
n d) - (h a (1 - b))/(
2 L d) (d + (((1 - b)/(
2 - b)) (2^(1/(1 - b)) L^(1/(1 - b)) d^((2 - b)/(1 - b))) +
d^((3 - b)/(1 - b)))) -
hp/(2 R d) ((a (1 - b) (2 L d - d^2))/(2 L))^(2/(1 - b)) - (
hp (n - 1))/(2 d) ((a (1 - b) (2 L d - d^2))/(2 L))^(2/(
1 - b)) (d ((a (1 - b) (2 L d - d^2))/(2 L))^(1/(1 - b)) - 1/
R) - (cf x + m s)/(d x ww) ((a (1 - b) (2 L d - d^2))/(2 L))^(
1/(1 - b)) (g Tf + g/q (Log[1 + z E^(-q n Tf)] - Log[1 + z]));
FindMaximum[{F[d, n], d > 0}, {d, n}]
However, I encounter an error in my code:
> FindMaximum::nrnum: The function value 598.228 +11.0638 (57.25 (-Log[121]+Log[1+Times[<<2>>]])-57.25 Log[1/120 (-1+Times[<<2>>])]) is not a real number at {d,n} = {0.999994,1.}.
> FindMaximum::grad: Evaluation of the gradient of function Experimental`NumericalFunction[{Hold[-(-(100/d)+(66.7933 (Times[<<2>>]+<<1>>)^1.25)/d-(0.0181019 (<<1>><<1>>^2.5)/d-(0.8 <<1>>)/d-(<<18>> <<1>> <<1>> (-1+n))/d-1250/(d n)-(0.971703 (<<1>>)^1.25 (57.25 Plus[<<2>>]-57.25 Log[<<1>>]))/d)],Block},<<4>>,{<<1>>}] failed at {1.,1.}.
After that, I try to just find the optimal solution of T only by setting the n value with the optimal value from the paper which is 20. However, the total profit and the value of T I obtain are different from the results in the paper. Here is the code I use for this :
Clear["Global`*"]
L = 4;
w = 0.064;
ww = 2;
R = 250;
Kf = 750;
cf = 0.1;
m = 0.2;
Kp = 500;
hp = 0.05;
Kd = 100;
h = 0.1;
g = 6.87;
q = 0.12;
a = 80;
b = 0.2;
pv = 1;
pf = 2;
pr = 5;
z = 120;
n = 20;
x = 0.9;
s = 0.2;
Tf = - (Log[1/z (g/ww - 1)]/q);
F[d_] = pr/d ((a (1 - b) (2 L d - d^2))/(2 L))^(1/(1 - b)) - (pv w)/(
d x ww) ((a (1 - b) (2 L d - d^2))/(2 L))^(1/(1 - b)) - Kd/d -
Kp/(n d) - Kf/(
n d) - (h a (1 - b))/(
2 L d) (d + (((1 - b)/(
2 - b)) (2^(1/(1 - b)) L^(1/(1 - b)) d^((2 - b)/(1 - b))) +
d^((3 - b)/(1 - b)))) -
hp/(2 R d) ((a (1 - b) (2 L d - d^2))/(2 L))^(2/(1 - b)) - (
hp (n - 1))/(2 d) ((a (1 - b) (2 L d - d^2))/(2 L))^(2/(
1 - b)) (d ((a (1 - b) (2 L d - d^2))/(2 L))^(1/(1 - b)) - 1/
R) - (cf x + m s)/(d x ww) ((a (1 - b) (2 L d - d^2))/(2 L))^(
1/(1 - b)) (g n Tf + g/q (Log[1 + z E^(-q n Tf)] - Log[1 + z]));
FindMaximum[{F[d], d > 0}, d]
The result I obtained are : Total profit = -27730 and T = 0.029
Could anyone help me understand why I am getting different results in Mathematica compared to the paper, even after using the same parameter values and the optimal value for n from the paper? Are there any potential issues with the way I’m using FindMaximum or something I might be overlooking in the optimization setup?
In case it was needed, here is the link of the paper : https://www.sciencedirect.com/science/article/abs/pii/S0307904X20306120 (I also attached the paper below)
Any insights would be greatly appreciated! Thank you!
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=2.PNG&userId=3190302
[2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=3.PNG&userId=3190302
[3]: https://community.wolfram.com//c/portal/getImageAttachment?filename=42714.PNG&userId=3190302Shafa Hananta2024-09-14T03:30:23ZFogler's isothermal laminar flow reactor solved using the Chebyshev orthogonal collocation technique
https://community.wolfram.com/groups/-/m/t/3273945
&[Wolfram Notebook][1]
[1]: https://www.wolframcloud.com/obj/92cfb6e9-bbc2-413b-a49b-4b8300fc6647Housam Binous2024-09-14T09:03:12ZFogler's isothermal laminar flow reactor solved using the finite difference method
https://community.wolfram.com/groups/-/m/t/3273933
&[Wolfram Notebook][1]
[1]: https://www.wolframcloud.com/obj/1068c538-7d1d-4346-ad66-5281ea899a43Housam Binous2024-09-14T08:46:37ZAIC and BIC criteria for model selection applied to benzene vapor pressure versus temperature
https://community.wolfram.com/groups/-/m/t/3273909
&[Wolfram Notebook][1]
[1]: https://www.wolframcloud.com/obj/fcc20e27-8436-448b-b50d-73d18a111c40Housam Binous2024-09-13T21:14:31ZDifferent ordinary graphs: creation and visualization
https://community.wolfram.com/groups/-/m/t/3273063
![Different ordinary graphs: creation and visualization][1]
&[Wolfram Notebook][2]
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=6482MainImage.png&userId=20103
[2]: https://www.wolframcloud.com/obj/f0ce9f77-b046-479c-8118-2e653cd2fab1Ed Pegg2024-09-12T20:27:46Z[WSG24] Daily Study Group: Introduction to Calculus
https://community.wolfram.com/groups/-/m/t/3241186
A Wolfram U Daily Study Group on ["Introduction to Calculus"][1] begins on Monday, August 12, 2024.
Join a cohort of fellow mathematics enthusiasts to learn about the fundamentals of calculus from the recent [Introduction to Calculus][2] ebook by John Clark and myself. Our topics will include functions and limits, differential and integral calculus, and practical applications of calculus.
The study group will be led by expert Wolfram U instructor [Luke Titus][4], and I will stop by occasionally to check in with the group. It should be a lot of fun!
No prior Wolfram Language experience is required.
Please feel free to use this thread to collaborate and share ideas, materials and links to other resources with fellow learners.
**Dates**
August 12- September 6, 2024,
11am-12pm CT (4-5pm GMT)
> **[REGISTER HERE][5]**
![enter image description here][6]
[1]: https://www.bigmarker.com/series/introduction-to-calculus-wsg56/series_details?utm_bmcr_source=community
[2]: https://www.wolfram-media.com/products/introduction-to-calculus/
[3]: https://www.wolfram.com/wolfram-u/courses/mathematics/introduction-to-calculus/
[4]: https://community.wolfram.com/web/luket
[5]: https://www.bigmarker.com/series/introduction-to-calculus-wsg56/series_details?utm_bmcr_source=community
[6]: https://community.wolfram.com//c/portal/getImageAttachment?filename=wolframu-banner.png&userId=26786Devendra Kapadia2024-08-05T20:01:27ZTeaching A level assembly language (AQA specification)
https://community.wolfram.com/groups/-/m/t/3273551
&[Wolfram Notebook][1]
[1]: https://www.wolframcloud.com/obj/49e24a38-aea5-4087-aa8d-b51dbdce5368Matthew Fairtlough2024-09-13T10:47:13ZHow do I calculate the conjugation for the whole expression?
https://community.wolfram.com/groups/-/m/t/3273536
This is probably a stupid question, but I haven't found a solution.
I need to conjugatе some sum of terms. Wolfram Mathematica does this for short sums, but not for long sums. How do I perform the conjugation for the whole expression?
&[Wolfram Notebook][1]
[1]: https://www.wolframcloud.com/obj/6a76a04c-9116-4743-998f-7f10625fb982A J2024-09-13T08:56:09ZAbility to see direction of Parametric Curves when plotted?
https://community.wolfram.com/groups/-/m/t/918054
Hello, all!
I have not been able to find any documentation on the docs for a way to see on the direction a single parameter curve has on a certain interval. I have seen many plots that were created using mathematica which led me to believe that I can - at the very least - determine the direction by seeing labeled points, let's say 't', on my plot. My question is, is there a known method that I may use to determine the direction of a parametric curve?
I have been using ParametricPlot[]. The [docs for it][1] hasn't provided any hint of this type of feature. Where should I look to read up on a feature similar to what I have described wanting?
[1]: https://reference.wolfram.com/language/ref/ParametricPlot.htmlAlex Flores2016-09-03T16:06:55ZEuler's number and rolling dice
https://community.wolfram.com/groups/-/m/t/3271711
![dicehill][1]
&[Wolfram Notebook][2]
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=3613simu.png&userId=23928
[2]: https://www.wolframcloud.com/obj/6cdc5566-ec1b-4105-9d8d-39846eeb4efcShenghui Yang2024-09-11T03:46:08ZLagrangian approach to origami vertex analysis: kinematics
https://community.wolfram.com/groups/-/m/t/3273116
![Lagrangian approach to origami vertex analysis: kinematics][1]
&[Wolfram Notebook][2]
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=2244MainImage.png&userId=20103
[2]: https://www.wolframcloud.com/obj/f9705140-8d5e-4a36-aa1f-3341e4664f66Matthew Grasinger2024-09-12T18:44:04ZText mode and typesetting palette changes style
https://community.wolfram.com/groups/-/m/t/3272658
Steps Mathematica 14.1
create new notebook
format > style > text
type any text with one space at the end
select fraction template from typesetting
former typed text is set as numerator
or switch to next line (cursor in column 1)
select fraction template
placed at end of line just typed and not at column 1 in new line
What is wrong in my typing ? All actions done in same cell.Heinz Wanger2024-09-12T10:23:40Z3DPlot not working for a function that contains complex solutions
https://community.wolfram.com/groups/-/m/t/3272727
Hi everyone!
I'm trying to use the 3D plot function, but since my function is non-trivial, I'm not having success, because I'm not sure about the domain (x,y) that makes f(x,y) real.
f[x_, y_] = ((2 e^-x y)/pi) tanh^-1 (x^2/(x^4 - y^4)^(1/2))
Plot3D[f[x, y], {x, a, b}, {y, c, d}]C goulart2024-09-12T09:28:28ZNew trigonometric proof of Pythagorean theorem via law of sines
https://community.wolfram.com/groups/-/m/t/2896079
![change_a][1]
&[Wolfram Notebook][2]
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=2023-04-11_12-02-53.gif&userId=23928
[2]: https://www.wolframcloud.com/obj/22e034a9-9af9-4d06-bff1-b2a092e7a6f9Shenghui Yang2023-04-11T15:20:36ZUninterrupted maximum flow on signalized traffic networks
https://community.wolfram.com/groups/-/m/t/3272429
![Uninterrupted maximum flow on signalized traffic networks][1]
&[Wolfram Notebook][2]
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=MainImage.gif&userId=20103
[2]: https://www.wolframcloud.com/obj/cb9dd3fb-afe5-4232-b0ee-14a412efa191Mel Friedman2024-09-11T20:03:25ZDoes Callout/Labeled work with NumberLinePlot?
https://community.wolfram.com/groups/-/m/t/2269113
Dear All,
NumberLinePlot[Callout[Interval[{0, 10}], "0\[LongDash]10"]]
does not display the expression "0–10". Any idea for a work around?
Best regards,
KMSKlaus-Martin Simonic2021-05-15T09:11:27ZReal-time financial data analysis with Python/Wolfram Language hybrid – overcoming blocking issues
https://community.wolfram.com/groups/-/m/t/3250713
**Background Information:**
I'm in the process of building a workflow for real-time financial data analysis using the Wolfram Language on a budget. Due to the lack of native websocket support in Mathematica, I've decided to create a hybrid system that leverages Python for real-time data acquisition and Mathematica for analysis and processing.
After exploring various options for market data (alpaca, polygon.io, Alpha Vantage, Schwab, etc.), I settled on using the Schwab Developer API with data updates down to the second. This level of detail is crucial for my analysis needs, and it's been the most suitable option I've found without requiring expensive subscriptions.
**The Challenge:**
My main problem arises when integrating the real-time data feed with Mathematica. I am using `SessionSubmit` to run asynchronous tasks in Mathematica that receive data from Python via ZeroMQ. The data is stored in a list (dataList) as it arrives. However, when I attempt to access or display dataList in Mathematica (by typing dataList and pressing Shift+Enter), the notebook blocks and waits for the next data update from the websocket.
I want to be able to access and work with the stored data immediately, without any blocking behavior. Ideally, when I request the data, I should get the current state of dataList instantly, without waiting for the next data update.
**What I’ve Tried:**
I initially used `CreateScheduledTask`, but then switched to `SessionSubmit` for more flexibility. Despite this, the blocking issue persists. I've tried using `Dynamic` to display dataList, but the front end still waits for the next scheduled task to execute before showing the data. I suspect the issue may be related to how Mathematica handles the task and data synchronization, but I haven't found a way to resolve it.
**My Goal:**
I currently have data streaming into the WL notebook in real-time. I need a method to immediately access and display the current contents of dataList, without waiting for the next websocket activity or encountering any blocking behavior. The websocket server is written in Python with ~20 lines of code. I could post it if someone needs. Here is my Mathematica code:
subscribe = SocketConnect[{"127.0.0.1", 63217}, {"ZMQ", "SUB"}];
SetOptions[subscribe, "ZMQ_SUBSCRIBE" -> ""];
dataList = {};
receiveMessage[socket_] := Module[{msg, data},msg = SocketReadMessage[socket];
If[msg === $Failed,Nothing,data =ImportString[ByteArrayToString[msg], "JSON"];
AppendTo[dataList, data];data]];
task = SessionSubmit[ScheduledTask[Module[{data},
data = receiveMessage[subscribe];
Print["Received Data: ", data];],1]];
(* asyncTask =
CreateScheduledTask[Module[{data},
data = receiveMessage[subscribe]; Print[data]],1];
StartScheduledTask[asyncTask];*)
The socket is bound to the local host on port 63217 in Python. Mathematica connects to the same port and receives data continuously. The `recieveMessage` function converts the incoming messages to strings and appends them to dataList. When I ask for dataList, that is where a significant delay takes place. `SessionSubmit` completely blocks and `CreateScheduledTask` waits for the update.
**Python to Wolfram Data Bridge**
import Sconfig,schwabdev,zmq,json
from datetime import datetime
stock_symbol = "SPY"
current_date = datetime.now().strftime("%y-%m-%d")
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:63217")
client = schwabdev.Client(Sconfig.appKey, Sconfig.appSecret)
def my_handler(message, another_var):
print(message)
socket.send_string(json.dumps(message))
streamer = client.stream
streamer.start(my_handler, "test")
streamer.send(streamer.level_one_equities(stock_symbol,
"0,1,2,3,4,5,9"))
This program does the following
- Connects to Schwab's Market Data API using the Python library(scwabdev) built by [Tylere Bowers][1] and my credentials.
- Creates a local ZMQ socket connection bound to port 63217.
- Sends a JSON string through the ZMQ socket every time a message is received from the market data API.
The data I'm sending in this example is for the S&P500 index "SPY" and contains the symbol, bid price, ask price, last price, bid size, ask size, and last size.
**Help:**
This workflow will be incredibly useful for many people if Mathematica can act on that incoming data in real-time. I am looking to fully decouple my working with dataList from the data accumulation effort. If I discover a solution, I'll post it here.
**Update:** Consider the following non-exhaustive table with GPT4o's opinion of market data providers:
![GPT4o Market Data Rankings][2]
Through the Wolfram App, one can access a robust collection of fundamental and technical data with daily granularity. Doing analysis and decision making on a daily(or longer) time scale can be done seamlessly with either the entity framework or `FinancialData` and associated functions. However, analysis with data on time scales < 1 day require the Wolfram Finance Platform and a subscription to one of the first two options in the table. This is not a solution that will work for the average retail investor/trader. $25k/yr wouldn't be so bad if you were making millions but alas, most of us are not quite there yet. Here is one example of an alternative solution I've found to be useful. Solutions require market data from some external source and if you are not doing high frequency(sub-second) micro-transactions, many free options will get the job done. Also, streaming data will require websockets. My choice has been to use Charles Schwab's market data API via Python.
- **Dynamic Trading Chart** - One can create a reliable 10-second chart. Append the data to a .txt file and dynamically import the data. Here is an example:
s = "SPY";
name = s <> "(" <> DateString[{"YearShort", "-", "Month", "-", "Day"}] <> ")";
filePath = "C:\\Team_Python&Wolfram\\" <> name <> ".txt"
data = Import[filePath, "CSV"] /. {timestamp_, o_, h_, l_, c_,v_} :>
{FromUnixTime[timestamp], {o, h, l, c, v}};
DynamicModule[
{currentData = data},
Dynamic[
currentData =
Import[filePath,
"CSV"] /. {timestamp_, o_, h_, l_, c_,
v_} :> {FromUnixTime[timestamp], {o, h, l, c, v}};
TradingChart[currentData],
UpdateInterval -> 10]]
- **Backtesting** - This is where being a WL enthusiast has paid off. The time series functionality surrounding `TradingChart` and associated `FinancialIndicators` has been quite useful in developing and testing strategies. IMHO, Mathematica is way out in front of all the other programming options when it comes to actually doing the analysis.
[1]: https://github.com/tylerebowers/Schwab-API-Python
[2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=table.png&userId=3250476John Martin2024-08-17T21:48:31ZAnalyzing the mass properties of STL files
https://community.wolfram.com/groups/-/m/t/3271862
Recently, I am working on a reverse engineering project. The object is a part similar to a windmill blade, and I need to obtain its accurate surface area. So far, I have used [MIRACO 3D scanner][1] to scan and generate STL files. But I cannot see the mass properties, such as surface details, overall volume, surface area, etc.
I am not familiar with [Mathematica][2]. Has anyone used Mathematica to perform similar analysis? What are the specific steps?
Looking forward to your reply!
[1]: https://www.revopoint3d.com/pages/standalone-3d-scanner-miraco
[2]: https://www.wolfram.com/mathematica/Emily o2024-09-11T08:16:24Z