Skip to main content

Questions tagged [code-generation]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
3 votes
0 answers
33 views

Mathematica call CompiledFunction from Python with Listable and Parrallelization attributes

I have a CompiledFunction e.g. this: ...
Okarin's user avatar
  • 31
1 vote
0 answers
28 views

Generator of limits of successions according to type of indeterminacy. Correct syntax

I am trying to make a limit generator with 3 columns, number of the exercise, the second column is the limit (perfectly written with n-->00), and the third column is the result of the limit. I have ...
wilma's user avatar
  • 11
1 vote
0 answers
81 views

How can I write the code for an inverse integral transform?

How can I code any type of integral transform with its inverse integral transform in Mathematica which gives the correct results and properties? Below is the example for Elzaki transform: ...
Kishor Kshirsagar's user avatar
0 votes
2 answers
116 views

How to find codewords from constraint equations? [closed]

I have edited this question to include more information about what algorithm I wish to use etc. Say if I have a linear binary code with parity check matrix $$H = \begin{bmatrix} 0 & 1 & 1 &...
am567's user avatar
  • 501
0 votes
0 answers
53 views

Part specification error

I am doing a solved exercise shared here. However, while running the code, I encountered an error on page-8, under the Dynamics section. with error : I think this error is due to the absence of ...
user444's user avatar
  • 2,446
1 vote
2 answers
144 views

Number operator

Suppose CR is my creation operator and AR is my annihilation operator. I have to show that ...
user444's user avatar
  • 2,446
1 vote
1 answer
307 views

Stepped Infinite Square Well [closed]

Here is the link for making the above graph for the Stepped infinite square well. The problem here is, all the eigenfunctions and energy eigenvalues are previously defined. Whereas, I want to use this ...
user444's user avatar
  • 2,446
4 votes
1 answer
191 views

How to convert any string of code to an input cell?

This is a generalization of this question, which already has very nice answers. Suppose str is a string of valid code, so that ...
WillG's user avatar
  • 960
2 votes
2 answers
279 views

How to generate input cells whose code is determined dynamically?

Following this post, I want to use code to generate an input cell with new code. However, unlike the linked post, I want my code to dynamically determine the new code to be printed in the input cell. ...
WillG's user avatar
  • 960
3 votes
1 answer
198 views

Convert boundary condition involving derivative to NeumannValue programmatically

As discussed in e.g. what causes the error "The dependent variable in the boundary condition needs to be linear" when using NDSolve? When FiniteElement ...
xzczd's user avatar
  • 66.8k
2 votes
1 answer
92 views

Activating part without resolving [[1]]

I'll try to make this question more clear in a little while. In the mean time, I'll ask directly the question which motivated it: Latin Square from submatrix Original Question I want, for instance, ...
Adam's user avatar
  • 3,956
3 votes
1 answer
79 views

Have Button fire with both Kernel and FrontEnd

Here's some code which, when evaluated, types an expression in the cell below it: ...
Adam's user avatar
  • 3,956
1 vote
1 answer
166 views

How to use Through by default on numeric functions?

I've used the following code to simulate defining operations between functions: ...
jjagmath's user avatar
  • 411
0 votes
0 answers
85 views

How to formulate NDSolve[...] for a two-sector SIR model

