Questions tagged [broken-code]

Use this tag only if you did your research and you still don't know why your syntactically correct code does not work.

Filter by
Sorted by
Tagged with
20 votes
4 answers
1k views

What's wrong with this FFT-based Von Kármán vortex street simulation?

About 9 years ago, I came across this interesting website, and found the following paragraph with a broken Mathematica code sample: When fluid passes an object, it can leave a trail of vortices ...
xzczd's user avatar
  • 63.4k
10 votes
2 answers
5k views

How to set up a simple Monte Carlo simulation?

there is a 1% chance that there will be a scattering event, if there is a scattering event the direction of scattering will be determined by a random sample of the custom[a_] function and if there is ...
AW1991's user avatar
  • 153
10 votes
2 answers
1k views

What is the Difference Between Rule (->) and RuleDelayed (:>)?

I am new to Mathematica so this question may seem rudimentary. Sorry for that! :) I want to implement the well-known property of Kronecker's Delta $$\Sigma_{i=1}^{n} a_i \delta_{ij}=a_j,\quad 1 \le ...
Hosein Rahnama's user avatar
7 votes
2 answers
514 views

Sound synthesizer using Manipulate

Sound synthesizers, both digital and analog, often include a parameter section for shaping the amplitude of a sound wave over time. This parameter section is commonly known as an "ADSR EG" (attack, ...
useranonis's user avatar
7 votes
1 answer
425 views

What is wrong with this code? (Usage of FunctionInterpolation and how to make code efficient)

I am trying to create an interpolation out of a function that comes from an improper integral. The end goal is to make a 3d plot over a specific region. Specifically, I have the following code: ...
AG1123's user avatar
  • 561
6 votes
2 answers
171 views

A box structure with a depth exceeding the maximum allowed depth was encountered

I am trying to perform the task in Mark McClure's article Parametric L-Systems and borderline fractals. I have copied his opening code on the first three pages: ...
David's user avatar
  • 14.8k
6 votes
2 answers
174 views

NonlinearModelFit inside Manipulate

I can't understand why this behavior with my code... I'm trying to visually adjust the best parameters to fit my model, everything is working fine, less the part of adjusting the model. ...
user avatar
5 votes
1 answer
133 views

How to compile sum over the compiled expression?

Consider the following toy code: ...
John Taylor's user avatar
  • 4,642
5 votes
1 answer
562 views

Label State Space Models converting ODEs

Say I have a set of differential equations not necessarily in first order form. I would like to build the corresponding state space model. When equations are many and long, it becomes difficult to ...
Mirko Aveta's user avatar
  • 2,150
4 votes
2 answers
515 views

Euler-method implementation

How can I implement this pseudocode in Mathematica? Algorithm: ...
Birgitt's user avatar
  • 167
4 votes
4 answers
271 views

Efficient generation of n-bit base-m Gray code with adjacent bit changes

How can I generate n-bit base-m Gray code in Mathematica, where only 1 bit changes at a time and all possibilities are covered? I have been hitting my head against a metaphorical wall for a few hours ...
More Senne's user avatar
4 votes
1 answer
366 views

Why Min cannot be used as constrains of NMinimize?

I met a strange problem when trying to do an optimization. Initialization code, ...
saturasl's user avatar
  • 1,429
4 votes
2 answers
164 views

Adding numbers with defined precision produces incorrect result

I've tracked a bug in my code down to the problem of adding two numbers together, with the left argument having machine precision, e.g by 3` . The issue is, if ...
shanedrum's user avatar
  • 557
4 votes
1 answer
894 views

Issue in ParallelTable after evaluating another function using NDSolve and FindRoot. What is wrong with this inverse?

I am trying to find the inverse of a function which is defined through NDSolve and NIntegrate. The question is pretty similar ...
Santiago's user avatar
  • 1,201
4 votes
1 answer
123 views

How to get rid of 0.000 and change 5.*10^n to 3*10^n on Log Plots?

Using Version 13.1.0.0 (Edit: MacOS BigSur Version 11.6, Hardware M1 chip) In order to show some Log (or LogLog) plot features that I find annoying, here is some code: ...
Carl's user avatar
  • 695
3 votes
2 answers
2k views

Create Table of replacement rules

I want to create a table of replacement rules. ...
olliepower's user avatar
  • 2,224
3 votes
3 answers
1k views

For-loop not working as I expect

I want to do this: When 10 <= t < 130, give t -> 1; When 130 <= t<300, give <...
Yuuhsing Tuan's user avatar
3 votes
2 answers
640 views

Solving a reaction diffusion dystem [closed]

I have a problem solving a numerical reaction diffusion equation. It emits the following message: RecursionLimit::reclim2: "Recursion depth of 1024 exceeded during evaluation How can I solve this ...
Thimo Merkel's user avatar
3 votes
2 answers
166 views

Colouring stacked 2D in 3D

...
user84456's user avatar
  • 1,524
3 votes
1 answer
137 views

some confusion about ReplaceRepeated

This is Right. NestWhile[Log, 100, # > 1 &] {100} //. {x_} /; x > 1 :> {Log[x]} 100. //. x_ /; x > 1 :> Log[x] This is wrong,why? ...
Apple's user avatar
  • 3,653
3 votes
2 answers
120 views

Why does introducing value of variable for NDSolve via function not work for this problem?

I am very confused and even restarted Kernel several times (Mathematica 13.1 Windows 10). However, I fail to understand why one evaluation of NDSolve works while a ...
Ali Hashmi's user avatar
  • 8,900
3 votes
2 answers
291 views

Extract mesh coordinates from a LaplaceSolution Plot

I have made a code for the solution to a particular problem involving the Laplacian, and after plotting in 3D the resultant potential, I have tried to look for a ...
Mounice's user avatar
  • 85
3 votes
1 answer
115 views

How to add element to a list once and then the last element will get replaced in the following iterations?

...
user36426's user avatar
  • 3,225
3 votes
1 answer
376 views

Optimization of power tower fractal generator [closed]

I tried to optimize the code for generating power tower fractals from here. As the author suggested, I tried to memorize the points already tested in a list. Here is my code : ...
deltux's user avatar
  • 55
3 votes
2 answers
744 views

EdgeRenderingFunction question

Bug introduced in 9.0 and fixed in 10.0.0 (Edit 1 : I added this paragraph after the original post, for context) Some context for this question can be found in another post (https://mathematica....
pdini's user avatar
  • 475
2 votes
5 answers
2k views

Where did I go wrong with my implementation of finding a plane tangent to a surface?

I am working on finding the plane tangent to a paraboloid at a given point. My code: ...
xyz's user avatar
  • 595
2 votes
1 answer
222 views

Stability classification code for dynamic system

I'm interested in carrying out stability analysis on discrete dynamic systems, as was done in this paper. The Author used their function ...
zeraoulia rafik's user avatar
2 votes
1 answer
367 views

Getting errors when I try to evaluate code taken from Trott's Mathematica Guidebook for Graphics

I would like to learn how to make high quality images in Mathematica. In my pursuit, I have come across Michael Trott's Mathematica Guidebook for Graphics. I have been trying some of the examples, ...
Olsen's user avatar
  • 21
2 votes
2 answers
515 views

Weighted mean of complex exponential function using NIntegrate

I have defined the following functions: ...
frankundfrei's user avatar
2 votes
1 answer
176 views

Python Code to Mathematica for Classical Map of Kicked Top

I am trying to convert this Python code for Classical map of kicked top to Mathematica. For a single trajectory, I am able to ...
user84456's user avatar
  • 1,524
2 votes
1 answer
166 views

How to combine Graphics primitives in a DynamicModule without breaking it

I am trying to present Graphics primitives dynamically. I want the displayed image to be able to update after the user changes the controls. An example would be ...
user42582's user avatar
  • 4,185
2 votes
1 answer
51 views

User Implemented SHA-1 is failing for strings of length >512 bits

So, earlier, I posed a question regarding getting a user implemented SHA-1 hash function to work correctly. Well, I fixed the problems, cleaned it up a little bit, but now I have the problem for when ...
Shinaolord's user avatar
2 votes
1 answer
162 views

Code for finding multiple roots only finding two

I've an issue with my code. I am basically trying to get the n-th root of a function. My code finds two roots correctly, but for others, which I think should be distinct, I get the two roots repeated ...
Pagode's user avatar
  • 121
2 votes
1 answer
265 views

Why different output is obtained for the same code (Mathematica 10.1)?

I wrote some code in Mathematica: ...
Misery's user avatar
  • 2,570
2 votes
1 answer
126 views

Python to Mathematica code bug

I have an assignment in Mathematica, which I've already solved using Python and it's a bit hard to convert the code. Here's what I have done so far: ...
mandella's user avatar
  • 133
2 votes
1 answer
121 views

How to partition $[0,1]$ into $m$ equal sub-intervals and count the number of sub-intervals that intersect with my cantor set?

Suppose I define my cantor set as ...
Arbuja's user avatar
  • 39
2 votes
0 answers
46 views

ParallelTry Hangs on previously working code

When I run the below ParallelTry command, it just sits on it and says its being evaluated, but I cant abort it, it doesn't return what I am expecting, and I have to ...
shanedrum's user avatar
  • 557
2 votes
0 answers
43 views

How can I fix this cycle in order to iterate several times? [closed]

I have been working on a code whose only purpose is to get the mean value over four numbers. And I managed to do one cycle, however after trying to repeat this process until a certain condition is ...
Mounice's user avatar
  • 85
2 votes
1 answer
1k views

NDSolve: Indeterminate expression 0. ComplexInfinity encountered? [closed]

The following code give errors that I don't understand. Could you please suggest a method to solve these differential equations? ...
Bikramjit's user avatar
1 vote
2 answers
432 views

What's wrong when I use NestWhileList?

Problem : A Happy number is a number that if one squares its digits and add them together, and then take the result and square its digits and add them together again and keep doing this process, ...
xyz's user avatar
  • 595
1 vote
3 answers
540 views

Solving cubic equation with unknown coefficients

I am trying to solve a cubic equation with unknown coefficients (p and t), here is the code: ...
SuperCiocia's user avatar
  • 1,472
1 vote
3 answers
77 views

Labeling point coordinates in path graph using VertexLabels

Question: How do we label point coordinates in Pathgraph using VertexLabels. Suppose we have a list of points ...
Arbuja's user avatar
  • 39
1 vote
2 answers
824 views

Michaelis–Menten kinetics using Gillespie Algorithm

I am trying to implement Michaelis–Menten kinetics using Gillespie Algorithm. $$\text{Reaction 1:}\quad E+S\rightarrow C$$ $$\text{Reaction 2:}\quad C\rightarrow E+S$$ $$\text{Reaction 1:}\quad C\...
OkkesDulgerci's user avatar
1 vote
1 answer
879 views

Error message: Coordinate index 0 is out of range for the enclosing GraphicsComplex

I am unable understand following error message: Coordinate index 0 is out of range for the enclosing GraphicsComplex. How to fix it? Attached data here: pts and polygons. See also end of question. <...
User12309's user avatar
  • 427
1 vote
3 answers
267 views

Creating an interactive plot that zooms into the function

Suppose we want an interactive plot for the code: ...
Arbuja's user avatar
  • 39
1 vote
2 answers
233 views

QR decomposition using Gram Schmidt [closed]

First of all I don't want to use the reflection method, only Gram-Schmidt. So here's the program for Gram-Schmidt: ...
John Hall's user avatar
1 vote
1 answer
99 views

Please help me find my error [closed]

When I use variables, errors are encountered. But when I change the variables to constants, I don't have a problem, but I wonder why. ...
이동민's user avatar
1 vote
1 answer
108 views

How do we find the limit of my code?

Suppose we have the following: ...
Arbuja's user avatar
  • 39
1 vote
1 answer
103 views

Outputting probability of rolling 6 dice N times, generating a new output each roll

I am looking to output the probability of n classic six-sided dice but I am not sure how to go about starting. This is what I have written out so far, but no way to go about accounting for n dice for ...
Brandon Evans's user avatar
1 vote
1 answer
71 views

Help Calculating My "Deviation"

I created a "distribution deviation" where for $\left\{a_1,...,a_k\right\}$ we take all take the mean of all combinations of $\frac{\min\left\{a_{i},a_{j}\right\}}{\max\left\{a_{i},a_j\right\...
Arbuja's user avatar
  • 39