Questions on writing non-trivial programs in Mathematica. Do not use this tag for questions on plotting/graphics or for questions on doing mathematics with Mathematica, where the focus is more on the math than the program.

learn more… | top users | synonyms

4
votes
0answers
85 views

Delete duplicates by a criteria

Given that I have a set of points as below ...
0
votes
0answers
38 views

Long term growth model. Recurrence solution in NestList not behaving as expected compared to NDSolve

I'm trying to model the long term growth of a bioreactor according to monod kinetics: $ x'[t] = $$Qin \over V$ $( x_0-x[t]) + x[t]*\mu[t]\\$ $ s'[t] = $$Qin \over V$ $( s_0-s[t]) - x[t]$ $\mu[t] ...
0
votes
1answer
171 views

Is it possible to build/simulate/extract data from a System Modeler model completely inside a notebook using the MathModelica language syntax?

See examples in: http://www.mathematica-journal.com/issue/v10i1/contents/MathModelicaPaper/MathModelicaPaper_2.html It seems to be ruled out by the statement (Chapter 2 intro): "The subset of the ...
204
votes
21answers
25k views

What are the most common pitfalls awaiting new users?

As you may already know, Mathematica is a wonderful piece of software. However, it has a few characteristics that tend to confuse new (and sometimes not-so-new) users. That can be clearly seen from ...
2
votes
2answers
140 views

Issue with Set function

Tables often come with column headers. Indexing the columns with the header is a natural thing to do. Although a proper dictionary is the usual solution in such a case, I find it often practical and ...
0
votes
0answers
69 views

Can a whole Mathematica program be placed inside my functionMain? [on hold]

Consider this C code #include <stdio.h> int main() { printf("Hello world\n"); return 0; } A Mathematica equivalent could be ...
4
votes
0answers
49 views

Relaxation of Mass-Spring System with Pinned Masses

Problem Assume that four masses are connected to each other by springs while two of them are pinned down at their initial positions. Find the position of masses when system is at its minimum ...
-1
votes
0answers
24 views

question of nested for loops with 3 variables [on hold]

hi I got a simple trouble here. this is the question and my solution. does for work with a variable start with other variables? I have no idea why it got a {}. Some one help me out?
3
votes
1answer
52 views

subtleties about variable shadowing in Block[]

Let' s consider this packege : BeginPackage["myProgram`"]; myProgramF::usage = "arg + 1"; Begin["`Private`"]; myProgramF[arg_: 0] := arg + 1; End[]; EndPackage[]; ...
0
votes
2answers
111 views

Spiral roots, how?

I found this picture on the net, as I can play in mathematica
1
vote
1answer
27 views

Implicit region is not “valid” in ParamatricNDSolveValue function?

I am trying to solve a geometric problem with relation to my Schrodinger equation and its boundaries. Here is my code: ...
1
vote
1answer
90 views

Perceptron: Do loop not returning a value

I am trying to write a function that finds a simple best fit line for some data (Perceptron algorithm). Sadly it returns no output at all. Here's the code below: ...
-1
votes
0answers
22 views

Feasability question about object tracking in 3d space

Is it possible to use 3 different webcams to track an object in an xyz axis. If so, how would one do it?
3
votes
2answers
130 views

How can I create a 3D representation of an object with known coordinates and adjacency table in mathematica?

Basically I want to create an object with specified coordinates and adjacency table, like in page two of this article. I'm completely new to using Mathematica, any help would be great! EDIT: So I ...
-4
votes
0answers
53 views

How convert code from C# to Mathematica [closed]

I must realize algorithm. I know how to write it on C# but I can't convert it into code in Mathematica. It is my code: ...
6
votes
1answer
240 views

Association and rudimentary object-oriented programming

Doesn't Association provide us rudimentary object oriented programming via constructs like ...
339
votes
13answers
67k views

Where can I find examples of good Mathematica programming practice?

I consider myself a pretty good Mathematica programmer, but I'm always looking out for ways to either improve my way of doing things in Mathematica, or to see if there's something nifty that I haven't ...
1
vote
1answer
88 views

How can I invoke the solution of NDSolve to determine a parameter in my equation just inside NDSlove?

I am trying to solve a differential equation by NDSlove for $h(x,t)$. It reads $$h_t=h_{xx}-V_h-\lambda(t)$$ where $V_h$ is a given function of $h(x,t)$ denoted by ...
3
votes
1answer
135 views

Why even try the semantic constraints, if expression can't match the pattern structure?

This result is unexpected: Trace[MatchQ[{7}, {_?NumberQ, __}], NumberQ] (* -> {{NumberQ[7], True}} *) Why evaluate ...
13
votes
2answers
465 views

Generating Gelfand-Tsetlin patterns

I am doing some research on some combinatorial object called GT-patterns. They are generated from three parts of data. Two integer, partitions (sequences of weakly decreasing numbers), $\lambda = ...
5
votes
2answers
324 views

Find permutations with constraints without using Permutations

