wolfram-mathematica

Moving an AutoCad DXF solid along a 3D path in Mathematica

五迷三道 提交于 2019-12-10 09:48:22
问题 I came across this post and found belisarius' answer interesting. Wondering whether he someone can post his complete mma code and give some explanation. In general, my question is about how to achieve this kind of annimation/plotting behavior in mma. It looks amazing to me! Many thanks. 回答1: Please tell me if further explanation is needed. x[t_] := {Cos@t, Sin@t, .1 t} /; t <= 3 Pi; x[t_] := {Cos@t, Sin@t, .3 Pi (4 - t/Pi)} /; t > 3 Pi; plotRange = {{-110, 110}, {-110, 110}, {-10, 110}}; z1 =

Changing values in nested lists according to elements in the list

做~自己de王妃 提交于 2019-12-10 09:44:46
问题 I have a list of pairs of values in mathematica, for example List= {{3,1},{5,4}} . How do I change the first element (3 & 5) if the second element does not reach a threshold. For example, if the second parts are below 2 then i wish the first parts to go to zero. so that list then = {{0,1},{5,4}} . Some of these lists are extremely long so manually doing it is not an option, unfortunately. 回答1: Conceptually, the general way is to use Map. In your case, the code would be In[13]:= lst = {{3, 1},

How to improve the performance of this piece of code?

瘦欲@ 提交于 2019-12-10 06:22:58
问题 I'm trying to learn a bit of Julia, after reading the manual for several hours, I wrote the following piece of code: ie = 200; ez = zeros(ie + 1); hy = zeros(ie); fdtd1d (steps)= for n in 1:steps for i in 2:ie ez[i]+= (hy[i] - hy[i-1]) end ez[1]= sin(n/10) for i in 1:ie hy[i]+= (ez[i+1]- ez[i]) end end @time fdtd1d(10000); elapsed time: 2.283153795 seconds (239659044 bytes allocated) I believe it's under optimizing, because it's much slower than the corresponding Mathematica version: ie = 200

Operations “intra” & “inter” lists

十年热恋 提交于 2019-12-10 04:36:08
问题 Please Consider the following : lesDisques={{14.2065, 10.609, 0.974938}, {19.5653, 6.92721, 0.974938}, {30.4607,17.4802, 0.974938}, {27.4621, 10.0393, 0.974938}, {15.915, 20.4278,0.974938}, {28.6921, 5.2132, 1.53205}, {27.0317, 24.8346,1.53205}, {20.8853, 18.8588, 1.53205}} where lesDisques[[#]] is {X,Y,R} frmCorner = {{6.5946, 1.5946`}, {6.5946, 28.4054`}, {60.2162`,28.4054`}, {33.4054`, 28.4054`}} cog = {23.91871026577044`, 15.010499627383863`} scrCenter = {20, 15} frmXY={{6.5946, 1.5946},

Suppressing a trailing “.” in numerical output from Mathematica

笑着哭i 提交于 2019-12-10 04:09:54
问题 Is there some straightforward way to ensure that, when converted to strings, approximate numbers (i.e., numbers with the Real head) won't have a trailing "."? I would like it if they were to only have the decimal point in cases where there's actually a displayed fractional part. The solutions I've found are not robust, and depend on using Precision and Accuracy together NumberForm in an awkward way, or using RealDigits in an even more awkward way. Thanks in advance. 回答1: I've used this in the

'StringCut' to the left or right of a defined position using Mathematica

三世轮回 提交于 2019-12-10 02:50:21
问题 On reading this question, I thought the following problem would be simple using StringSplit Given the following string, I want to 'cut' it to the left of every "D" such that: I get a List of fragments (with sequence unchanged) StringJoin @fragments gives back the original string (but is does not matter if I have to reorder the fragments to obtain this). That is, sequence within each fragment is important, and I do not want to lose any characters. (The example I am interested in is a protein

Symbolic Conditional Expectation in Mathematica

孤人 提交于 2019-12-09 20:11:15
问题 I want to implement the conditional expectation operator. I will use the capital epsilon E to denote the operator. I expect at least the following input (underscore means subscript) E_2[a] E_2[x_1] E_2[x_1 + y_5] E_1[3 a + b - 4 + 2 x_] E_6[x_5 x_7] E_t[x_t] E_t[3 x_{t - 1} x_{t + 2}] to produce the following output a x_1 E_2[y_5] + x_1 -4 + 3 a + b + 2 E_2[x_5] E_6[x_7] x_5 x_t 3 E_t[x_{t + 2}] x_{t - 1} The examples above are not the only input/output pairs I need to produce, but rather

Batch input and output in Mathematica?

亡梦爱人 提交于 2019-12-09 17:51:53
问题 Recently I found some old post on MathGroup where usage of undocumented command-line options -batchinput and -batchoutput is shown: If test.mma contains the following commands: a=2+2 b=10!; a+b then, running Mathematica in batch mode, only output for the first and third commands goes to stdout: # math -batchinput -batchoutput < test.mma 4 3628804 But when trying to reproduce this behavior under Windows I get only first output printed in the console window. What am I doing wrong? 回答1: I tested

What is the simplest way to constraint a built-in function's output in Mathematica? say let Sin returns only odd numbers?

有些话、适合烂在心里 提交于 2019-12-09 17:00:38
问题 For example, for a built-in function in Mathematica, f, originally f[1] gives {1,2,3}, but I want to let Mathematica gives only {1,3}. A simple method for rewritting f is desired. I don't want to define a new function or totally rewrite f or just dealing with original f's outputs. I want to rewite f. Thanks. :) 回答1: You can use the Villegas-Gayley trick for this. For the Sin function: Unprotect[Sin]; Sin[args___]/;!TrueQ[$insideSin]:= Block[{$insideSin=True,result}, If[OddQ[result=Sin[args]]

Avoid repeated calls to Interpolation

穿精又带淫゛_ 提交于 2019-12-09 16:50:20
问题 I want to interpolate a function in mathematica. The function depends on a parameter a , in fact it is the inverse of a function F which also depends on a , so I build my approximation as follows, approx = Interpolation[Table[{F[0.1 n, a], 0.1 n}, {n, -100, 100}]] now I can simply call approx[x] to evaluate the inverse function at a point. Instead I would like to do something like this: Define a function which takes a parameter, G[x_,a_] = "construct the interpolating function, and return the