Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [code-generation]

The tag has no usage guidance.

0
votes
1answer
77 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\...
2
votes
1answer
172 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 ...
0
votes
1answer
199 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$.
2
votes
1answer
71 views

How generalizes (automate) recursive code

This is a small version of my code (for n=2): ...
3
votes
1answer
133 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., ...
1
vote
1answer
77 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 ...
1
vote
1answer
43 views

SymbolicC namespace?

What is the equivalent for C++'s using namespace ...; in SymbolicC package of mathematica and are there any good resources like ...
2
votes
2answers
128 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 (...
0
votes
0answers
76 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 ...
-3
votes
1answer
84 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: ...
3
votes
2answers
98 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 ...
3
votes
2answers
329 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 ...
13
votes
0answers
189 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 ...
3
votes
1answer
48 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'
2
votes
1answer
62 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 ...
1
vote
0answers
68 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 ...
7
votes
3answers
485 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: ...
3
votes
1answer
227 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... ...
1
vote
1answer
221 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 ...
6
votes
2answers
357 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 ...
6
votes
1answer
120 views

Applying And to a list inside a Function

And has HoldAll attribute and test its argument by sequence. But doing And@@{} will lost ...
5
votes
1answer
91 views

SymbolicC`CSwitch basically broken?

The CSwitch manual page gives the example CSwitch["val", 1, CAssign["i", 10], CBreak[], 2, CAssign["i", 3], CBreak[]] // ToCCodeString which generates this ...
2
votes
0answers
103 views

SymbolicC/SymbolicCUDAFunction generating C/C++ parser?

I wish to do some program transformation and analysis. Is there any package that generates SymbolicC expressions from C code? In a sense I'm looking for the ...
5
votes
2answers
657 views

Compute Hessian of function symbolically

This question could equally apply to the computation of other symbolic transformations of a function, but I use the Hessian as an example here. Consider a two-variable function ...
6
votes
6answers
268 views

Automatically add debug contents to a program

Sometimes I'll use Print[1] or Print[n] to debug in a long loop, but it's really a boring job to add these sentence by sentence ...
3
votes
1answer
229 views

Generate assignment code to symbols from string

I want the function to take in string, then assign a value to its corresponding symbol. An implementation using ToExpression is ...
0
votes
2answers
122 views

Uniting lists of lists

Here's what I'm trying to do. First a simple example: ...
3
votes
3answers
219 views

OEIS A144311 Generating function

I'm looking for a way to use calculate OEIS A144311 efficiently in Mathematica. First, let's define the series. In one sense or another, this series considers the number between "relative" twin ...
6
votes
0answers
130 views

Generating OpenCL C code [closed]

I'm trying to make an interactive complex function plotter using OpenCl. So far I can only plot functions that I hardcode into the kernel by hand. I'd like to be able to use ...
5
votes
1answer
276 views

Generate FORTRAN77 code from Mathematica

I need to transform a function from Mathematica to Fortran77. An internal program FortranForm gives some result, but it works incorrectly in Fortran77. The string must start a 7th column and finish at ...
1
vote
1answer
307 views

How to write this Matlab code in Mathematica

I have a small hiccup here. I am trying to write my Matlab code for a dynamical system in Mathematica. I have managed to get most of it except one part. The Mathematica code for the system is <...
18
votes
3answers
809 views

Generating assignments and transforming code inside held forms when generating code

I have been playing with slightly above trivial code manipulations in Mathematica. I thought Mathematica would be great for this kind of work because of rule replacement and expression manipulation, ...
1
vote
2answers
135 views

Plot for pressure rise per wavelength [closed]

I have another question that i need to ask. I have been struggling in making the graphs for pressure rise per wavelenth. my equation for pressure rise per wavelength is: $Δp=∫_0^¹∫_0^¹(((∂p)/(∂x)))_{...
4
votes
0answers
41 views

Why are Parenthesis not added to CExpression in Package SymbolicC?

The documentation of SymbolicC, more specifically of COperator, states that Parentheses are added as necessary together with the ...
8
votes
1answer
127 views

How to prevent SymbolicC constructs from using the semicolon (;) as the separator?

When putting several SymbolicC expressions in a list, they will usually be joined together with semicolons in the final generated code: ...
2
votes
2answers
251 views

How to generate a range of numbers

Is there a quick and dirty way to generate a list of numbers from 1 to some arbitrary large number in order such that the digits of each number are only 0's, 1's, and 2's? I tried doing ...
1
vote
1answer
102 views

Variables input generation for Minimization in High dimensional space [duplicate]

I'm currently doing optimization in a high dimensional space. I was thinking of giving FindMinimum (or NMinimize not certain yet)...
2
votes
3answers
251 views

SymbolicC Simplified Displayed

How might I display a simplified SymbolicC below. For example in the following example ...
3
votes
1answer
55 views

Indent SymbolicC [duplicate]

What is they shortest way to automatically indent SymbolicC at the Brackets { and }? For example: ...
3
votes
1answer
102 views

How to make N apply to exponent?

For example, I want to covert y + Sqrt[x] to y + x^0.5, where y and ...
2
votes
1answer
403 views

How can I adjust ContourPlot in Mathematica?

I have problem because of the max point and min point, when I have too high or low data point, it just make it white. Here is example of data ...
1
vote
0answers
88 views

Get rid of external library dependency [closed]

I am trying to generate C code for some functions, which I do not post in full because they are a few hundred lines long. The functions do nothing too fancy: a bunch of dot products, powers and roots. ...
0
votes
1answer
115 views

Graphing the sequence {$p_k$} = $\frac{c - a + dp_{k-1}}{b}$ [duplicate]

Graphing the sequence {$p_k$} = $\frac{c - a + dp_{k-1}}{b}$ I need to know how to graph this function where it automatically plugs in the previous term for $p_{k-1}$, the coefficients are of my ...
16
votes
0answers
537 views

C Code generated from Mathematica not working?

I am a .Net developer. I'm trying to build a Visual C++ application using C code generated from Mathematica (by another person). I don't have Mathematica installed on my machine. When I try to compile ...
6
votes
0answers
233 views

Output most efficient Fortran code by mathematica

I am trying to output most efficient Fortran code by mathematica 9.0 with the method Simon provided: How can I get Mathematica to produce better Fortran code? The expressions is as follows: ...
1
vote
1answer
553 views

Latest Mathematica 9.0 can't use Format.m to generate optimized Fortran code [closed]

Before updating to Mathematica 9.0, I have successfully generated beautiful Fortran code using Mark Sofroniou's Format.m package, which is posted on MathSource. ...
2
votes
1answer
269 views

Optimizing my code to generate symmetric tensors

I have written code that does carries out the following task: Construct a fully symmetric rank-$P$ "tensor" out of a collection of user-input rank-1 vectors, and a rank-2 symmetric tensor $h$. The ...
3
votes
1answer
198 views

Mathematica Library

I created a Mathematica packagr and then I used the Needs function to add the library to my .nb file, but when use a function in my .nb file and the function is built in my library it comes up with ...
12
votes
1answer
4k views

Creating a standalone (executable) from mathematica code

I have written a small mathematica code to input a ".csv" file and output the data in a specific format, in a ".txt" file. I would like to give this program as an executable to my friend as she doesn'...
1
vote
0answers
298 views

matrix with IF/THEN condition

How to generate all posible matrices with some conditions on the elements? I need to make for given $n$ all $n\times n$ matrices $A=(a_{ij})$ with three conditions: I. $a_{ij}=+1$ or $0$ or $-1$. ...