EDIT: To clarify, the bottleneck right now is available RAM, so any answer should keep that in mind (I cannot store all T! lists of length ...
3
votes
1answer
192 views

How to download pictures from webpage automatically?

Today, I read a good web page about love which owns many beautiful pictures. It is fussy for me to download every picture hand-by-hand, so I'd like to use Mathematica to do this case automatically. I ...
9
votes
3answers
160 views

Implement settable properties

I am looking for advice on implementing the following. (It is possible that the answer is that it is simply not a good idea to do this.) I would like to have an object similar to ...
0
votes
0answers
29 views

Retrieve rendered graphics via WSTP

I am planning on using Mathematica as calculation- and rendering backend for an application, i.e.: Call Mathematica via WSTP and by using EvaluatePacket have it ...
1
vote
1answer
122 views

Read expression from Mathematica via Mathlink C++

This is a simple C++ program to send an expression to the_Mathematica_ Kernel and get its response. ...
2
votes
3answers
134 views

How to extract both first and last rows of each group from unbalanced panel data

This is a follow up question form my last question click here. I have unbalanced panel data such as : ...
2
votes
3answers
178 views

How can I use NestWhileList instead of While in this case?

OK, the problem occurred when I challenged with Project Euler No. 10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. My code is: ...
6
votes
1answer
189 views

How can a function know in which function it was evaluated?

Hello my second question here might be very hard. I am asking for something "magical", if i define a function g and i call it inside a function f, how can g have information about the outer function ...
3
votes
1answer
97 views

How can I overload a function with multiple bracket-slots so f[a][b] and f[a] can coexist?

Maybe this is not even possible: I want to create a function f that can have two input brackets like: f[a_][b_:1]:= a*b and ...
2
votes
2answers
57 views

Need help updating an old Mathematica worksheet

I found a notebook that symbolically applies the multiple time scales method to any differential equations. I don't like just using other people's code so I am going through the author's work line by ...
17
votes
2answers
2k views

Open Excel file with Mathematica

I would like to open an Excel file and manipulate it as a COM object. While I'm able to open an instance of excel with ...
44
votes
0answers
897 views

Is this 30% slowdown in Mathematica 10 due to DownValues lookup time?

Running several numerical self-programmed packages I realized already some time ago that Mathematica 10 needed between 20 and 40% more time. I did already report this of course with a simple example ...
0
votes
1answer
79 views

How to improve this function that selects parameters from arbitrary distribution using Recursion?

Below, I have defined a function using Which to select model parameters based upon various conditions. My questions are: Is there any danger in writing this function using Recursion? Is there a more ...
0
votes
0answers
41 views

Trying to write a program to find an approximate harmonic function on a given graph using relation method

So given an undirected graph with two vertices that have fixed values assigned to them, a harmonic function is a function that assigns values to all other vertices such that the value assigned to each ...
4
votes
0answers
45 views

Using mathlink/WSTP with fortran

I would like to access Mathematica functions from within a Fortran program. I am unsure how to start (which is probably related to my lack of up-to-date Fortran knowledge). Is it necessary to write a ...
1
vote
3answers
349 views

Replace with position and order number

question conversion1 : Convert "[AA]AB[AA]BB[AA]B[AA]CCC" to "[A1A2]A3B1[A4A5]B2B3[A6A7]B4[A8A9]CCC" conversion2 : Convert ...
2
votes
2answers
108 views

How to plot points with error circles on map with latitude/longitude grid

I am currently working on a project to model the location of icebergs in the northwest atlantic. When an iceberg is sighted, an error circle is plotted around it (with a bivariate normal probability ...
0
votes
1answer
96 views
5
votes
0answers
89 views

How to construct custom operators with precedence?

I need to combine data structures in operations analogous to addition, subtraction, multiplication and division (and more). I need more than one operation of each type, i.e. more than one method of ...
1
vote
1answer
71 views

Hypothesis Testing and Formatting Output

I am trying to write a function that tests hypotheses and gives me a nice table but I can't. I need forum's help. For example, I have the following data ...
10
votes
5answers
520 views

Best way to modify values in a list of rules?

Recently I had to solve a problem similar to this: Let's say I have a list of list of rules ...
1
vote
1answer
104 views

Using FindMinimum with matrix input

I define the following function which spits out a number S when I feed it a dxd square matrix: ...
1
vote
1answer
48 views

Ways to protect certain parts of expressions

I am currently working on a quantum mechanics problem where I try to find equations that relate different states of a many-body system. The states are described by sets of pairs of integers, like ...
1
vote
0answers
83 views

Simulations using alternative initial conditions

With help from some of you guys here in this forum, I have developed the following code, which works perfectly. My questions are: how to automate the simulations with varying initial conditions. In ...
0
votes
0answers
25 views

Iterating a model with 2nd order difference equations using Manipulate [duplicate]

I have a model including first and second order difference equations. It works for the case of first difference equation, which is below: ...
4
votes
2answers
123 views

Nested mapping of a function

If I use the construct f[#] & /@ f[#] & /@ f[#] & /@ {a, b, c} my function works, but if I use ...
4
votes
2answers
97 views

Finding column-wise ranks of values in a multidimensional list

I often have to find ranks of values in a list. However, Mathematica does not have built-in functions for that, or may be I'm just not aware of them. I can easily find ranks of a row/column vector. ...
0
votes
1answer
40 views

Why does this cause an error? [closed]

In[73]:= f[x_] := Save["C:\\Users\\user\\Desktop\\file", x <> x] f["###"] During evaluation of In[73]:= Save::sym: Argument ...
2
votes
0answers
87 views

How to efficiently find parts of a string with beginning and ending specified?

I'm trying to find specific URL addresses from a html document. The addresses can be found between the strings "href=\"" and "\" class=\"listing". The problem is not including strings like this: ...
5
votes
3answers
341 views

Easiest way to create a binary variable

Binary variable is often used in applied statistics. However, I had a hard time to figure out how to create it. Somebody might have better idea how to do it. I have two variables say x and y as ...