The following Code aims to simulate the employment effects of a pandemic, drawing on the conventional SIR model. I extended the SIR model with two economic sectors (...
Tugrul Temel's user avatar
  • 6,223
3 votes
1 answer
103 views

Is it possible to automate definitions given with TagSetDelayed?

I am using the following two lines of code relatively frequently f/:Plus[f[x_], f[y_], z___]:=f[x+y]+z f/:Times[c_, f[x_]]:=f[c x] and I was wondering if it is ...
joka's user avatar
  • 332
0 votes
1 answer
73 views

Compiling RiccatiSolve LQRegulator gains

Given some specific matricies, numA, numB, numP, q and r to calculate LQR gains, one can use simply LQRegulatorGains or solve the same via ...
DrMrstheMonarch's user avatar
5 votes
3 answers
428 views

How to programmatically modify a function definition

I would like to know an efficient method (without converting Mathematica Code to strings and string processing) of modifying a function definition programmatically. For example, I would like to tidy ...
Iconoclast's user avatar
5 votes
1 answer
116 views

Turn definitions into rules

I know that this seems to be unnecessary, but here I have a bunch of assignments, like around 50, and I want to create rules for all these to have the freedom to apply these rules only on certain ...
Ying Zhang's user avatar
2 votes
0 answers
67 views

Microcontrollerkit No longer compiles code after update

I recently restarted a project where I used MicrocontrollerKit to generate code for me into the Wiring language to be then imported into arduino IDE for editing and ...
DrMrstheMonarch's user avatar
1 vote
0 answers
67 views

Optimal code generation for evaluation of a fixed set of multivariate rational polynomials

Given a set of multivariate rational polynomials, is it possible to find the optimal (shortest or least expensive in some other sense) sequence of arithmetical operations, such that it results in ...
aooiiii's user avatar
  • 609
0 votes
2 answers
309 views

Assign a variable to a condition only if the condition is met using Which

If I have a conditional of the form: Which[Round[b[i], 0.1] == 74,1,40 < b[i] < x,2] where b[i] represents a number that ...
John's user avatar
  • 471
1 vote
0 answers
49 views

General question about RSolveValue and general programming

If I have the following code: ...
John's user avatar
  • 471
1 vote
1 answer
123 views

How to solve first order complex differential equation?

I want to solve these differential equations and want to get the value of 'a1'. I used this code given below but it is not showing any result. If anyone can resolve this will be appreciated. ...
vini's user avatar
  • 83
6 votes
1 answer
288 views

Understanding code generated by MicrocontrollerEmbedCode

I've been using MicrocontrollerKit for a while now to generate code for little projects, inverse pendulums, filters, etc. Generally it works well. I am now currently trying to design a LQI (Linear ...
DrMrstheMonarch's user avatar
0 votes
2 answers
72 views

How can I index a function with the type of dataset used

I have the following code which serves my purpose for a single matrix input. For one or two matrices, the operation can be done manually, but I have 65 matrices and ...
Tugrul Temel's user avatar
  • 6,223
6 votes
0 answers
159 views

MWE for compiling functions into standalone DLL and calling them in Python?

I have read calling-a-compiledfunction-dll-from-outside-mathematica and the CodeGeneration tutorial and scanned other related questions too numerous to mention, but I am still unclear about how to ...
Julian Moore's user avatar
  • 2,560
8 votes
1 answer
279 views

Converting Piecewise function to C code

I'm trying to convert a function to C Code f = D[Piecewise[{{x^2, -10 < x < 0}, {x, x > 0}}], x] I decided to scan through conditions and corresponding ...
Vsevolod A.'s user avatar
2 votes
1 answer
95 views

Compiled library crashes at WolframLibraryData_new

I am using CreateLibrary to create a dynamic library of a Mathematica function, so that it can be linked into standalone code, but I run into segmentation faults (...
Marijnn's user avatar
  • 287
3 votes
1 answer
203 views

Easy code help about matrix. How to change the elements in a given matrix?

For example I have a matrix A[1,1]={1,2,3,4}; Now I want to change the second element of A[1,1] to ...
郑新然's user avatar
0 votes
2 answers
638 views

How to get a peek at the source code for demonstrations if there is no source code provided [closed]

NOTE: The prequel to my question has been answered before here In the case of the question linked above, the author's code was available. But I would like to know if it is possible to reveal the code ...
Rene Duchamp's user avatar
  • 1,419
0 votes
1 answer
124 views

Solving a difficult differential equation

I've the following DE, describing a physical phenomenon. And the prupose is to solve that DE using Mathematica $$x(t)\cdot r+x'(t)\cdot l+a\cdot\ln\left(1+\frac{x(t)}{b}\right)=0\space\...
Jan Eerland's user avatar
  • 2,001
2 votes
1 answer
560 views

NDSolveValue solutions differ based on number of equations

Short version: Do the methods (or other things the function uses to solve the equations like time steps or error estimates) that NDSolveValue uses by default depend on the types and quantity of ...
BioPhysicist's user avatar
  • 1,124
0 votes
1 answer
2k views

Making a table of solutions from NSolve or Solve

How can I generate a table of solutions to an equation such as this: Solve[{a^m+b==c,b-m==a+Sqrt[n]},{a,b}] for some given values for $n$ and $m$.
Jan Eerland's user avatar
  • 2,001
2 votes
1 answer
82 views

How generalizes (automate) recursive code

This is a small version of my code (for n=2): ...
Filburt's user avatar
  • 578
3 votes
1 answer
851 views

How can I automatically generate usage messages?

When programming, I try and name my functions and arguments clearly and document them with usage:: so I can keep track of everything; e.g., ...
mikemtnbikes's user avatar
2 votes
1 answer
126 views

Optimizing an expression – find identical subexpressions and substitute them

I'd like to simplify a complex symbolic expression expr by substituting and listing subexpressions that appear more than once in ...
sarasvati's user avatar
  • 215
1 vote
1 answer
58 views

SymbolicC namespace?

What is the equivalent for C++'s using namespace ...; in SymbolicC package of mathematica and are there any good resources like ...
user13892's user avatar
  • 9,443
2 votes
2 answers
191 views

Should I implement an iteration with a While-loop? [closed]

I have written a code that uses a guessed eigenvector (avecs) to construct a Hamiltonian (my hamiltonian depends on its own eigenvectors, so I can not solve it directly and I need to use iteration (...
Delaram Nematollahi's user avatar
0 votes
0 answers
110 views

How to create a file that runs without displaying the code (similar to an .exe)

I am writting a code that could be useful for some people. The program will be free but I would like to protect the code. As I am not good at explaining myself I will simply illustrate my question ...
neuron's user avatar
  • 1
-3 votes
1 answer
117 views

Help with NDSolve for system of odes [closed]

Can someone please tell me what I am doing wrong? I am trying to solve a system of odes using NDSolve. The code I have written is as follows: ...
Matt Rueben's user avatar
3 votes
2 answers
107 views

Division sieve operations in Mathematica

I am just wondering how to easily compute this problem using Mathematica. What Percent of Even Integers are Divisible by either 6, 20, 28 or 70? My purpose is to extend this to a finite number of ...
Jr Antalan's user avatar
3 votes
2 answers
872 views

Write Power in CForm[] as multiplication instead

Is there a simple way to make Mathematica write CForm[p^2] not as Power[p,2] but rather as ...
Physics_maths's user avatar
13 votes
0 answers
224 views

Bug: Library functions from older versions of Mathematica may crash in Mathematica 11.1 and conversely

The following is a confirmed bug [CASE:3846875] that turned up in the prerelease 11.1.0 and is not solved in the official release. This is a small example. Execute the following commands in ...
Fred Simons's user avatar
  • 10.2k
3 votes
1 answer
57 views

SymbolicC`: Is there a CChar, i.e. a way to generate a single character constant?

I am aware of CConstant and CString, but neither can output the single-char literal 'a'
masterxilo's user avatar
  • 5,739
2 votes
1 answer
159 views

Applying a function for several sets of input [duplicate]

I'm trying to understand the Wolfram language and copied some examples from the documentation into a workbook and then tried to work through examples of my own. I'm attempting to evaluate a function ...
IronMarshal's user avatar
1 vote
0 answers
123 views

What Does Slot Mean In Root Output and How To Translate It To Code? [duplicate]

I have the notebook below which produces the correct numerical output but the CForm function doesn't appear as though it is working correctly (or I don't know how ...
CoryG's user avatar
  • 111
8 votes
3 answers
621 views

Metaprogramming: creating compiled functions from inter-dependent code blocks

I want to create a compiled function from inter-dependent code blocks. Here is a minimal example showing the salient features based on strings: ...
mrupp's user avatar
  • 777
3 votes
1 answer
583 views

Christmas fun with Mathematica [closed]

In a previous post we saw how we can create animated snowfall. So, I was wandering what else, related to Christmas, we can do with Mathematica? Perhaps, drawing a tree full of ornaments and lights... ...
Vaggelis_Z's user avatar
  • 8,790
1 vote
1 answer
482 views

Writing text inside Venn Diagrams

I found this question which is extremely cool and amazing How to plot Venn diagrams with Mathematica? which also helped me in plotting and creating Venn Diagrams. But there is something that is ...
Enrico M.'s user avatar
  • 961
6 votes
2 answers
747 views

OptimizeExpression to C code

Is there a function which turns optimized expression to C code? Calling Experimental`OptimizeExpression[ Sin[x] + Cos[Sin[x]]] returns ...
tom's user avatar
  • 295