Community RSS Feed
http://community.wolfram.com
RSS Feed for Wolfram Community showing any discussions in tag Wolfram Scienceshowthread.php?threadid=153 sorted by activeHow do I make a working USB camera discoverable by Mathematica on macbook?
http://community.wolfram.com/groups/-/m/t/1362109
I'm trying to use Mathematica to automate capture and analysis of USB camera images attached to a microscope. I believe the camera to be correctly installed because 1) The camera successfully captures images using the microscope's own software on my macbook pro through the USB directly to the camera and 2) the System Information >> Hardware >> USB >> USB2.0 Camera shows the camera recognized by the macbook pro's system setup.
However, calls to FindDevices[] discover no camera but the iSight built-in camera. (I'm familiar with Mathematica's help files on this and related functions at http://reference.wolfram.com/language/ref/device/Camera.html).
Any advice to make it discoverable?
System Info:
-- Mathematica 11
-- Computer: Macbook Pro
-- OS 10.10.5
-- AmScope MU1400 USB Camera (connected to USB2.0 port on the macbook pro)
Thanks, All.
StephenStephen Guimond2018-06-24T02:01:34ZHow do I plot a semi-lattice so that it has symmetry ... ?
http://community.wolfram.com/groups/-/m/t/1361957
Attached is what I sent Wolfram support ...Mark Tuttle2018-06-24T00:24:08ZMaximize a function with multinomial conditions?
http://community.wolfram.com/groups/-/m/t/1358653
Consider the following code:
Maximize[{1000000/100*(0*a + 25*b + 75*c + 100*d), Reduce[a + b + c + d == 1 && a >= 0 && b >= 0 && c >= 0 && d >= 0 &&
a^101 + 101*a^100*b + 101*a^100*c + 101*100*a^99*b*c + 50*100*a^99*b^2 >= 0.05, {a, b, c, d}, Reals]},
{a, b, c, d}]
Hi. I'm trying to maximize this excpresssion but after several hours it is still runing. Without "reduce" it give me the wrong answer. i need to get the output somthing like this a=0.9538 b=0.0045 c=0.0280 d=0.0137. Maybe I need to use kinda gradient seearch technique?Alex Graham2018-06-19T14:41:32ZDSolve the functions appears with no arguments.
http://community.wolfram.com/groups/-/m/t/1361500
Hello =)
I dont understand the DSolve Error i got on this differntial equations system.
Some ideas?
Thanks!
![enter image description here][1]
[1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=Unbenannt.JPG&userId=1357779ha bla2018-06-23T14:35:13Zhelp with this limit
http://community.wolfram.com/groups/-/m/t/1361876
lim(x->0+) (x^(a) log(x))/(log(1 + x^2) (sin(x^2) - sin^2(x)))
a>0Fabiola Pepe2018-06-23T19:48:37ZSolve this PDEs system?
http://community.wolfram.com/groups/-/m/t/1312709
Hello everybody,
I would like to solve numerically this system of PDEs with the following initial conditions:
![PDEs System][1]
Here is my attempt to do it in Mathematica:
clear[\[Phi], \[Chi]];
sol = NDSolve[{
-2*D[\[Phi][x, t], t, t] +
2 D[\[Phi][x, t], x,
x] + (Exp (\[Phi][x, t])/
2)*((D[\[Chi][x, t], t])^2 - (D[\[Chi][x, t], x])^2) -
Exp[\[Phi][x, t]]*(Exp[\[Phi][x, t]] - 1) == 0,
-D[\[Chi][x, t], t, t] + D[\[Chi][x, t], x, x] -
D[\[Phi][x, t], t]*D[\[Chi][x, t], t] +
D[\[Phi][x, t], x]*D[\[Chi][x, t], x] == 0 ,
\[Phi][x, 0] == Exp[-x^2],
D[\[Phi][0, t], t] == 0,
\[Chi][x, 0] == Exp[-x^2],
D[\[Chi][0, t], t] == 0
},
{\[Phi], \[Chi]}, {x, 0, 10}, {t, 0, 10}];
Plot3D[\[Phi][x, t] /. sol[[1]], {x, 0, 10}, {t, 0, 10}]
Unfortunately it gives me an unexpected error.
I have reread the code many times but I do not find the error.
Can someone help me please?
[1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=PDEsExp.PNG&userId=1310504Jonathan Crabbé2018-03-31T20:48:11ZSolve these differential equations?
http://community.wolfram.com/groups/-/m/t/1292028
I want to solve these differential equations but could not get the simplified answer. Can anyone help me? it will be very appreciated.
See the attached file for your reference.Mirza Farrukh Baig2018-02-26T07:32:35ZHow to export data to Matlab
http://community.wolfram.com/groups/-/m/t/1361727
I have a Mathematica code that gives several variables, e.g., output1 and output2. output1 is a list of 10 values and output2 is a matrix with 10 rows and 4 columns . Is there a way of exporting these data to Matlab or I should export them to a file and then call them from Matlab?mohamed alzenad2018-06-23T15:31:53ZPlot the result of NDSolve as a RectangleChart3D?
http://community.wolfram.com/groups/-/m/t/1323155
Hi,
I request a solution to my problem where i want to plot the either the energy (x^2) or the signal itself (x) which is being the solution of a differential solution. I am successful only placing the phase-plane of a 2D system but the bar graph on the right does not shown anything. The code is
splot = StreamPlot[{y, -Sin[x] - .25 y}, {x, -4, 4}, {y, -3, 3}];
Manipulate[
Grid[{{Show[splot,
ParametricPlot[
Evaluate[
First[{x[t], y[t]} /.
NDSolve[{x'[t] == y[t], y'[t] == -Sin[x[t]] - .25 y[t],
Thread[{x[0], y[0]} == point]}, {x, y}, {t, 0, T}]]], {t,
0, T}, PlotStyle -> Red]],
RectangleChart3D[{{0.25, 1,
Evaluate[
First[{x[t]} /.
NDSolve[{x'[t] == y[t], y'[t] == -Sin[x[t]] - .25 y[t],
Thread[{x[0], y[0]} == point]}, {x, y}, {t, 0,
T}]]]}, {0.25, 1,
Evaluate[
First[{y[t]} /.
NDSolve[{x'[t] == y[t], y'[t] == -Sin[x[t]] - .25 y[t],
Thread[{x[0], y[0]} == point]}, {x, y}, {t, 0, T}]]]}},
ChartLegends -> {"x[t]", "y[t]"}, PlotRange -> {0, 1},
ImageSize -> {200, 250}, ChartStyle -> {Red, Green},
AspectRatio -> 1, BarSpacing -> 0.2, Axes -> False]}}], {{T, 90},
1, 100}, {{point, {2, 1.0}}, Locator}, SaveDefinitions -> True]Salman Zaffar2018-04-19T11:54:06ZA primer on Association and Dataset
http://community.wolfram.com/groups/-/m/t/1167544
*NOTE: all Wolfram Language code and data are available in the attached notebook at the end of the post.*
----------
For my class this fall, I developed a little primer on Association and Dataset that I think might be useful for many people. So, I'm sharing the attached notebook. It's somewhat about the concepts embedded inside these features. It's intended for people at an beginner-intermediate level of Mathematica/Wolfram Language programming but might be of value even to some more advanced users who have not poked about the Dataset functionality.
The sections of the notebook are:
1. The world before Associations and Datasets
2. Datasets without Associations
3. Enter the Association
4. Creating a Dataset from a List of Associations
5. Nice queries with Dataset
6. Query
7. Some Recipes
#The world before Associations and Datasets#
Here' s an array of data. The data happens to represent the cabin class, age, gender, and survival of some of the passengers on the Titanic.
t = {{"1st", 29, "female", True}, {"1st", 30, "male", False}, {"1st",
58, "female", True}, {"1st", 52, "female", True}, {"1st", 21,
"female", True}, {"2nd", 54, "male", False}, {"2nd", 29, "female",
False}, {"3rd", 42, "male", False}};
As it stands, our data is a List of Lists.
Head[t]
> List
Head /@ t
> {List, List, List, List, List, List, List, List}
Suppose I wanted to get the second and fifth rows of the data. This is how I could do it.
t[[{2, 5}]]
> {{"1st", 30, "male", False}, {"1st", 21, "female", True}}
Suppose we want to group the passengers by gender and then compute the mean age. We could do this with the following pretty confusing code.
Use and enjoy. Constructive feedback appreciated.
grouped = GatherBy[t, #[[3]] &];
justTheAges = grouped[[All, All, 2]];
Mean /@ justTheAges
> {189/5, 42}
Or I could write it as a one liner this way.
Map[Mean, GatherBy[t, #[[3]] &][[All, All, 2]]]
> {189/5, 42}
But either way, realize that I have to remember that gender is the third column and that age is the second column. When there is a lot of data, this can get hard to remember.
#Datasets without Associations#
I could, if I wanted, convert this data into a Dataset. I do this below simply by wrapping Dataset about t. You see there is now some formatting about the data. But there are no column headers (because no one has told Dataset what to use). And there are no row headers, again because no one has told Dataset what to use.
t2 = Dataset[t]
![enter image description here][1]
The head of the expression has changed.
Head[t2]
> Dataset
Now, I can now access the data in a different way.
Query[{2, 5}][t2]
![enter image description here][2]
Or, I can do this. Mathematica basically converts this expression into Query[{2,5}][t2]. The expression t2[{2,5}] is basically syntactic sugar.
t2[{2, 5}]
![enter image description here][3]
##Digression : Using Query explicitly or using syntactic sugar##
Why, by the way would anyone use the longer form if Mathematica does the work for you? Suppose you want to store a Dataset operation -- perhaps a complex series of Dataset operations -- but you want it to work not just on a particular Dataset but on any Dataset (that is compatible). Here's how you could do it.
q = Query[{2, 5}]
> Query[{2, 5}]
q[t2]
![enter image description here][4]
Now, let' s create a permutation of the t2 Dataset so that the rows are scrambled up.
t2Scrambled = t2[{1, 4, 8, 3, 2, 7, 5}]
![enter image description here][5]
We can now run the q operation on t2Scrambled. Notice that the output has changed even though the query has stayed the same.
q[t2Scrambled]
![enter image description here][6]
We can also generate Query objects with functions. Here's a trivial example. There are very few languages of which I am aware that have the ability to generate queries by using a function. The one other example is Julia.
makeASimpleQuery[n_] := Query[n]
makeASimpleQuery[{3, 4, 7}][t2]
![enter image description here][7]
##MapReduce operations on Dataset objects##
Now, if I want to know the mean ages of the genders I can use this code. This kind of grouping of data and then performing some sort of aggregation operation on the groups is sometimes known as a MapReduce. (I'm not a fan of the name, but it is widely used). It's also sometimes known as a rollup or an aggregation.
Query[GroupBy[#[[3]] &], Mean, #[[2]] &][t2]
![enter image description here][8]
Or this shorthand form in which the Query is constructed.
t2g = t2[GroupBy[#[[3]] &], Mean, #[[2]] &]
![enter image description here][9]
I think this is a little cleaner. But we still have to remember the numbers of the columns, which can be challenging.
By the way, just to emphasize how we can make this all functional, here's a function that creates a query that can run any operation (not just computing the mean) on the Dataset grouped by gender and then working on age.
genderOp[f_] := Query[GroupBy[#[[3]] &], f, #[[2]] &]
genderOp[Max][t2]
![enter image description here][10]
To test your understanding, see if you can find the minimum age for each class of passenger on the Titanic in our Dataset **t2**.
Query[GroupBy[#[[1]] &], Min, #[[2]] &][t2]
![enter image description here][11]
#Enter the Association#
##Review of Association##
If you feel comfortable with Associations, you can skip this section; otherwise read it carefully. Basically the key to understanding most Dataset operations is understanding Associations.
###Construction of Associations###
Now let' s alter the data so that we don't have to remember those facts. To do this we will create an **Association**. Here's an example called **assoc1**. Notice that we do so by creating a sequence of rules and then wrapping it in an Association head. Notice that the standard output does not preserve the word "Association" as the head but, just as List is outputted as stuff inside curly braces, Association is outputted as stuff inside these funky "<|" and "|>" glyphs.
assoc1 = Association["class" -> "1st", "age" -> 29, "gender" -> "female", "survived" -> True]
> <|"class" -> "1st", "age" -> 29, "gender" -> "female", "survived" -> True|>
I could equivalently have created a list of rules rather than a sequence. Mathematica would basically unwrap the **List** and create a sequence.
assoc1L = Association[{"class" -> "1st", "age" -> 29, "gender" -> "female", "survived" -> True}]
> <|"class" -> "1st", "age" -> 29, "gender" -> "female", "survived" -> True|>
We can use **AssociationThread** to create Associations in a different way. The first argument is the list of things that go on the left hand side of the Rules -- the "keys" -- and the second argument is the list of things that go on the right hand side of the Rules -- the "values".
assoc1T = AssociationThread[{"class", "age", "gender", "survived"}, {"1st", 29, "female", True}]
> <|"class" -> "1st", "age" -> 29, "gender" -> "female", "survived" -> True|>
Now let's use **AssociationThread** function to create a list of Associations similar to our original data.
convertListToAssociation =
list \[Function]
AssociationThread[{"class", "age", "gender", "survived"}, list]
> Function[list, AssociationThread[{"class", "age", "gender", "survived"}, list]]
I start with t and Map the **convertListToAssociation** function over the rows of the data. I end up with a list of Associations.
t3 = Map[convertListToAssociation, t]
![enter image description here][12]
###Keys and Values###
Associations have keys and values. These data structures are used in other computer languages but known by different names: *Python* and *Julia* call them dictionaries. *Go* and *Scala* call them maps. *Perl* and *Ruby* call them hashes. *Java* calls it a *HashMap*. And *Javascript* calls it an object. But they all work pretty similarly. Anyway, the keys of an **Association** are the things on the left hand side of the Rules.
Keys[assoc1]
> {"class", "age", "gender", "survived"}
And the values of an Association are the things on the right hand side of the Rules.
Values[assoc1]
> {"1st", 29, "female", True}
That' s about all there is too it. Except for one thing. Take a look at the input and output that follows.
assoc2 = Association["a" -> 3, "b" -> 4, "a" -> 5]
> <|"a" -> 5, "b" -> 4|>
You can' t have duplicate keys in an Association. So, when Mathematica confronts duplicate keys, it uses the last key it saw. You might think this is a minor point, but it is actually very important in coding. We will see why soon.
###Nested Associations###
A funny thing happens if you nest an **Association** inside another **Association**.
Association[assoc1, assoc2]
> <|"class" -> "1st", "age" -> 29, "gender" -> "female", "survived" -> True, "a" -> 5, "b" -> 4|>
You end up with a single un - nested (flat) association. That's a little unusual for Mathematica, but we can exploit this flattening as a way of adding elements to an Association.
Association[Association["dances" -> False], assoc1]
> <|"dances" -> False, "class" -> "1st", "age" -> 29, "gender" ->
> "female", "survived" -> True|>
Or, here' s a function that exploits the flattening to add elements to an **Association**.
addstuff = Association[#, "dances" -> False, "sings" -> True] &
> Association[#1, "dances" -> False, "sings" -> True] &
addstuff[assoc1]
> <|"class" -> "1st", "age" -> 29, "gender" -> "female", "survived" -> True, "dances" -> False, "sings" -> True|>
###Extracting Values from Associations###
Just as the values contained in a **List** can be accessed by using the **Part** function, the values contained in an **Association** can likewise be accessed. Suppose, for example that I wanted to compute double the age of the person in **assoc1**.
It turns out there are a lot of ways of doing this. The first is to treat the Association as a list except that the indices, instead of being integers, are the "keys" that are on the left hand side of the rules.
2*Part[assoc1, "age"]
> 58
2*assoc1[["age"]]
> 58
A second way is to use Query. We can wrap the "key" in the head **Key** just to make sure Mathematica understands that the thing is a Key.
2*Query[Key["age"]][assoc1]
> 58
Usually we can omit the Key and everything works fine.
2*Query["age"][assoc1]
> 58
A third way is to write a function that has an association as its argument.
af = Function[Slot["age"]]
> "#age &"
Now look what we can do.
2*Query[af][assoc1]
> 58
We can shorten this approach by using a simpler syntax for a function.
2*Query[#age &][assoc1]
> 58
Note, though that this still will not work. Basically, Mathematica is confused. It thinks the function itself is the key.
2*assoc1[af]
> 2 Missing["KeyAbsent", #age &]
But here' s a simple workaround. For very simple functions, I can just use the name of the key.
2*assoc1["age"]
> 58
##A Note on Slot Arguments##
And please pay attention to this : sometimes the Mathematica parser gets confused when it confronts a "slot argument" written as #something. If you see this happening, write it as Slot["something"].
Slot["iamaslot"] === #iamaslot
> True
Here' s another problem. What if the key in the association has spaces or non-standard characters in it. Any of these, for example, are perfectly fine keys: the string "I have a lot of spaces in me", the string "I_have_underscores", the symbol True, the integer 43. But if we try to denote those keys by putting a hash in front of them, it will lead to confusion and problems.
problemAssociation = Association["I have a lot of spaces in me" -> 1, "I_have_underscores" -> 2, True -> 3, 43 -> 4]
> <|"I have a lot of spaces in me" -> 1, "I_have_underscores" -> 2,
True -> 3, 43 -> 4|>
{Query[#I have a lot of spaces in me &][problemAssociation],
Query[#I _have _underescores &][problemAssociation]}
![enter image description here][13]
Here' s a solution.
{Query[Slot["I have a lot of spaces in me"] &][problemAssociation],
Query[Slot["I_have_underscores"] &][problemAssociation]}
> {1, 2}
Here' s how we solve the use of True and an integer as keys. We preface them with **Key**.
{Query[#True &][problemAssociation], Query[#43 &][problemAssociation]}
![enter image description here][14]
{Query[Key[True]][problemAssociation],
Query[Key[43]][problemAssociation]}
> {3, 4}
##Working with Associations and Lists of Associations##
Here' s something we can do with the data in the form of an Association. I could ask for the gender of the person in the third row as follows. Notice I did not have to remember that "gender" was generally in the third position.
t3[[3]][["gender"]]
> "female"
So, even if I scramble the rows, I can still use the same code.
t3Scrambled = Map[convertListToAssociation, t[[All, {4, 1, 3, 2}]]]
![enter image description here][15]
t3Scrambled[[3]][["gender"]]
> female
I could also group the people according to their cabin class. Here I use Query on a list of Associations.
Query[GroupBy[#class &]][t3]
![enter image description here][16]
Again, the following code, which does not explicitly use **Query**, won' t work. Basically, nothing has told Mathematica to translate t3[stuff___] \[RightArrow]Query[stuff][t3]. If t3 had a head of Dataset, Mathematica would know to make the translation.
t3[GroupBy[#class &]]
![enter image description here][17]
I can also get certain values for all the Associations in a list of Associations.
Query[All, #age &][t3]
> {29, 30, 58, 52, 21, 54, 29, 42}
I can also map a function onto the result. I don't have to go outside the Query form to do so.
Query[f, #age &][t3]
> f[{29, 30, 58, 52, 21, 54, 29, 42}]
Or, without exiting the Query form, I can map a function onto each element of the result.
Query[Map[f], #age &][t3]
> {f[29], f[30], f[58], f[52], f[21], f[54], f[29], f[42]}
I could also do the same thing as follows.
Query[All, #age &, f][t3]
> {f[29], f[30], f[58], f[52], f[21], f[54], f[29], f[42]}
#Creating a Dataset from a List of Associations#
To get full use out of Query and to permit syntactic shorthands, we need for Mathematica to understand that the list of Associations is in fact a Dataset. Here' s all it takes.
d3 = Dataset[t3]
![enter image description here][18]
We can recover our original list of associations by use of the **Normal** command.
t3 === Normal[d3]
> True
With the data inside a Dataset object we now have pretty formatting. But we have more.
We can still do this. We get the same result but in a more attractive form.
d3g = Query[GroupBy[#class &]][d3]
![enter image description here][19]
But now this shorthand works too.
d3g = d3[GroupBy[#class &]]
![enter image description here][20]
And compare these two elements of code. When the data is in the form of a dataset, Mathematica understands that the stuff in the brackets is not intended as a key but rather is intended to be transformed into a Query.
{Query[#age &][t3[[1]]], d3[[1]][#age &]}
> {29, 29}
##A Dataset that is an Association of Associations##
Let' s look under the hood of **d3g**.
d3gn = Normal[d3g]
![enter image description here][21]
Note : if you *really* want to look under the hood of a **Dataset** ask to see the **Dataset** in **FullForm**. You can also get more information by running the undocumented package Dataset`, but this is definitely NOT recommended for the non-advanced user.
What we see is an Association in which each of the values is itself a list of Associations.
We can map a function over d3gn.
Map[f, d3gn]
![enter image description here][22]
I can of course do the mapping within the **Query** construct.
Query[All, f][d3gn]
![enter image description here][23]
If I try synactic sugar, it doesn' t work because d3gn is not a Dataset.
d3gn[All, f]
> Missing["KeyAbsent", All]
But, if I use the Dataset version, it does work. (The first line may be an ellipsis depending on your operating system and display, but if you look under the hood it looks just like the values for 2nd and 3rd. I have no idea why an ellipsis is being inserted.
d3g[All, f]
![enter image description here][24]
##A Dataset that just has a single Association inside.##
We can also have a Dataset that just has a single Association inside. Mathematica presents the information with the keys and values displayed vertically.
Dataset[d3[[1]]]
![enter image description here][25]
In theory, we could have a Dataset that just had a single number inside it.
Dataset[6]
![enter image description here][26]
#Nice queries with Dataset#
Now I can construct a query that takes a dataset and groups it by the gender column. It then takes each grouping and applies the Mean function to at least part of it. What part? The "age" column part. Notice that I no longer have to remember that gender is the third column and age is the second column.
qd = Query[GroupBy[#gender &], Mean, #age &]
> Query[GroupBy[#gender &], Mean, #age &]
Now I can run this query on t3.
qd[d3]
![enter image description here][27]
We can now learn a lot about Query. So long as our data is in the form of a Dataset we can write the query as either a formal Query or use syntactic sugar.
#Query#
A major part of working with data is to understand **Query**. Let's start with a completely abstract **Query**, that we will call **q1**.
q1 = Query[f];
Now let' s run q1 on t3.
q1[t3]
![enter image description here][28]
We end up with a list of Associations that has f wrapped around it at the highest level. It's the same as if I wrote the following code.
f[t3] === q1[t3]
> True
Now, let' s write a **Query** that applies the function g at the top level of the list of associations and the function **f** at the second level, i.e. to each of the rows. Why does it work at the second level? Because it's the second argument to **Query**.
q2 = Query[g, f];
q2[t3]
![enter image description here][29]
The result is the same as if I mapped **f** onto t3 at its first level and then wrapped **g** around it.
g[Map[f, t3, {1}]] === q2[d3]
Query[All, MapAt[StringTake[#, 1] &, #, {{"class"}, {"gender"}}] &][d3]
Here' s a function **firstchar** that takes the first character in a string.
firstchar = StringTake[#, 1] &
> StringTake[#1, 1] &
Now, let' s construct a query **cg1** that applies **firstchar** to the class and gender keys in each row.
cg1 = Query[All,
a \[Function] MapAt[firstchar, a, {{"class"}, {"gender"}}]]
> Query[All, Function[a, MapAt[firstchar, a, {{"class"}, {"gender"}}]]]
We apply **cg1** to our little dataset **d3**.
cg1[d3]
![enter image description here][30]
What if we want to apply the same function to every element of the Dataset. We just apply it at the lowest level. Here's one way.
Query[Map[f, #, {-1}] &][d3]
![enter image description here][31]
We can also combine it with column wise and entirety wise operations. For reasons that are not clear, Mathematica can't understand this as a Dataset and returns the Normal form.
Query[(Map[f, #, {-1}] &) /* entiretywise, columnwise][d3]
![enter image description here][32]
Here' s how we could actually a multilevel **Query**.
Suppose we want to write a function that computes the fraction of the people in this little dataset that survived. The first step is simply going to be to extract the survival value and convert it to 1 if True and 0 otherwise. There's a built in function Boole that does this.
{Boole[True], Boole[False]}
> {1, 0}
q3 = Query[something,
assoc \[Function] assoc["survived"] /. {True -> 1, _ -> 0}]
> Query[something, Function[assoc, assoc["survived"] /. {True -> 1, _
> -> 0}]]
q3[t3]
> something[{1, 0, 1, 1, 1, 0, 0, 0}]
So, now we have something wrapping a list of 1 s and 0 s. By making **something** the **Mean** function, we can achieve our result.
q4 = Query[Mean, Boole[#survived] &]
> Query[Mean, Boole[#survived] &]
q4[d3]
> 1/2
We can also examine survival by gender. Notice that **Query** is a little like **Association**: it gets automatically flattened.
Query[GroupBy[#gender &], q4][t3]
> <|"female" -> 4/5, "male" -> 0|>
If the data is held in a **Dataset**, we can also write the final step as follows.
d3[GroupBy[#gender &], q4]
![enter image description here][33]
Notice that even if we omit the "Query", this code works. Mathematica just figures out that you meant Query.
The code immediately above is in the form we typically see and often use.
#Some Recipes#
titanic = ExampleData[{"Dataset", "Titanic"}]
![enter image description here][34]
How to add a value to the Dataset based on values external to the existing columns.
Here' s some additional data. Notice that the data is the same length as the titanic dataset.
stuffToBeAdded =
Table[Association["id" -> i,
"weight" -> RandomInteger[{80, 200}]], {i, Length[titanic]}]
![enter image description here][35]
We use **Join** at level 2.
augmentedTitanic = Join[titanic, stuffToBeAdded, 2]
![enter image description here][36]
##How to add a column to a Dataset based on values in the existing columns and to do so row-wise##
Notice that the query below does NOT change the value of the titanic dataset. To change the value of the titanic dataset, one would need to set titanic to the result of the computation. Remember, Mathematica generally does not have side effects or do modifications in place.
Query[All, Association[#, "classsex" -> {#class, #sex}] &][titanic]
![enter image description here][37]
We can add multiple columns this way.
Query[All,
Association[#, "classsex" -> {#class, #sex},
"agesqrt" -> Sqrt[#age]] &][titanic]
![enter image description here][38]
##How to change the value of an existing column : row - wise##
Age everyone one year.
Query[All, Association[#, "age" -> #age + 1] &][titanic]
![enter image description here][39]
How to change the value of columns selectively.
Query[All,
Association[#,
"age" -> If[#sex === "male", #age + 1, #age]] &][titanic]
![enter image description here][40]
How to create a new column based on some aggregate operator applied to another column.
With[{meanAge = Query[Mean, #age &][titanic]},
Query[All,
Association[#, "ageDeviation" -> #age - meanAge] &]][titanic]
![enter image description here][41]
Can you develop your own recipes?
[1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=17751.png&userId=20103
[2]: http://community.wolfram.com//c/portal/getImageAttachment?filename=47222.png&userId=20103
[3]: http://community.wolfram.com//c/portal/getImageAttachment?filename=60813.png&userId=20103
[4]: http://community.wolfram.com//c/portal/getImageAttachment?filename=83664.png&userId=20103
[5]: http://community.wolfram.com//c/portal/getImageAttachment?filename=44435.png&userId=20103
[6]: http://community.wolfram.com//c/portal/getImageAttachment?filename=105416.png&userId=20103
[7]: http://community.wolfram.com//c/portal/getImageAttachment?filename=49777.png&userId=20103
[8]: http://community.wolfram.com//c/portal/getImageAttachment?filename=16898.png&userId=20103
[9]: http://community.wolfram.com//c/portal/getImageAttachment?filename=28239.png&userId=20103
[10]: http://community.wolfram.com//c/portal/getImageAttachment?filename=262710.png&userId=20103
[11]: http://community.wolfram.com//c/portal/getImageAttachment?filename=749611.png&userId=20103
[12]: http://community.wolfram.com//c/portal/getImageAttachment?filename=209912.png&userId=20103
[13]: http://community.wolfram.com//c/portal/getImageAttachment?filename=925313.png&userId=20103
[14]: http://community.wolfram.com//c/portal/getImageAttachment?filename=851614.png&userId=20103
[15]: http://community.wolfram.com//c/portal/getImageAttachment?filename=627315.png&userId=20103
[16]: http://community.wolfram.com//c/portal/getImageAttachment?filename=679516.png&userId=20103
[17]: http://community.wolfram.com//c/portal/getImageAttachment?filename=674717.png&userId=20103
[18]: http://community.wolfram.com//c/portal/getImageAttachment?filename=707518.png&userId=20103
[19]: http://community.wolfram.com//c/portal/getImageAttachment?filename=1053319.png&userId=20103
[20]: http://community.wolfram.com//c/portal/getImageAttachment?filename=579820.png&userId=20103
[21]: http://community.wolfram.com//c/portal/getImageAttachment?filename=980221.png&userId=20103
[22]: http://community.wolfram.com//c/portal/getImageAttachment?filename=450322.png&userId=20103
[23]: http://community.wolfram.com//c/portal/getImageAttachment?filename=113723.png&userId=20103
[24]: http://community.wolfram.com//c/portal/getImageAttachment?filename=932624.png&userId=20103
[25]: http://community.wolfram.com//c/portal/getImageAttachment?filename=754825.png&userId=20103
[26]: http://community.wolfram.com//c/portal/getImageAttachment?filename=836826.png&userId=20103
[27]: http://community.wolfram.com//c/portal/getImageAttachment?filename=393227.png&userId=20103
[28]: http://community.wolfram.com//c/portal/getImageAttachment?filename=577928.png&userId=20103
[29]: http://community.wolfram.com//c/portal/getImageAttachment?filename=158329.png&userId=20103
[30]: http://community.wolfram.com//c/portal/getImageAttachment?filename=984930.png&userId=20103
[31]: http://community.wolfram.com//c/portal/getImageAttachment?filename=664831.png&userId=20103
[32]: http://community.wolfram.com//c/portal/getImageAttachment?filename=1090332.png&userId=20103
[33]: http://community.wolfram.com//c/portal/getImageAttachment?filename=450733.png&userId=20103
[34]: http://community.wolfram.com//c/portal/getImageAttachment?filename=740234.png&userId=20103
[35]: http://community.wolfram.com//c/portal/getImageAttachment?filename=143835.png&userId=20103
[36]: http://community.wolfram.com//c/portal/getImageAttachment?filename=36.png&userId=20103
[37]: http://community.wolfram.com//c/portal/getImageAttachment?filename=37.png&userId=20103
[38]: http://community.wolfram.com//c/portal/getImageAttachment?filename=38.png&userId=20103
[39]: http://community.wolfram.com//c/portal/getImageAttachment?filename=39.png&userId=20103
[40]: http://community.wolfram.com//c/portal/getImageAttachment?filename=40.png&userId=20103
[41]: http://community.wolfram.com//c/portal/getImageAttachment?filename=41.png&userId=20103Seth Chandler2017-08-20T19:26:30ZPlease share neural network illustrations
http://community.wolfram.com/groups/-/m/t/1360660
*(A version of the same/similar [MSE post](https://mathematica.stackexchange.com/q/175686/34008), which was met with a certain reluctance to be given answers.)*
Please share neural networks diagrams you have made in Mathematica / WL. Here is an example:
ClearAll[a];
ns = {3, 4, 6, 4, 1};
nodes = MapIndexed[Function[{n, i}, Prepend[#, i[[1]]] & /@ Array[a, {n}]], ns];
edges = Map[Outer[Rule, #[[1]], #[[2]]] &, Partition[nodes, 2, 1]];
colors = Map[# -> ColorData[11, "ColorList"][[#[[1]]]] &, Flatten[nodes]];
Graph[Flatten[edges], VertexSize -> 0.3, VertexStyle -> colors]
[![enter image description here][1]][1]
But, [here are some more examples](https://www.google.com/search?q=neural+network&source=lnms&tbm=isch&).
The question is intentionally given with a short explanation and a link to examples. I wanted to gather some pictures of neural networks made with Mathematica/WL for a few presentations about deep learning. (Using Mathematica/WL's neural networks framework; [like this one](http://community.wolfram.com/groups/-/m/t/1356138).) I was somewhat surprised that such images were not easy to find.
What I am interested are images like these:
[![enter image description here][2]](https://www.tritytech.com/courses/by-software-platform/python-courses/65-python-for-machine-and-deep-learning.html)
[![enter image description here][3]](http://www.mdpi.com/2073-4441/10/1/4)
[![enter image description here][4]](http://www.mdpi.com/2076-3417/7/5/447)
[1]: https://i.stack.imgur.com/qgvjz.png
[2]: https://i.stack.imgur.com/GbsQd.png
[3]: https://i.stack.imgur.com/BHR1Gm.png
[4]: https://i.stack.imgur.com/Yp2Ncm.jpgAnton Antonov2018-06-21T12:33:42ZObtain temperature values from the pixel values of a thermal image?
http://community.wolfram.com/groups/-/m/t/1360447
How do I obtain temperature values from the pixel values obtained in thermal image?Assuming the thermal image obtained is in Grey scale formatsampath rachumallu2018-06-21T07:14:21ZIntegrate an unknown function?
http://community.wolfram.com/groups/-/m/t/1361227
The following is the integral:
Integrate[(-1/g[z]^2 + 2/g[z]^3) *(D[g[z], z, z]), z]
This returns:
![enter image description here][1]
[1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=MyIntegral.bmp&userId=610498
where g(z) is an unknown function of z. How can I modify the code in order to solve this integral?
ThanksHamidreza Khataee2018-06-22T02:56:48ZSlicing vector-valued TimeSeries
http://community.wolfram.com/groups/-/m/t/1361611
I'd like to ListPlot a subset of the value elements of a vector-valued TimeSeries.
Towards this end, is it possible to reduce the value dimensionality of a vector-valued time series (TimeSeries)?
The documentation shows how to slice across paths (in TemporalData) and times. But I have not yet found instructions on how to slice through values if they are vectors (instead of scalars).
Thank you,
VinceVincent Virgilio2018-06-22T14:45:36ZSpecify a stochastic difference equation for solving?
http://community.wolfram.com/groups/-/m/t/1360695
I've been trying to get full solutions to time series difference equations with a stochastic component. But my syntax has been off.
Solving a basic time series autoregressive order 1 function AR(1):
$$ y_t = a_0 + a_1y_{t-1} + \epsilon_t $$
How could I go about solving this where the output would be the particular + all homogenous solutions? Such that for the above function I could specify initial conditions whereby the solution output is:
$$ y_t = a_0 \sum_{i=0}^{t-1}{a_i^i} + a_1^t y_0 + \sum_{i=0}^{t-1}{a_i^i} \epsilon_{t-i} $$
Or then for the same function *without* initial conditions **but $ a_1<1$**:
$$ y_t = \frac{a_0}{1-a_1} + \sum_{i=0}^{\infty}{a_1^i} \epsilon_{t-1} + Aa_1^t $$
Even if I could get the notation to incorporate time correctly that'd be a great help. I've been trying to use DifferenceDelta in combination with with DSolve but can't get it to work. Of course, moving forward the problems would extend to higher order ARMA process'. But I imagine once the functional form is entered correctly I could extend it a similar fashion?
Any help or suggestions appreciated.Ali Sheikhpour2018-06-21T13:46:48ZUser survey: What version of M are you using?
http://community.wolfram.com/groups/-/m/t/1361199
Hello everyone,
I created a survey to try to determine what versions of Mathematica people are most commonly using. Please fill it out, and forward the survey to any friends or colleagues who also use Mathematica.
https://docs.google.com/forms/d/e/1FAIpQLSdmiNCQH5mBKYWAf9V6DzcuidsRRqX3LOg2_C6Hr0eKDxunog/viewform
Motivation:
This information will be useful for package authors to decide what versions of Mathematica to support. For example, my MaTeX and IGraph/M packages still support Mathematica 10.0. I would like to know how many users are left out if I make e.g. M11.1 the minimum requirement. I believe other package authors would find these statistics useful too. [Similar statistics are available e.g. for Android versions.](https://developer.android.com/about/dashboards/)
If enough people respond, results will be posted in this thread in a couple of weeks.Szabolcs Horvát2018-06-22T13:27:11ZA quick question about futures and forwards
http://community.wolfram.com/groups/-/m/t/1360607
We discuss similarity and differences between interest rates forwards and futures. Differences are explained not through products mechanics, but as expectations based on different probability measures. We show that forward rates are not risk-neutral expectations of Libor rates as their measures are not identical. Several drift correction schemes are presented to show the conditions under which both rates converge.
enter image description here
Introduction
Futures and forwards are one of the oldest financial instruments. They represent the family of simplest derivative products and are well-known to all members of financial community. Despite being around for a long time, the question why and how they differ is still not completely understood. We therefore look at these products again and bring theoretical reasoning into the scope to show that futures and forwards are essentially different products with their own pricing dynamics driven by different probability measures. Although forwards and futures exist in various of financial classes, we focus on interest rates where this topic is most pronounced.
Zero-coupon bond as a discount factor
Time value of money is generally associated with (i) compounding and (ii) its inverse - i.e. discounting. The latter is normally associated with a discount factor - i.e. zero-coupon bond that pays unity at maturity. This is denoted as B[t,T] where t describes initiation time and T is maturity. A standard conventions assumes t=0, which translates into current discount factor B[0,T] for T>0.
Zero-coupon bond B[t,T] is not unique measure of the time value of money. Additional measure include:
A) yield
B[t,T] = Exp[-Y[t,T] δ[t,T]]
where δ[t,T] stands for the year-fraction this is unique constant rate under continuous compounding
B) term rate
B[t,T] = 1/ (1+R[t,T] δ[t,T]}
this is unique constant rate on interval t-T with no compounding. The above term rate definition above is obtained from the floating rate note (FRN) pricing formula paying Libor index with one remaining payment:
B[t,T] (1+ R[[t,T] δ[t,T]) = 1
Forward rates
When interest rates are deterministic, it can be shown that B[0,t] B[t,T] = B[0,T]. However, if they are not, this cannot be established since B[t,T] will not be known until time t (t>0). However, B[0,T] / B[0,t] is till a useful measure as it denotes forward discount factor starting at time t with final maturity at T.
Since discount factor is function of rate process, we can define associated forward rate f0[t,T] as the rate observed today for borrowing (lending) starting on time t and maturing at time T. If the agreement to lend or borrow is done on the forward rate f0[t,T], then the contract value must have present value = 0.
Clear[B, F, f0, δ];
F[t, T] = B[0, T]/B[0, t];
F[t, T] = 1/(1 + f0[t, T] δ[t, T])
enter image description here
Agreements to borrow or lend in the future (i.e. forward rate agreements) are generally done on the fixed rate K. This is essentially an agreement to exchange market term rate R[t,T] for the fixed contract rate K. This contract is priced on the assumption that the market term rate R[t,T] will be the forward rate f0[t,T]. Although R[t,T] is unknown at time 0, f0[t,T] is, so this equality allows to price the forward rate agreement at inception at time 0.
Futures
Futures contract is similar to forward, but some differences exist. It is designed to lock in a price for purchase / sell of an asset before the physical purchase / sale occurs. At the same time, future corrects certain deficiencies of the forward contract - it allows daily variation of the rate for the given delivery rate, and due to mark-to-market nature, it eliminates the counterparty exposure. Daily settlement is primary difference in these two contracts.
Future contract is associated with a future price. This is the settlement price on which contract evaluates. In the risk-neutral world governed by risk-neural probabilities, the future price is simply ℱ = Ern[X[T]] = Exp[r T]* P0 where P0 is the future price at time 0. When the rate is constant, the future price equals forward price.
Martingales
A process is known as martingale under the risk-neutral probabilities if it satisfies the condition: h(t) = Ern[h(T)] for t<T where Ern denotes the risk-neutral expectation. In other words, price now = Ern[price next].
This also applies to futures. Futures prices are determined by the fact the ℱ(t) is martingale relative to risk-neutral probabilities. In the context of risk-free world, we frequently work with money-market account which earns risk-free rate and compounds in forward time. At inception, the account is equal to A(0) = 1, and the balance at time t is A(t) = Exp[ r t] when rate stays constant. Given this, a method to determine the price of tradable asset becomes: h(t)/A(t) = Ern[h(T)/A(T)] Since zero-coupon bond is tradable security, we establish that B[t,T] / A(t) = Ern[1/A(T)]. Since A(T) = A(t)*Exp[∫r(s) ds], the pricing formula for zero-coupon bond becomes B[t,T] = Ern[Exp[-∫r(s) ds]].
The nature of future - forward difference
Future
Interest rate future exists in many currencies and involves 3 months contract referenced to Xibor index (eg- Libor, Euribor, Tibor etc.). At contract maturity the holder makes loan to the counterparty equal to 3-months Xibor rate. This is the term rate R[t,T] we defined in the first paragraph. The associated future price (i..e future rate) is martingale:
R0[t,T] = Ern[R[t,T]]
This means that the expected future rate is the 3-month term rate R[t,T] for the period [t,T] observed today.
Forward
We can now define the similar reasoning for the forward term rate ==> f0[t,T]. We can get its definition form the forward discount factor F[t,T]
Clear[B, f0, F]
F[t, T] = B[0, T]/B[0, t];
Solve[F[t, T] == 1/(1 + f0[t, T] \[Delta][t, T]), f0[t, T]]
soln = f0[t, T] /. %;
enter image description here
This is the forward rate obtained from the ratio of discount factors.
We split the formula above into (i) numerator and (ii) denominator and express the two zero-bonds as risk-neutral expectations of zero-rates:
num1 = Numerator[soln];
num2 = num1 /. {B[0, t] -> Exp[-Integrate[r[s], {s, 0, t}]], B[0, T] -> Exp[-Integrate[r[s], {s, 0, T}]]}
enter image description here
We can simplify the above using the fact that interval [0,T] can be broken into two shorter intervals [0,t] and [t,T].
num3 = num2 /. {Exp[-Integrate[r[s], {s, 0, T}]] ->
Exp[-Integrate[r[s], {s, 0, t}]] Exp[-Integrate[r[s], {s, t, T}]]}
enter image description here
We rewrite the expression as follows:
num4 = Collect[num3, Exp[-Integrate[r[s], {s, 0, t}]]]
enter image description here
and then further simplify by bringing the year-fraction into the formula
num5 = num4 /. {Exp[-Integrate[r[s], {s, t, T}]] -> B[t, T]};
num6 = num5/δ[t, T]
enter image description here
Combining all terms brings us the formula:
f0[t, T] = (1/B[0, T]) Ern[num6]
enter image description here
Using the definition
B[t,T] = 1/(1+R[t,T] δ[t,T])
we further state:
Clear[B, R];
B[t, T] = 1/(1 + R[t, T] δ[t, T]);
num7 = (1 - B[t, T])/δ[t, T] // Simplify
which translates to
R[t,T] B[t,T]
Clear[B, R, f0];
num8 = num7 /. {R[t, T]/(1 + R[t, T] δ[t, T]) -> R[t, T]*B[t, T]} // Simplify
enter image description here
We can now express the expectation of the forward rate as:
f0[t, T] = (1/B[0, T]) Ern[
Exp[-Integrate[r[s], {s, 0, t}]] num8]
enter image description here
further rewrite the discount factor formula as rate process
f0[t, T] = f0[t, T] /. {B[t, T] -> Exp[-Integrate[r[s], {s, t, T}]]}
enter image description here
Noting that two periods combine into one [0,t] [t,T] -> [0,T]
f0[t, T] /. {Exp[-Integrate[r[s], {s, 0, t}]] Exp[-Integrate[
r[s], {s, t, T}]] -> Exp[-Integrate[r[s], {s, 0, T}]]}
enter image description here
which further simplifies to:
% /. {B[0, T] -> Ern[Exp[-Integrate[r[s], {s, 0, T}]]]}
enter image description here
The above formula shows that the forward rate f0[t,T] is NOT the risk-neutral expectation of the Xibor term rate R[t,T]. The formula above shows that the forward rate is the expectation taken under different probability measure where the Xibor rate is weighted by Exp[-∫r(s) ds].
Defining both rates in simplified notation with [DoubleStruckCapitalE] representing the risk-neutral expectation, we can now quantify the difference between the two rates:
Clear[R, f0, B];
R[t, T] = \[DoubleStruckCapitalE][R];
f0[t, T] = \[DoubleStruckCapitalE][R B]/\[DoubleStruckCapitalE][B];
f0[t, T] - R[t, T] // Together
enter image description here
If R and B were independent, the nominator would vanish leading to the fact that forward rate = futures rate. However, independence cannot be justified since R is a rate and B is a discount factor that implies negative correlation between the two.
This will make the nominator negative, leading to a conclusion that forward rate < future term rate. This is not surprising. Since futures offer certain advantages over forwards - namely in daily settlement - their higher price relative to forwards is logical.
The adjustment of future rate to the forward rate is known as drift correction. Practitioners refer to it as 'convexity adjustment'. As the formula above shows, different dynamics for interest rates will lead to different drift correction formula.
Various drift correction approaches
We look at several examples of drift correction formulas where we assume certain distributions for the term rate R[t,T] and the discount factor B[t,T]. We set the Xibor distribution to Normal (explicitly allowing for negative rates), whereas we choose different processes for discount factor. The joint expectation is computed via Copula distributions (Binormal and Farlie-Gumbel-Morgenstern). We output (i) the joint copula expectation of rate and discount factor E[R B] and the final drift correction formula. As shown below, different combination of rate and DF processes lead to a different drift correction formulas.
Normal- Normal process
rDist = NormalDistribution[a, b];
bDist = NormalDistribution[c, d];
bc1 = CopulaDistribution[{"Binormal", ρ}, {rDist, bDist}];
jd1 = Expectation[x y, {x, y} \[Distributed] bc1,
Assumptions -> b > 0 && d > 0] // Simplify
eR = Expectation[x, x \[Distributed] rDist, Assumptions -> b > 0];
eD = Expectation[y, y \[Distributed] bDist, Assumptions -> d > 0];
dc1 = (jd1 - eR eD)/eD // Simplify
enter image description here
enter image description here
Drift adjustment formula depends on the covariance product and DF drift. This is similar to 'quanto' adjustment in equity options.
Plot3D[dc1 /. {c -> 0.95, ρ -> -0.85}, {b, 0.001, 0.02}, {d, 0.5, 1.5},
ColorFunction -> "TemperatureMap", PlotLegends -> Automatic,
AxesLabel -> Automatic,
PlotLabel -> Style["N-N drift adjustment - volatility dependence", 15, Blue]]
enter image description here
Normal - Log Normal process
bDist = LogNormalDistribution[c, d];
bc1 = CopulaDistribution[{"Binormal", ρ}, {rDist, bDist}];
jd1 = Expectation[x y, {x, y} \[Distributed] bc1,
Assumptions -> b > 0 && d > 0] // Simplify
eR = Expectation[x, x \[Distributed] rDist, Assumptions -> b > 0];
eD = Expectation[y, y \[Distributed] bDist, Assumptions -> d > 0];
dc1 = (jd1 - eR eD)/eD // Simplify
enter image description here
enter image description here
Normal - LogNormal process generates similar drift adjustment routine to the double-normal process.
Normal - Laplace process
bDist = LaplaceDistribution[c, d];
bc1 = CopulaDistribution[{"FGM", ρ}, {rDist, bDist}];
jd1 = Expectation[x y, {x, y} \[Distributed] bc1,
Assumptions -> b > 0 && d > 0] // Simplify
eR = Expectation[x, x \[Distributed] rDist, Assumptions -> b > 0];
eD = Expectation[y, y \[Distributed] bDist, Assumptions -> d > 0];
dc1 = (jd1 - eR eD)/eD // Simplify
enter image description here
enter image description here
Normal -Laplace process (as a special case of Variance-Gamma process) generates more complex adjustment rule with deeper dependence on each process.
Normal - Gamma process
bDist = GammaDistribution[c, d];
bc1 = CopulaDistribution[{"FGM", ρ}, {rDist, bDist}];
jd1 = Expectation[x y, {x, y} \[Distributed] bc1,
Assumptions -> b > 0 && d > 0 && c > 0] // Simplify
eR = Expectation[x, x \[Distributed] rDist, Assumptions -> b > 0];
eD = Expectation[y, y \[Distributed] bDist, Assumptions -> d > 0 && c > 0];
dc1 = (jd1 - eR eD)/eD // Simplify
enter image description here
enter image description here
Normal-Gamma process is well defined and relatively simple.
Normal - Logistic process
bDist = LogisticDistribution[c, d];
bc1 = CopulaDistribution[{"FGM", ρ}, {rDist, bDist}];
jd1 = Expectation[x y, {x, y} \[Distributed] bc1,
Assumptions -> b > 0 && d > 0 && -1 <= ρ <= 1] // Simplify
eR = Expectation[x, x \[Distributed] rDist, Assumptions -> b > 0];
eD = Expectation[y, y \[Distributed] bDist, Assumptions -> d > 0];
dc1 = (jd1 - eR eD)/eD // Simplify
enter image description here
enter image description here
Simplicity is also a feature of Normal-Logistic process where the adjustment formula is a product of covariances
Normal - K process
bDist = KDistribution[c, d];
bc1 = CopulaDistribution[{"FGM", ρ}, {rDist, bDist}];
jd1 = Expectation[x y, {x, y} \[Distributed] bc1,
Assumptions -> b > 0 && d > 0 && -1 <= ρ <= 1] // Simplify
eR = Expectation[x, x \[Distributed] rDist, Assumptions -> b > 0];
eD = Expectation[y, y \[Distributed] bDist, Assumptions -> d > 0];
dc1 = (jd1 - eR eD)/eD // Simplify
enter image description here
enter image description here
On the other hand, selection of Normal - K process (as representation of Exponential / Gamma mixture) for DF calibration leads to a complex adjustment rule
Normal - Johnson SN process
bDist = JohnsonDistribution["SN", c, d1, d2, d3];
bc1 = CopulaDistribution[{"FGM", ρ}, {rDist, bDist}];
jd1 = Expectation[x y, {x, y} \[Distributed] bc1,
Assumptions -> b > 0 && d3 > 0 && -1 <= ρ <= 1] // Simplify
eR = Expectation[x, x \[Distributed] rDist, Assumptions -> b > 0];
eD = Expectation[y, y \[Distributed] bDist, Assumptions -> d3 > 0];
dc1 = (jd1 - eR eD)/eD // Simplify
enter image description here
enter image description here
Conclusion
We have taken more rigorous approach to show why futures and forwards differ when the rates are stochastic. We have demonstrated that the nature of deviation lies in probability measure - due to the fact that futures and forwards are essentially subject to different expectations. This leads to a conclusion that forward rates cannot be unbiased estimates on future Xibor rates since forward process is principally different.
We have also demonstrated that drift adjustment formula to equate futures and forward is probability-dependent, and selection of different rate (discount factor) processes leads to different results. The rule complexity depends on (i) joint expectation and (ii) distributional assumptions about each component.
We conclude the exposition to model selection with the higher-order Normal-Johnson process of 'SN' type where more process parameters provide better control for DF process.tgstgs dawfa2018-06-21T07:16:49ZOnline multiple choice quiz using FormPage
http://community.wolfram.com/groups/-/m/t/1360762
Please find attached a Mathematica notebook that demonstrates the CloudDeploy of a FormPage for an online quiz. It can be taken by different students at the same time, provided that each one enters a different student id number. Student's progress is stored in the Wolfram Cloud (CloudPut) using string labels (uri) that include the student id number. In the source code, the correct answer to each question is always the first choice in the list, however different students will see the multiple choice answers in different order (RandomPermutation) when the quiz is online. The quiz looks very nice in my iPhone, but students can also work in a computer or tablet. This is a link to the final product: [online quiz created with FormPage][1]
I hope you find it useful
Jose from Mexico
[1]: https://wolfr.am/vxZpPK3LJose Gomez2018-06-21T22:31:10ZWhy Doesn't Minimize Use the Kuhn-Tucker equations for bounded problems?
http://community.wolfram.com/groups/-/m/t/1361031
From the documentation:
For linear cases, Minimize and Maximize use exact linear programming methods.
For polynomial cases they use cylindrical algebraic decomposition.
For analytic cases in closed and bounded boxes they use methods based on Lagrange multipliers.
The following example is a bounded problem which can be solved by the Kuhn-Tucker equations (Lagrange multipliers) but
Minimize does not solve it but Reduce can solve the Kuhn-Tucker equation.
objective function, constraints, variables of problem
In[1]:= obj = x^2 -
y^2; cons = {Cos[x - y] >= 1/2, -5 <= x <= 5, -5 <= y <= 5}; vars = {x, y};
Minimize does not find a solution
In[2]:= Minimize[{obj, Sequence @@ cons}, vars]
Out[2]= Minimize[{x^2 - y^2, Cos[x - y] >= 1/2, -5 <= x <= 5, -5 <= y <= 5}, {x, y}]
function to generate the Kuhn-Tucker equations for a minimization problem.
In[3]:= KTEqs[obj_, cons_List, vars_] :=
Module[{consconvrule = {GreaterEqual[x_, y_] -> LessEqual[y - x, 0],
Equal[x_, y_] -> Equal[x - y, 0],
LessEqual[x_, y_] -> LessEqual[x - y, 0],
LessEqual[lb_, x_, ub_] -> LessEqual[(x - lb) (x - ub), 0],
GreaterEqual[ub_, x_, lb_] -> LessEqual[(x - lb) (x - ub), 0]}
, stdcons, eqcons, ineqcons, lambdas, mus, lagrangian, eqs1, eqs2, eqs3,
alleqns, allvars },
stdcons = cons /. consconvrule;
eqcons = Cases[stdcons, Equal[_, 0]][[All, 1]];
ineqcons = Cases[stdcons, LessEqual[_, 0]][[All, 1]];
lambdas = Array[\[Lambda], Length[eqcons]];
mus = Array[\[Mu], Length[ineqcons]];
lagrangian = obj + lambdas.eqcons + mus.ineqcons;
eqs1 = Thread[ D[lagrangian, {vars}] == 0];
eqs2 = Thread[mus >= 0];
eqs3 = Thread[mus*ineqcons == 0];
alleqns = Join[eqs1, eqs2, eqs3, cons];
allvars = Join[vars, lambdas, mus];
{alleqns, allvars}
]
Kuhn-Tucker equations for this problem
In[4]:= kteqs = KTEqs[obj, cons, vars];
solution found by Reduce
In[5]:= sln = Reduce[Sequence @@ kteqs, Backsubstitution -> True];
convert the solution to rules
In[6]:= slnrls = List @@ (ToRules /@ sln);
Look at the numerical objective function values to see how many global minima there are
In[7]:= N[obj /. slnrls]
Out[7]= {0., -9.37535, -24.9443, -9.37535, -24.9443}
find the objective function values and pair them with the solution rules
In[8]:= res = Thread[{obj /. slnrls, slnrls}];
Take the best two results
In[9]:= Sort[res, #1[[1]] < #2[[1]] &][[{1, 2}]]
Out[9]= {{-25 + 25/9 (-3 + \[Pi])^2, {y -> 5, \[Mu][2] -> 0,
x -> -(5/3) (-3 + \[Pi]), \[Mu][1] -> (20 (-3 + \[Pi]))/(
3 Sqrt[3]), \[Mu][3] ->
1/9 (9 + 6 Sqrt[3] Sin[5 + 5/3 (-3 + \[Pi])] -
2 Sqrt[3] \[Pi] Sin[5 + 5/3 (-3 + \[Pi])])}}, {-25 +
25/9 (-3 + \[Pi])^2, {y -> -5, \[Mu][2] -> 0,
x -> 5/3 (-3 + \[Pi]), \[Mu][1] -> (20 (-3 + \[Pi]))/(
3 Sqrt[3]), \[Mu][3] ->
1/9 (9 + 6 Sqrt[3] Sin[5 + 5/3 (-3 + \[Pi])] -
2 Sqrt[3] \[Pi] Sin[5 + 5/3 (-3 + \[Pi])])}}}
Examine the numerical values of the global minima
In[10]:= N[%]
Out[10]= {{-24.9443, {y -> 5., \[Mu][2.] -> 0.,
x -> -0.235988, \[Mu][1.] -> 0.54499, \[Mu][3.] ->
1.0472}}, {-24.9443, {y -> -5., \[Mu][2.] -> 0.,
x -> 0.235988, \[Mu][1.] -> 0.54499, \[Mu][3.] -> 1.0472}}}
compare to NMinimize result
In[11]:= NMinimize[{obj, Sequence @@ cons}, vars]
During evaluation of In[11]:= NMinimize::cvmit: Failed to converge to the requested accuracy or precision within 100 iterations.
Out[11]= {-24.9443, {x -> 0.235988, y -> -5.}}Frank Kampas2018-06-21T15:07:43ZReal-time tracking of motor temperature and IR sensors in an Arduino robot
http://community.wolfram.com/groups/-/m/t/1360573
Infra-red reflectance sensor arrays, widely used in line following robots, typically comprise of 5 to 8 sensors. However, for best performance, the sensors of the array must be calibrated properly according to the reflectivity of the specific surface so that the robot follows the line primarily using the central sensors. Using a larger number of reflectance samples for this is preferable for best results; the only issue here is that this is very time consuming when tuning the robot using a PD algorithm, often resulting in heating of the DC motors, particularly if the ambient temperatures are high. To avoid excessive heating, it is therefore important to attempt performing the calibration using lesser number of samples, provided it is possible to verify that the sensors have been tuned properly.
For creating fast robots, micro-metal gear motors with a 30:1 gearbox at 1000 rpm offer fantastic speeds, but are prone to heating due to their miniature size, even at lower speeds around 300 rpm, if powered for longer intervals of time. As mentioned, this process is accelerated by high ambient temperatures; in New Delhi, India, midday temperatures in June can hover around 45 degrees Celsius (about 113 degrees Fahrenheit)!
## ROBOT CONSTRUCTION ##
In this project, a line following robot utilizing the Arduino Mega 2560 microprocessor was constructed which featured, primarily, the following hardware:
- The QTR-8RC Reflectance sensor array involving 8 IR LED/Phototransistor pairs, from Pololu USA ([https://www.pololu.com/docs/pdf/0J12/QTR-8x.pdf][1])
- Two HP 6V micro metal gear motors, with gearbox specifications as mentioned above, from Pololu USA ([https://www.pololu.com/file/0J1487/pololu-micro-metal-gearmotors.pdf][2])
- Two Texas Instruments LM235 analog out temperature sensors ([http://www.ti.com/lit/ds/symlink/lm235.pdf][3])
- TB6612FNG dual DC motor driver, from Pololu USA ([https://www.pololu.com/file/0J86/TB6612FNG.pdf][4])
- Texas Instruments LM2596 DC-DC buck converter Step-Down module ([http://www.ti.com/lit/ds/symlink/lm2596.pdf][5])
- HC 05 Bluetooth Module ([http://www.electronicaestudio.com/docs/istd016A.pdf][6])
- 1500 mAh, 3S, 30 C (11.1V) Lithium Polymer Battery with a digital voltage indicator
The temperature sensors were physically affixed to the casing of each motor, respectively, with their outputs connected to the Arduino analog pins.
Photographs of the robot appear below:
![Photograph 1][7]
![Photograph 2][8]
## ROBOT OPERATION ##
The temperature sensors needed to be calibrated according to the prevailing ambient temperature before starting the robot. The DC motors were controlled using the TB6612FNG module and the Lithium Polymer (LiPo) battery. The power supply to the Arduino board was provided via the LiPo battery and the LM2596 DC-DC buck converter Step-Down module to ensure constant 5V DC input. Finally, two-way communication between the robot and Mathematica was established using the HC 05 module i.e. to send commands to the robot and also receive sensor data from the QTR array and the temperature sensors, in real time, using a serial connection. The powerful and dynamic graphical capabilities of Wolfram Mathematica were utilized to create a real time graph of data from both the temperature sensors, and a dynamic graphic showing the specific sensor of the 8-sensor array positioned above the line.
The video of the setup is available [here][9].
## CODE ##
Following is a recursive definition for acquiring serial data. Recursion was, by far, the best method to ensure that data was received into Mathematica.
GetData[] := (Off[Last::nolast]; ard = DeviceOpen["Serial", "COM6"];
in = Last@
Flatten[ToExpression[
StringSplit[
StringCases[FromCharacterCode@DeviceReadBuffer[ard],
"{" ~~ __ ~~ "}"], "\r\n"]], 1];
If[Length[in] == 1,
Clear[in];
GetData[], Return@in])
## RESULTS ##
The ‘MedianFilter’ function of Wolfram Mathematica was used to filter noisy raw data, and the ‘Fit’ function was used for fitting a linear model to the data, for two segments:
- Robot in operation (temperature of both the motors increasing), and
- Robot halted (temperature of both the motors decreasing)
An algorithm was also written to determine the median temperatures attained by the motors, which are indicated by the red points on some graphs.
Since the left wheel of the robot traversed a longer distance due to the robot taking right turns, as seen in the video, it was observed that the left motor heated up more, and that too faster, in comparison to the right motor.
![Raw Right][10]
![Raw Left][11]
![Filtered Right][12]
![Filtered Left][13]
![Fitted Right][14]
![Fitted Left][15]
## CONCLUSION ##
Wolfram Mathematica offers an excellent platform for real-time data acquisition and processing. This led to the following being achieved:
1. Determination, through a dynamic graphic, of the exact sensor above the line being followed by the robot resulted in achieving faster implementation of the PD algorithm used in this project. This also helped in monitoring the movement of the robot in real time and verifying if the sensors of the array were calibrated properly while performing multiple runs continuously.
2. Temperature monitoring of the motors in real-time. This was important as previously one had to stop the robot to check the temperatures of the motors manually, usually when burning smell became apparent!
3. Extracting relevant data from noisy temperature data, and determining equations for the same. The filtering and fitting functions of Mathematica made the task simpler!
[1]: https://www.pololu.com/docs/pdf/0J12/QTR-8x.pdf
[2]: https://www.pololu.com/file/0J1487/pololu-micro-metal-gearmotors.pdf
[3]: http://www.ti.com/lit/ds/symlink/lm235.pdf
[4]: https://www.pololu.com/file/0J86/TB6612FNG.pdf
[5]: http://www.ti.com/lit/ds/symlink/lm2596.pdf
[6]: http://www.electronicaestudio.com/docs/istd016A.pdf
[7]: http://community.wolfram.com//c/portal/getImageAttachment?filename=20180616_211518%282%29.jpg&userId=1102146
[8]: http://community.wolfram.com//c/portal/getImageAttachment?filename=20180616_211655%282%29.jpg&userId=1102146
[9]: https://youtu.be/I47b04aEsA4
[10]: http://community.wolfram.com//c/portal/getImageAttachment?filename=RawRight.jpg&userId=1102146
[11]: http://community.wolfram.com//c/portal/getImageAttachment?filename=RawLeft.jpg&userId=1102146
[12]: http://community.wolfram.com//c/portal/getImageAttachment?filename=FilteredRight.jpg&userId=1102146
[13]: http://community.wolfram.com//c/portal/getImageAttachment?filename=FilteredLeft.jpg&userId=1102146
[14]: http://community.wolfram.com//c/portal/getImageAttachment?filename=Right_motor_Fitted.jpg&userId=1102146
[15]: http://community.wolfram.com//c/portal/getImageAttachment?filename=Left_motor_Fitted.jpg&userId=1102146Anmol Singh2018-06-21T07:38:41ZMake DeleteCases work with string patterns?
http://community.wolfram.com/groups/-/m/t/1360558
I am trying to reproduce the illustration of cleaning up imported data in *Mathematica* from [here][1].
I had to make a slight change in ***input 13*** to `j[x_] := If[StringMatchQ[x, "TOTAL*"], x, DateList[x]];`
After running ***input 14***, I get the following output:
![enter image description here][2]
There is a "TOTAL" row for every year. The article proposes to delete those rows by running `tmp4 = DeleteCases[tmp3, {"TOTAL*", __}];` (*the asterisk I my contribution*). But it doesn't work! After searching the internet, I found that `DeleteCases` is not compatible with string patterns. [here][3].
So how do we delete those rows?
And if `DeleteCases` is truly incompatible, how did the Mathematica article succeed?
PS: I did manage to delete those rows by sorting the data and then *Dropping* them. But I would still like to know how to proceed with `DeleteCases` because there might be situations where Sorting doesn't work.
[1]: http://reference.wolfram.com/language/howto/CleanUpDataImportedFromAWebsite.html
[2]: http://community.wolfram.com//c/portal/getImageAttachment?filename=StringMatchQ.PNG&userId=529007
[3]: https://mathematica.stackexchange.com/questions/8945/specifying-string-Thadeu Freitas Filho2018-06-21T06:53:33ZSolve the following differential equations and plot them?
http://community.wolfram.com/groups/-/m/t/1360355
Good evening,
I'm a new user and I just started with Mathematica. I need some help. I study an astrophysics (PhD cand.). In that moment I making calculations, and create code which need to be solved. But now I have problem with graphics. The program does not create it.
Maybe something is wrong with program code?
I will be grateful for the help.
**Program code**
solution = NDSolve[{
x'[t] = u[t]/0.01 Sqrt[u[t]^2 + v[t]^2 + w[t]^2], x[0] == 5.0,
y'[t] == v[t]/x (0.01 Sqrt[u[t]^2 + v[t]^2 + w[t]^2]) sin[y],
y[0] == 5.0,
z'[t] == w[t]/x (0.01 Sqrt[u[t]^2 + v[t]^2 + w[t]^2]),
z[0] = .00001,
u'[t] == 0, u[0] == 0.0,
v'[t] == 0,
01 (x (Sqrt[u[t]^2 + v[t]^2 + w[t]^2]) sin[y] - x[t] - z[t]),
v[0] == 0.0,
w'[t] == 0, 01 y'[t], w[0] == 1.0},
{x, z, y, u, v, w}, {t, 0, 5, 1700.0},
MaxSteps -> 1000000000, Method -> ExplicitRungeKutta]
ParametricPlot[Evaluate[{x[t], v[t]} /. solution], {t, 0, 1700},
AxesLabel -> {"10\[Rho]", "p\[Phi]"}];Alexey Faust2018-06-20T18:55:30ZGet the step by step mode on W|A app?
http://community.wolfram.com/groups/-/m/t/1360296
I bought the app on the tunes and unfortunately the step by step mode does not work properly, I am not shown the complete procedure but only a part. HELPLUNGU RADU2018-06-20T17:10:10ZEdit a netcdf file?
http://community.wolfram.com/groups/-/m/t/1359920
Hi Mathematica experts.
I am new to Mathematica, so I have a question.
How can I edit netcdf file in Mathematica?
Many Thanks.
Samadabdossamad r2018-06-20T13:27:04ZSemicolon-Separated Expression-Sequences: How to Control Formatting?
http://community.wolfram.com/groups/-/m/t/1357032
Here is an illustration of what I mean by semicolon-separated expression-sequence:
x1 = 0; x2 = 3; x3 = 1;
When using the notebook interface to edit my code, sometimes Mathematica allows me to sequence expressions on a single line as illustrated above, but other times Mathematica forces each expression onto its own separate line. How Mathematica decides when to force the line-breaking is obscure to me (if it is documented, I have not found where), and so Mathematica's behavior in this respect appears random and surprises me when I'm not trying to be surprised by my editor. Is it predictable? Is it controllable?Joe Donaldson2018-06-17T05:00:49ZWhat keys need to press to type a dot (to be interpreted as multiplication)
http://community.wolfram.com/groups/-/m/t/1359321
edited to add: the keys needed to type a dot are esc-.-esc, but I still haven't found the documentation to that effect. Maybe I will write a program to record my long and frustrating travels through the Wolfram documentation.
Here is how not to find the answer: Start by typing esc-d-o-t; give up on that. Now go to the front page of the Documentation Center. Search "Dot". After realizing you have made another mistake, go back to the front page of the Documentation Center. Press random links until you find yourself on "Wolfram Language Syntax". Then you see "Mathematics & Operators", in orange, and under that you see a "+' and a "*" but not dot. Another dead end, or is it, because things in orange might be hyperlink, or they might not, and you won't know unless you take a gamble and try. Click it. Nothing. Lost the gamble. 20 more minutes killed, no dot, and no math done. When I was a kid, we would just push the #2 pencil into a piece of paper, and the dot would happen.
My little latex paper I'm writing has an index on the last page of all mathematical symbols used in the paper, scan the index, see a symbol, the index tells you what page the symbol is defined on, with a hyperlink to the definition....Joe Donaldson2018-06-19T22:30:21ZImport a list of data and apply a function to one of the coordinates?
http://community.wolfram.com/groups/-/m/t/1360123
I'm really new on programming and similar things,
I have a data, import on math (with the command data= Import["PAtht"]) like {{x1,y1},{x2,y2}, etc etc}..
Is it possible to have a new list like {{f(x1),y1},{f(x2),y2}, etc (for example f(x)= a*x^2 with a = parameter )
I mean I wish to have a list of command to transform my data in new data and then plot the new data maybe also with a variable parameter .
Really thanx.Achille Angrisani Armenio2018-06-20T12:17:59ZOrdered list of hyperlinks to all Mathematica tutorials?
http://community.wolfram.com/groups/-/m/t/1359354
Is there an ordered list of hyperlinks to all Mathematica tutorials, ordered like a table of contents would be?Joe Donaldson2018-06-19T23:09:30ZMathematica Single Shot Detector Implementation (Object Detection)
http://community.wolfram.com/groups/-/m/t/1273291
Hi Folks,
I have added an implementation of the Single Shot Detector Object detection system to my CognitoZoo project.
![enter image description here][1]
Please see the following link for details (it's a GitHub project):
[CognitoZoo Wiki link][2]
It can recognise the 20 Pascal object categories. It's really quite fun.
I've also got an implementation of Yolo as well in that project. (The Tiny Yolo v2 version)
From playing with both of them, in my experience the SSD VGG 300 detector seems to have better recognition performance than the tiny Yolo version.There are other versions of Yolo which I hope to implement later.
I hope this is of interest.
Thanks,
Julian Francis.
[1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=ssd.jpg&userId=778270
[2]: https://github.com/jfrancis71/CognitoZoo/wiki/SSDVGG300Julian Francis2018-01-28T10:12:30ZWrite a sum of equation in Wolfram Language?
http://community.wolfram.com/groups/-/m/t/1359865
Hello!
How can I program this equation in Mathematica?
![Equation][1]
[1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=Zajetaslika.JPG&userId=1359850
I would really appreciate some help with this problem.tomo2 //2018-06-20T08:59:54ZEnter equal symbol aligned math cell without palette?
http://community.wolfram.com/groups/-/m/t/1359345
In the Writing Assistant palette I see a way to enter an Equal Symbol Aligned Math Cell, which would be useful both for input to be evaluated and also for formulas in the "DisplayFormula" cell-style. Is there a way to enter an Equal Symbol Aligned Math Cell without opening the palette or using the mouse?Joe Donaldson2018-06-19T23:03:55ZGet the entire output instead of wrapping it?
http://community.wolfram.com/groups/-/m/t/1358761
Hello everybody! I am new to Mathematica and I have a question, which I guess should be rather simple. In the attached file there is a script, that allows to obtain faces out of the adjacency matrix. It seem to work good. However, if the output is large enough, the program wraps the answer (the very last line of the script) instead of giving the list of vertices of faces. What is the way to make it write the whole list instead of wrapping it?
Thanx in advance, AntonAnton Savchenkov2018-06-19T17:40:31Z[Job] 3D Region Modeling and Exporting
http://community.wolfram.com/groups/-/m/t/1359449
We (one software engineer, one mathematician) are looking for someone in the NYC area to do some in-person code review, and develop a short-term project with us in Mathematica. We have roughly prototyped in notebooks, but are in need of some expert help.
The project involves making 3D polygons as regions, sub-dividing those regions, and then recombining them with different rotations with the help of a GUI. The resulting 3D plots should be exportable as 3D files, and will be used in an existing iPhone app, and for 3D printing.
Thank you!Lia Emars2018-06-20T09:26:17ZThe inverse of moving from a map to a network topology
http://community.wolfram.com/groups/-/m/t/1358396
Caveat: this may be more of a math problem than a Mathematica-specific problem, but I thought some in this group might have insight.
A solved problem is moving from a map in which there are districts with boundaries to a representation of that map as a network in which the vertices are the districts and edges represent shared boundaries between districts.
fr = UndirectedGraph[
NestGraph[#["BorderingCountries"] &, Entity["Country", "France"],
3]]
But what about the inverse problem: how does one move from a network to a map which is consistent with that network. There are likely to be an infinite number of such maps, but how does one even find a single exemplar. I'm thinking this is actually quite a difficult problem, but perhaps some people here might have insight on the matter and how such an exercise might be tackled using Mathematica.Seth Chandler2018-06-19T13:27:01ZFind the value of b for which one of the eigenvalues crosses the imaginary?
http://community.wolfram.com/groups/-/m/t/1358740
Dear members,
I have a Matrix that that depends on a parameter "b"
A={{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0}, {0, 0, 0, 0, 0, 0, -2 \[Pi], 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, -4 \[Pi], 0, 0, 0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, -6 \[Pi], 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, -8 \[Pi], 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0,
0, -10 \[Pi], 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, {0, 2 \[Pi], 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, {0, 0,
4 \[Pi], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
0}, {0, 0, 0, 6 \[Pi], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0}, {0, 0, 0, 0, 8 \[Pi], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 10 \[Pi], 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1}, {-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.1, 0,
0, 0, 0, 0, -(b/2), 0, 0, 0, 0}, {0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, -0.1, 0, 0, 0, 0, -2 \[Pi], -(b/2), 0, 0, 0}, {0, 0, -1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, -0.1, 0, 0, 0, b/2, -4 \[Pi], -(b/2), 0,
0}, {0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.1, 0, 0, 0, b/
2, -6 \[Pi], -(b/2), 0}, {0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, -0.1, 0, 0, 0, b/2, -8 \[Pi], -(b/2)}, {0, 0, 0, 0, 0, -1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, -0.1, 0, 0, 0, b/2, -10 \[Pi]}, {0, 0, 0,
0, 0, 0, -1, 0, 0, 0, 0, -b, 2 \[Pi], b/2, 0, 0, 0, -0.1, 0, 0, 0,
0}, {0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, -(b/2), 4 \[Pi], b/2, 0,
0, 0, -0.1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
0, -(b/2), 6 \[Pi], b/2, 0, 0, 0, -0.1, 0, 0}, {0, 0, 0, 0, 0, 0, 0,
0, 0, -1, 0, 0, 0, 0, -(b/2), 8 \[Pi], b/2, 0, 0, 0, -0.1, 0}, {0,
0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, -(b/2), 10 \[Pi], 0, 0,
0, 0, -0.1}}
To find the value of b for which one of the eigenvalues crosses the imaginary I am doing this
FindRoot[Max[Re[Eigenvalues[A]]] == 0, {b, 1}]
varies errors rise when executing FindRoot. For intance, "Unable to find all roots of the characteristic polynomial"
It seem to me that FindRoot does not take "b" as a variable.
Am I using FindRoot correctly?
Thanks for any help you can provide.
JesúsJ Jesus Rico-Melgoza2018-06-19T14:40:56ZRun a code multiple times and each time it returns a value?
http://community.wolfram.com/groups/-/m/t/1357962
Hello,
I have a code that I want to run multiple times. In Matlab, I can enclose the code within a function and call the function every time I want to run the code. In each iteration, I should pass multiple values to the variables within the code and then the code runs and return multiple values. I wonder if this can be done in Mathematica.
Thank youmohamed alzenad2018-06-18T22:54:23Z[GIF] Recursive Complete Graph
http://community.wolfram.com/groups/-/m/t/1358541
![enter image description here][1]
The rule is simple:
1. Start with n-points in any arbitrary configuration.
2. Connect every point to every other point with a line.
3. Draw a point where any *new* intersections occur.
4. These intersections become your initial set of points for the next iteration. Repeat the process.
I only took it 3 iterations because render time blows up, but it looks like it approaches a particular figure as # of iterations -> infinity.
We may suspect that different sets of initial points yield a converging image, while others do not converge. Much like a geometric series.
Here is a closer look at the 3rd iteration:
![enter image description here][2]
We could also keep the points from previous iterations, yielding something more like this:
![enter image description here][3]
The code is not super clean, did a lot of manual stuff.
pts0 = N[CirclePoints[6]];
lines = Subsets[pts2, {2}];
threshold = 0.0000000001;
lul = {};
Monitor[
Do[
p = Quiet[
Position[lul,
t_ /; (RegionDistance[InfiniteLine[lines[[i]]], t[[1]]] <
threshold &&
RegionDistance[InfiniteLine[lines[[i]]], t[[2]]] <
threshold)]];
Quiet[If[MatchQ[p, {}],
AppendTo[lul, lines[[i]]],
Set[lul,
ReplacePart[lul,
p[[1]][[1]] ->
Flatten[MaximalBy[{lines[[i]], lul[[p[[1]][[1]]]]},
EuclideanDistance[#[[1]], #[[2]]] &, 1], 1]]]]]
Clear[p];
, {i, 1, Length[lines]}]
, {i, Length[lul]}]
longestUniqueLines=lul;
intersectionpoints =
Monitor[
DeleteDuplicates[
Flatten[
Table[
If[MatchQ[
RegionIntersection[Line[longestUniqueLines[[i]]],
Line[longestUniqueLines[[
j]]]], _EmptyRegion] \[Or] (RegionDistance[
Line[longestUniqueLines[[i]]],
longestUniqueLines[[j]][[1]]] < threshold) \[Or]
(RegionDistance[Line[longestUniqueLines[[i]]],
longestUniqueLines[[j]][[2]]] < threshold) \[Or]
(RegionDistance[Line[longestUniqueLines[[j]]],
longestUniqueLines[[i]][[1]]] < threshold) \[Or]
(RegionDistance[Line[longestUniqueLines[[j]]],
longestUniqueLines[[i]][[2]]] < threshold)
, Nothing,
Flatten[RegionIntersection[Line[longestUniqueLines[[i]]],
Line[longestUniqueLines[[j]]]][[1]]]
], {i, Length[longestUniqueLines]}, {j,
Delete[Range[Length[longestUniqueLines]],
Table[{q}, {q, i}]]}]
, 1]
, Abs[#1[[1]] - #2[[1]]] < threshold \[And]
Abs[#1[[2]] - #2[[2]]] < threshold &];
, {i, j}]
[1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=RCG.gif&userId=167076
[2]: http://community.wolfram.com//c/portal/getImageAttachment?filename=RCG_thirdIt2.png&userId=167076
[3]: http://community.wolfram.com//c/portal/getImageAttachment?filename=RCGpreviousItskept.png&userId=167076Bryan Lettner2018-06-19T09:49:29ZGet a simplified result from PDE with NDSolve?
http://community.wolfram.com/groups/-/m/t/1305883
Hi, I have tried out this command to test the results:
op = I*Nest[op, \[CapitalPsi][r, \[Phi]], 3] == 2 \[CapitalPsi][r, \[Phi]]*r^2/Cos[\[Phi]]^5
sol = CapitalPsi[r, Phi] /.
NDSolve[{op,
CapitalPsi[0, Phi] == 1,
Derivative[1, 0][CapitalPsi][0, Phi] == 0,
Derivative[2, 0][CapitalPsi][0, Phi] == 10,
Derivative[3, 0][CapitalPsi][0, Phi] == 0},
CapitalPsi, {r, 0, 3}, {Phi, 0, 3},
MaxSteps -> Infinity, PrecisionGoal -> 1,
AccuracyGoal -> 1,
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid",
"MinPoints" -> 32, "MaxPoints" -> 32, "DifferenceOrder" -> 2},
Method -> {"Adams", "MaxDifferenceOrder" -> 1}}] //
Plot3D[sol, {r, 0, 3}, {Phi, 0, 3}, AxesLabel -> Automatic]
However, I get a very messy output, with no plot.
Is there something missing here?
Thanks!Ser Man2018-03-21T09:05:52ZUpdate notebook after I changed a variable?
http://community.wolfram.com/groups/-/m/t/1357794
Hello,
I just started with Mathematica and coming from MathCAD because of its poor functionality in higher math.
Now I created a new Spreadsheet and was just trying around with some functions and variables.
Because I want to make some big calculations, I must have the possibility to sometimes changes some variables/functions at the start. Therefore i need the option to update my whole spreadsheet with these changes, without reentering all the later commands.
Greetings.ha bla2018-06-18T09:42:09ZImplement Mathematica in Mathematica
http://community.wolfram.com/groups/-/m/t/1357709
Has anyone written Mathematica code simulating the Mathematica evaluation process (or at least some of its basics)? A Mathematica emulator (not the heavy math stuff like integration and reduce), written Mathematica, but using a small subset of Mathematica's functions? I hope one of you thinks it is fun, because it would be far beyond my ability, but the results would at least be helpful to new users trying to understand what Mathematica does. Once you learned said small subset of functions, you could understand the emulator's code; and once you understood the emulator's code, you would understand Mathematica. I cannot pay though, so I hope this sounds fun.Joe Donaldson2018-06-17T22:41:37ZGet the right data type from MatrixExp?
http://community.wolfram.com/groups/-/m/t/1305503
Good morning,
I am using MatrixExp[] inside a Compiled function and, at a certain point, I assign to a square matrix the output of MatrixExp. I am getting an error complaining that MatrixExp is of type {_Real,0} and cannot be assigned to a variable of type {_Real,2}. The code is quite straightforward... The problem occurs with the instruction "M=M.Mexp". If I change that instruction to "M = M + Mexp" the problem goes away. Is M.Mexp not of type {Real,2}?? Any thoughts?
par = {5.7, 1.038, 1.016, 1.018, 1.015, 0.186, 0.003, 0.009, 0.004,
0.0003, 0.00004, 0.071};
dim = 69;
P = Compile[{{par, _Real, 1}},
Module[{i, L1, L2, L3, L4, L, q1, q2, q3, q4, gama, alfa, beta,
A},
L1 = par[[1]]; L2 = par[[2]]; L3 = par[[3]]; L4 = par[[4]];
L = par[[5]];
q1 = par[[6]]; q2 = par[[7]]; q3 = par[[8]]; q4 = par[[9]];
gama = par[[10]];
alfa = par[[11]]; beta = par[[12]];
A = ConstantArray[0.0, {dim, dim}];
A[[1, 1]] = -(L1 + q1); A[[2, 2]] = -(L2 + q2);
A[[3, 3]] = -(L3 + q3); A[[4, 4]] = -(L4 + q4);
A[[1, 2]] = L1; A[[2, 3]] = L2; A[[3, 4]] = L3; A[[4, 5]] = L4;
For[i = 5, i <= dim - 1, i++, A[[i, i + 1]] = L];
For[i = 5, i <= dim - 1, i++,
A[[i, i]] = -(L + gama + alfa*Exp[beta*i])];
A[[dim, dim]] = -(gama + alfa*Exp[beta*dim]);
Return[A]
]
];
OBJ2 = Compile[{{par, _Real, 1}},
Module[{M, Mexp, s, i},
Mexp = MatrixExp[P[par]];
M = ConstantArray[0., {dim, dim}];
For[i = 1, i <= dim, i++, M[[i, i]] = 1.;];
vec = ConstantArray[0., {dim + 1}];
For[i = 1, i <= dim, i++,
M = M.Mexp; vec[[i]] = Total[M[[1, All]]]];
Return[
Total[Table[((Q[[i]] - (1 - vec[[i + 1]]/vec[[i]]))^2)*
S[[i]]^2, {i, 1, dim}]]]
]
];João Janela2018-03-20T14:19:50ZPure Intonation on a Keyboard
http://community.wolfram.com/groups/-/m/t/1358606
Run this
Clear[into1, pureIntonationTree]
into1[l_List] := Block[{l0 = NestWhile[(1/2) # &, #, # > 2 &] & /@ l},
Union[If[MemberQ[l0, 2], Join[{1}, l0], l0]]
] /; VectorQ[l, (# >= 1) &]
pureIntonationTree[] :=
Module[{s0 = {1 (* c *) , (9/8) (* d *), (10/9) (* ,e *), (16/15) (*
f *), (9/8) (* g *), (10/9) (* ,a *), (9/8) (* ,h *), (16/15) (*
c *)}, s1, s2, \[Delta] = 1/43, h = 2^(1/12)},
s1 = into1 /@
NestList[FoldList[Times, #[[5]], Rest[s0]] &,
FoldList[Times, First[s0], Rest[s0]], 12];
s2 = ConstantArray @@@
Transpose[{Range[Length[s1] - 1, 0, -1], Length /@ s1}];
Graphics[{Blue, PointSize[\[Delta]/2],
Point[Transpose[#]] & /@ Inner[List, s1, s2, List],
{White, Opacity[0.1], EdgeForm[Black],
Polygon[{{1 - \[Delta],
13}, {1 - \[Delta], -1}, {h - \[Delta], -1}, {h - \[Delta],
13}, {1 - \[Delta], 13}}]},
{Gray, Opacity[0.6], EdgeForm[Black],
Polygon[{{h - \[Delta],
13}, {h - \[Delta], -1}, {h^2 - \[Delta], -1}, {h^2 - \
\[Delta], 13}, {h - \[Delta], 13}}]},
{White, Opacity[0.1], EdgeForm[Black],
Polygon[{{h^2 - \[Delta],
13}, {h^2 - \[Delta], -1}, {h^3 - \[Delta], -1}, {h^3 - \
\[Delta], 13}, {h^2 - \[Delta], 13}}]},
{Gray, Opacity[0.6], EdgeForm[Black],
Polygon[{{h^3 - \[Delta],
13}, {h^3 - \[Delta], -1}, {h^4 - \[Delta], -1}, {h^4 - \
\[Delta], 13}, {h^3 - \[Delta], 13}}]},
{White, Opacity[0.1], EdgeForm[Black],
Polygon[{{h^4 - \[Delta],
13}, {h^4 - \[Delta], -1}, {h^5 - \[Delta], -1}, {h^5 - \
\[Delta], 13}, {h^4 - \[Delta], 13}}]},
{White, Opacity[0.1], EdgeForm[Black],
Polygon[{{h^5 - \[Delta],
13}, {h^5 - \[Delta], -1}, {h^6 - \[Delta], -1}, {h^6 - \
\[Delta], 13}, {h^5 - \[Delta], 13}}]},
{Gray, Opacity[0.6], EdgeForm[Black],
Polygon[{{h^6 - \[Delta],
13}, {h^6 - \[Delta], -1}, {h^7 - \[Delta], -1}, {h^7 - \
\[Delta], 13}, {h^6 - \[Delta], 13}}]},
{White, Opacity[0.1], EdgeForm[Black],
Polygon[{{h^7 - \[Delta],
13}, {h^7 - \[Delta], -1}, {h^8 - \[Delta], -1}, {h^8 - \
\[Delta], 13}, {h^7 - \[Delta], 13}}]},
{Gray, Opacity[0.6], EdgeForm[Black],
Polygon[{{h^8 - \[Delta],
13}, {h^8 - \[Delta], -1}, {h^9 - \[Delta], -1}, {h^9 - \
\[Delta], 13}, {h^8 - \[Delta], 13}}]},
{White, Opacity[0.1], EdgeForm[Black],
Polygon[{{h^9 - \[Delta],
13}, {h^9 - \[Delta], -1}, {h^10 - \[Delta], -1}, {h^10 - \
\[Delta], 13}, {h^9 - \[Delta], 13}}]},
{Gray, Opacity[0.6], EdgeForm[Black],
Polygon[{{h^10 - \[Delta],
13}, {h^10 - \[Delta], -1}, {h^11 - \[Delta], -1}, {h^11 - \
\[Delta], 13}, {h^10 - \[Delta], 13}}]},
{White, Opacity[0.1], EdgeForm[Black],
Polygon[{{h^11 - \[Delta],
13}, {h^11 - \[Delta], -1}, {h^12 - \[Delta], -1}, {h^12 - \
\[Delta], 13}, {h^11 - \[Delta], 13}}]},
{White, Opacity[0.1], EdgeForm[Black],
Polygon[{{h^12 - \[Delta],
13}, {h^12 - \[Delta], -1}, {h^13 - \[Delta], -1}, {h^13 - \
\[Delta], 13}, {h^12 - \[Delta], 13}}]}
}, AspectRatio -> 1/2,
Frame -> True,
FrameLabel -> {None, None, "Tasten", "Tonarten"},
FrameTicks -> {{{{12, "C"}, {11, "G"}, {10, "D"}, {9, "A"}, {8,
"E"}, {7, "H"}, {6, "Fis"}, {5, "Des"}, {4, "As"}, {3,
"Es"}, {2, "B"}, {1, "F"}, {0, "C"}},
None}, {{{1, "c"}, {h^2, "d"}, {h^4, "e"}, {h^5, "f"}, {h^7,
"g"}, {h^9, "a"}, {h^11, "h"}, {h^12, "c"}}, None}}
]
]
to see how many different frequencies of the pure intonation are *bundled* onto one key on a keyboard
![enter image description here][1]
Observe how the C from the end of the cycle of fifths (12 fifths or 7 octaves) shifts with respect to the starting C. Observe also how the frequencies mapped to the same key on the keyboard deviate from each other less than they deviate from the nearest frequency of a neighboring key. So it justifies the equal intonation beside the fact that one can -impure- modulate to anywhere.
[1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=pureIntonation.PNG&userId=28832Udo Krause2018-06-19T06:16:07ZIndividually apply functions in a list to the same arguments,& list results
http://community.wolfram.com/groups/-/m/t/1358253
This does what I want:
In[688]:= #[x] & /@ {f, g}
Out[688]= {f[x], g[x]}
but is there a better way, maybe a native function particularly for this purpose? Or some pattern tricks I haven't thought of?Joe Donaldson2018-06-18T23:55:30ZControl a replacement step in any step and get the number of steps?
http://community.wolfram.com/groups/-/m/t/1342594
Given the following sets with names
s1={x1,x2}
x1={y1,y2}
y1 ={z1,z2}
When s1 is entered, the names would be replaced finally by all the sets. That is
Input s1
output::{{{z1,z2},y2},x2}
Question1: could we control a replacement step in any step? For example, we get
{{y1,y2},x2} so that y1 is not replaced?
Question2:: could we get the number of the replacement step, for example,to know, at step 2, we get {{y1,y2},x2}?Math Logic2018-05-21T20:20:58ZPool Noodle Spikey
http://community.wolfram.com/groups/-/m/t/1356464
I made a [compound of 5 tetrahedra](http://mathworld.wolfram.com/Tetrahedron5-Compound.html). It's surprisingly sturdy.
![noodle spikey][1]
This was built with [pool noodles](https://www.amazon.com/dp/B01BY1S2US/). Noodles are 55" (about 4.5 feet) long with a 2 3/8" diameter. Cut in half these give a Length/Diameter ratio of 11.5789. How close is that to a perfect Length/Diameter ratio?
![pool noodles][2]
First, lets build up a dodecahedron with simple vertices and an edge length of 1.23607 or $\sqrt5-1$.
From that dodecahedron, find the ten tetrahedra with edge length $2 \sqrt2 $ .
Then find five disjoint tetrahedra. The following code works.
tup=Tuples[{1,-1},{3}];
gold=Table[RotateRight[{0, \[Phi], 1/\[Phi]},n],{n,0,2}];
dodec=RootReduce[Union[Join[tup,Flatten[Table[gold[[n]] tup[[m]],{n,1,3},{m,1,8}],1]]]/.\[Phi]-> GoldenRatio];
tetra=FindClique[Graph[#[[1]]\[UndirectedEdge]#[[2]]&/@Select[Subsets[dodec,{2}],Chop[2 Sqrt[2]-EuclideanDistance@@N[#]]==0&]],{4},All];
compounds=FindClique[Graph[#[[1]]\[UndirectedEdge]#[[2]]&/@Select[Subsets[tetra,{2}],Length[Intersection[#[[1]],#[[2]]]]==0&]],{5},All];
Manipulate[Graphics3D[{
Table[{{Yellow,Red,Green,Purple,Blue}[[n]],Tube[#,thickness]&/@Subsets[compounds[[1,n]],{2}]},{n,1,k}],
Table[{{Yellow,Red,Green,Purple,Blue}[[n]],Sphere[#,thickness 2 ]&/@compounds[[1,n]]},{n,1,k}]}, Boxed-> False, SphericalRegion->True,
ViewAngle-> Pi/10, ImageSize-> 650],
Row[{Control@{{k,5, "number shown"},1,5,1, ControlType->Setter },Spacer[15],
Control@{{thickness,.11, "thickness"},.08,.20,.01, Appearance-> "Labeled" }}], SaveDefinitions->True]
![Manipulate 5 tetrahedra][3]
The "perfect" Length/Diameter ratio for rigid tubes seems to be 11.8565. The half-noodle ratio is 11.5789. Since foam is forgiving, I figured that would give a tighter figure, and that turned out to be correct.
For a regular dodecahedron with edge length 1, the inradius and circumradius are 1.11351 and 1.40125.
For an edge length of 1.23607, the inradius and circumradius are 1.37638 and 1.73204.
Based on the sizes of the tetrahedra, we can find the scaling factor of 11.4021.
Height in inches is about 31 inches tall. Distance between vertices is about 14 inches.
The notebook also has a color template. And that's how to build a spikey from pool noodles.
[1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=noodle5tetra.png&userId=21530
[2]: http://community.wolfram.com//c/portal/getImageAttachment?filename=noodles.png&userId=21530
[3]: http://community.wolfram.com//c/portal/getImageAttachment?filename=manipulate5tetra.png&userId=21530Ed Pegg2018-06-15T19:42:04ZIs Defer[] like single-quote from LISP?
http://community.wolfram.com/groups/-/m/t/1355524
I have been looking for something like LISP's single-quote. Is Defer[] it?Joe Donaldson2018-06-13T19:37:49ZPlot a wave in 3d
http://community.wolfram.com/groups/-/m/t/1357311
Hello
I wish to plot the following field, in the x-y-z space:
![enter image description here][1]
It is the electric field component of an electromagnetic wave travleing in the positive x-direction.
I came [across this question][2] form Mathematica stackexchange which has a few solution to plot the very-familiar EM wave, but I am interested in this rather different field, and only in the electric field.
I am not familiar with `Module`, but familiar with `Plot3D` and `ParametricPlot3D` only up to the level seen in the Documentation.
Thanks in advance for any "simple way" suggestions.
[1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=1588png.latex.png&userId=1344988
[2]: https://mathematica.stackexchange.com/questions/1987/how-do-i-plot-a-plane-em-waveUdi Behar2018-06-17T17:52:58ZPlot a function within a circle, e.g. stresses within a loaded disk?
http://community.wolfram.com/groups/-/m/t/1356287
I wonder if anyone knows how to plot results within a circle, e.g. stresses and strains within a loaded disc?jiri havir2018-06-15T13:19:38ZDelete cases using a "Complement" that accounts for multiplicities?
http://community.wolfram.com/groups/-/m/t/1357207
Hi, I have cats, fish and dogs.
In[173]:= animals = {cat, dog , fish, dog, cat}
Out[173]= {cat, dog, fish, dog, cat}
I want to take out the fish.
In[174]:= Complement[animals, {fish}]
Out[174]= {cat, dog}
Unfortunately Mathamatica killed one of my cat and one of my dog. I want a result that looks like:
Out[173]= {cat, dog, dog, cat}
or if Mathematica really wants to sort it, then:
Out[173]= {cat, cat, dog, dog}
How can I do it and make it fast?
Thanks ahead, János
P.S. The documentation says only that the result is sorted.smile sung2018-06-17T16:07:24ZExport strings without quotes to a .csv?
http://community.wolfram.com/groups/-/m/t/1357082
Writing a file from Mathematica for use by another program.
The output file will be a comma separated file.
Content of the file will be a combination of numbers and text.
The text in the output file should **not** have quotes around it.
Below is a sample data set and what I have tried so far.
row0 = {"h1", "h2", "h3", "h4", "h5", "h6"};
row1 = {"", "", "a1", 1.01, "", ""};
row2 = {"", "", "b1", 2.02, "", ""};
row3 = {"", "", "c1", 3.03, "", ""};
data = {row0, row1, row2, row3};
Export["data.csv", data];
Export["data.txt", data];
Export["data.dat", data];
Export["data.tsv", data];
Export["data.xls", data];
A summary of the results:
- data.csv -- has quotes around the strings
- data.txt -- has quotes around the strings and curly braces around each line
- data.dat -- no quotes around the strings, but the data is separated by tabs
- data.tsv -- has quotes around the strings
- data.xls -- no quotes around strings, data in appropriate columns, but this is an Excel file, which can't be read by the other program.
**One successful work-around:**: save the files as data.xls, then from Excel export to a .csv
Is there a way to Export the data so that it does not have quotes around the strings, but is separated by commas?
(Follow-up question: how to include quotes in some of the exported text. The Excel workaround fails for this case.)Robert McHugh2018-06-17T16:03:25Z