# Tagged Questions

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.

36 views

### ReplaceAll - Position of list arguments not displayed properly [closed]

This code A[1, 2, 4, 5] /. A[a___] -> Position[{a}, 4] return {} Why this code not return 3 (a position of number 4) ? I ...
91 views

### Ask about the variable and constants in partial derivative in a loop

EDITED I have a function in a list like : func={2(x^2)+x*y+3(y^2)}; I want to have a UI that ask me which parameter (x or y) is a variable in a ...
234 views

### Fibonacci Line Search Method

I am attempting to write a code to find to bracket the minimum of a function using the Fibonacci Line Search Method, I believe my code is well written but I am not ...
548 views

### FindShortestTour to solve Traveling Salesman Problem

I'm trying to write my own code to find the shortest route but I'm lost on how or where to start. Does anyone have any idea how the FindShortestTour function works? What type of algorithm or structure ...
101 views

### InterpolatingFunction used to work with mathematic 7 but not working with mathematica 10

This code is used to work perfectly with Mathematica 7 and now it is not working with Mathematica 10. Any help is appreciated. CL05 = InterpolatingFunction[{{0.5, 11.99999999999999}}, {1, ...
91 views

### Subroutine execution repetition

I like to write second and third lines repeated operation only once as a separate module with some Name. In each main program line a set of different set boundary conditions data is given,Name invoked ...
235 views

### For loops in Mathematica [duplicate]

I'm actually the first time using loops in Mathematica. For example, I have: For[i = 1, i <= n, i++, For[j = 1, j <= n, j++, ....] How it is possible now ...
225 views

### More efficient implementation for comparing coefficient lists in a Do-loop

I'm wondering how to speed up the following code so it actually computes for $n=2$: ...
1k views

### Euler's method for system of differential equation

I need to program Euler's method to solve a system of two diffferential equations of first order. Fist, I have programmed the Euler's method for just one differential equation: ...
172 views

### How to automatically put the part of a variable name after the first letter in symbolized subscripts?

So here is what I have thought: Use ToString and StringLength in order to get the number of characters in the variable name. If it is bigger than one, change variable name by putting everything but ...
112 views

...
318 views

### Pseudo-code for rules of probability?

I am having a hard time in Stats understanding some basic rules of probability and set-theory, namely $P(A|B)$, $P(A\ \textrm{and}\ B)$ and $P(A\ \textrm{or}\ B)$ where $A$ and $B$ depend on each ...
373 views

### Handling Overflow

I have a notebook which takes in a user-defined function and starting value and tracks the orbit of the particle under iteration of the function. The problem occurs when the user enters a starting ...
305 views

### Automating sequential import of data from web

I am trying to import data from multiple web pages hosted by a single online source. The data is posted by the source as one data set per web page for each week of the year. I would like to import the ...
254 views

### How do I slice an image of size “width × height” in n² pieces of size “width / n × height / n”?

Background: What I want is to make a jigsaw from an image. (A simple one where the pieces are polygons.) I have the following strategy in mind. Create a set of polygons and assign images (or just the ...
125 views

### How to connect some separate components with shortest total length line

Maybe this post too hard.So I try to make a simple version to research. Simulating a simple graph than that post. ...
105 views

### How to write or extend operators like $*\!\!*$

I'm stuck on trying to define simplification rules for NonCommutativeMultiply, much like ExpandNCM found in Documentation Center, under Applications. For example, I'd like ...
87 views

### Functions behaving weirdly

The following code f[k_, n_] := Sum[2*(1 + Sum[f[k - j, n - m - j], {j, 1, k - 1}]), {m, 1, n - k + 1}] f[4, 7] f[4, n] gives the output: ...
78 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 <...
140 views

### How do you apply an algorithm individually to an array with many graphs

I have and array with many graphs to which I want to apply an algorithm (below) to each graph in an array that contains all my graphs. ...
633 views

### Plotting an orbit using first principles [duplicate]

I am fairly new to Mathematica, but I am trying to plot an orbit of the Earth around the sun using the equation: $\quad r(t+dt) = (2 - G*M*dt^2/r^3)*r(t) - r(t-dt)$ I need to break this into ...
242 views

### Programming- cryptography

I have defined the following function in Mathematica to get a SET OF m SETS (these sets are the codes {p,q,d,e,n} for the ...
402 views

### Plotting in the “Manipulate” function - simple coding

Hello Mathematica community, my name is Preston! I have a real quick question that should be easy to answer. Alright, so for a research project that I'm involved it at my university, I need to ...
123 views

### how to generate repeatable Unique streams?

I need to label some data in arbitrarily nested ragged lists, with a stream of unique labels. It's very convenient if the labels are consecutive integers, starting at ...
229 views

### Calculating mean of multiple stochastic processes and setting a lower threshold

Thanks to “Rod Lm” I got some very nice input for the following problem. My intention is to simulate within a Manipulate function a given number of possible stock ...
319 views

### Checking equality with ComplexInfinity and testing whether a function is (mathematically) undefined

This seems ridiculously basic, but I cannot find anywhere explaining how to do it. If you evaluate certain undefined functions like 1/0 or ...
119 views

### How can I find the row differences of a matrix?

How can I compute the row differences of an m x n matrix to obtain an m-1 x n matrix; that is, given how do I obtain
294 views

### Inputting two arrays for a module in Mathematica

I am relatively new to the Mathematica enviroment and not sure where I am going wrong. I have evaluated the question and understand it, but dont know how to exactly create a module for it. The ...
258 views

### How can Time be made to go backwards?

I would like to make a countdown timer, but cannot find a reliable method to make the DateList[] function reverse. The not so robust code for the Digital Clock with the display of seconds follows: ...
120 views

### Which data tabulation concept is best suited for discrete dynamic programming problems (e.g. for optimum series of account withdrawals)?

A bank account has starting balance, which shall be completely withdrawn in n steps, such that the sum of benefits of withdrawals is maximum. Remaining balance yield interest between steps such that ...
42 views

### Question about transforming a list of rules

Consider the following list: ...
73 views

### Help with getting an output from some calculations

I entered the following from @Rahul's answer in "Help with finding the point(s) inside a closed shape with the highest average ray length?" below my post. He told me I should enter his data one input ...
84 views

### How to find line error in init.m file?

I have been changing my init.m user file. It runs fine, but I do get this error below. What does it mean by line 55? What constitutes a line? Are lines separated by "," or ";" or both? Or is it ...
172 views

### Code for Newton's Method [closed]

I'm trying to write a program for finding the root of f(x)=e^x+sin(x)-4 by Newton's Method but I'm instructed to not use the built in function and write the code from scratch. I'm pretty new to this ...
112 views

### How to write a loop

I try to create a table which will describe traffic paths at a crossroads. Instead of using copy-paste repeatedly, I would like to write a loop. For example: ...
245 views

### How to properly use conditionals inside NDSolve

Currently I am working with Mathematica to learn the program, and I'm confused what exactly is wrong with this code. ...
70 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: ...
269 views

### How would I obtain a list of column names in a Dataset?

I really love the addition of Dataset to Mathematica. I would like to write a basic utility function that exports a Dataset to Excel. Is there a way to get a list of column names from a Dataset?
65 views

### How to get the outermost command evaluated first?

I have an expression like ToString[Stuff[...]]. I plan on having the Stuff[...] be manipulated as a string according to the output of other parts of the program. The problem is that Mathematica tries ...
68 views

### Changing a tag when one function is passed into another using UpValues

I have two complicated functions f[x,y] and g[t]. Before the main evaluation code in g[expr]...
72 views

### Elements of a List according position in axis

({{a, b}, {c, d}}) a, b, c and d are Lists of 300 length. Their first 4 elements must specify their position in the column (1 column, 2 column, etc) and the ...
121 views

### Clearing arguments passed to a Module

Is there a possible way to clear the arguments passed to a module to release some memory. I believe that arguments passed to modules are passed by value rather than pass by reference. e.g. I have the ...
219 views

This is a simple C++ program to send an expression to the_Mathematica_ Kernel and get its response. ...
75 views

### MLEvaluate() Function Gives Error

I am trying to link my C++ program to Mathematica Kernel. I am trying to use the MLEvaluate() evaluate but I receive an error while compilation. My codes are as below: ...
128 views

### How to return matching sublists or empty list

How to return matching sublists or empty list m1 = {{1, 0.5}, {2, 0.4}, {3, 0.1}}; m2 = {{1, 0.5}, {0, 0.4}, {0, 0.1}}; Commonest[Join[m1, m2]] out: ...
337 views

### A problem on generating convex hull

For example, I typed the following: ...
280 views

### Making an animated simulation without procedural loops

I'm still new to Mathematica and this is the first time I've wanted to do something more complicated than plotting and changing parameters of mathematical functions. I want to make a simple ...
190 views

### How can I import sound from within a Manipulate expression?

I want to import sound from a file, record, and import sound. ...