Linked Questions

11 votes
4 answers
721 views

Using predefined expressions as free variables in a pure function [duplicate]

I want to have a function value of an expression where some variables are solutions to some set of equations, with some values of parameters. I had an idea to use pure functions for that. However, ...
Picek's user avatar
  • 125
2 votes
3 answers
167 views

Globally Defining a Variable that Depends on Arguments of Functions [duplicate]

I have many delayed-defined functions of many variables, and all the functions share a term containing some of these variables. Thus, I would like to just call the term ...
Just Some Old Man's user avatar
1 vote
3 answers
931 views

Assign a function within a function [duplicate]

What I'm doing wrong? 1st function works as expected but the 2nd one doesn't. What I want is to enter an algebraic expression and two numeric constants and get the same result as with the first ...
Sanmuten's user avatar
0 votes
1 answer
1k views

Calling a function on a variable with parameters [duplicate]

I have an equation that contains parameters. I want to use it in a function like NDSolve, but I can't seem to figure out how to do so. Here's an example: I define ...
Matthew's user avatar
  • 221
1 vote
1 answer
154 views

Implementation of a recursive function [duplicate]

I have been trying to implement a recursive function, but still struggle. Here's what I have written: ...
Rariel's user avatar
  • 11
1 vote
1 answer
155 views

Substitution in delayed evaluation function [duplicate]

I am trying to do the the following: precomputing an expression and then making a function out of it. It has to be delayed evalution, because some of the parameters are only known when the function is ...
orion's user avatar
  • 141
3 votes
1 answer
91 views

Defining function [duplicate]

ver1 = 2 x verf[x_] := ver1 verf[3] Result : 2 x Expected Result : 6 In the above code ...
rainversion_3's user avatar
0 votes
0 answers
40 views

Basic Question on function of $n$ when it shift to $n-1$ [duplicate]

This question is basic, but I do not know what is wrong. Clear[a0,a] a0=n; a[n_]:=a0 But when I evaluate a[n-1] the output ...
Chen M Ling's user avatar
50 votes
5 answers
3k views

Enforcing correct variable bindings and avoiding renamings for conflicting variables in nested scoping constructs

Using global variables the following turns an "expression" into a Function: expr = 2 x; Function[x, Evaluate[expr]] Of course ...
einbandi's user avatar
  • 4,024
12 votes
2 answers
6k views

How to pass variables by reference and by value [duplicate]

I haven't seen this question specifically addressed before in this site, although some hints and traces have been given, for instance, here: Pass by reference for an option argument Does pass-by-...
Vicent's user avatar
  • 1,101
7 votes
5 answers
659 views

What is the the proper way to define a function from an expression? [duplicate]

Say after some long computation we get an expression expr=x^2 We do not know what the value of expr beforehand. Now we want ...
NonalcoholicBeer's user avatar
7 votes
4 answers
2k views

Delayed evaluation of assignment

I have a set of PDE's that depend on parameters. They depend on many parameters, but for simplicity we can here assume that they depend only on one, say a. I want ...
yohbs's user avatar
  • 7,046
4 votes
3 answers
546 views

Using Block with a list of variables

I have a list of variables var={v1,v2}; which I want to protect/localize during a particular operation. I have decided that I want to use ...
Heterotic's user avatar
  • 306
3 votes
4 answers
1k views

Passing a function as an argument to another function using the same variables

I define a function with two variables and an argumment which is a function of this two first variables. For example the function Ttrho below (the two variables are T and Rho and pTt is a function of ...
F. Aitken's user avatar
  • 111
3 votes
2 answers
268 views

Recursion doesn't happen any more or doesn't happen correctly if I store the recursive relationship in a variable first

I know the following code will form a recursion: Clear["Global`*"] u[i_, n_] := u[i - 1, n] + u[i, n - 1] u[0, n_] := n u[i_, 0] := i u[2, 2] (* => 8 *) But ...
xzczd's user avatar
  • 66k
7 votes
2 answers
175 views

How to create Functions that have Compiled functions effectively

I'm about to build a package that will provide lots of simple functions. I want these functions to run as fast as possible when evaluating numerically but still provide symbolic results when needed. ...
c186282's user avatar
  • 1,402
0 votes
1 answer
294 views

What to use instead of ReplaceAll to replace a parameter with a number before the evaluation of an integral?

This is probably very simple but I don't see the solution now. Let us say I have a variable e defined as e=n ReplaceAll can subsitute n with value 3 using ...
wondering's user avatar
  • 595
2 votes
2 answers
168 views

Changing from parameter to variable in Mathematica

I'm having trouble defining a function where I previously treated a variable as a parameter. See the following example: var := 2*a f[a_] := var Then ...
sma11s101's user avatar
2 votes
2 answers
87 views

Issues Implementing Pure Function

Thanks in advance for any assistance you may be able to provide. I'm new to Mathematica and running into issues creating a usable function from the code seen below. For context, all of this code works ...
Jim's user avatar
  • 31
1 vote
1 answer
249 views

nonatomic expression expected when trying to sum of the integrals of two functions

newbie to MMA. After computing the following two integrals: ...
Yun's user avatar
  • 23
1 vote
1 answer
159 views

Order of evaluation

I am having a hard time figuring this out: ( sample ) I have any matrix which can have an arbitrarily large dimension. ...
Rupesh's user avatar
  • 887
1 vote
0 answers
252 views

Problem in evaluating nested anonymous functions [duplicate]

It seems that I have found a bug (or a fundamental problem in the design of the programming language of Mathematica) with functions defined as rules. Define the function g as g(1)=2 and g(2)=1. We can ...
Mauri Ericson Sombowadile's user avatar
2 votes
1 answer
90 views

Difference Between Set and Pattern in Mathematica

Ok, sorry if this is too basic, I'm somewhat new to Mathematica, but I keep making errors in my code because I'm not understanding the namespaces. So this part I thought I understood. ...
NathanRL's user avatar
  • 127
0 votes
1 answer
89 views

Defining a function when the variables do not appear explicitly in the definition of the function

I am trying to take the curl of a vector field which is the a product of a scalar field (Psi) and a coordinate vector, {r,Theta,Phi}. After taking the curl I want to calculate the magnitude of the ...
A. Pauls's user avatar
2 votes
1 answer
64 views

Handling a list of variable assignments to be used with `With` [duplicate]

Is there a way to use With as follows? variables := {a = 2, b = 3}; With[variables, a^b] Desired output ...
Diffycue's user avatar
  • 1,834
3 votes
1 answer
95 views

Forcing variable substitution on delayed evaluation

Problem, the following snippet doesn't substitute vars ...
Yaroslav Bulatov's user avatar
1 vote
1 answer
105 views

Unit conversion in a function using another function as an argument

My problem is related to the previous post Passing a function as an argument to another function using the same variables. I don't understand why in the following example the conversion of units does ...
F. Aitken's user avatar
  • 111
2 votes
0 answers
101 views

Definition of a function using variables outside of the function [closed]

I would like to define a function using variables outside of the function. For example, g = x + y; f[x_, y_] := g; f[1, 2] then, I hope to get 3 as the answer. ...
Syota_nokemono's user avatar
0 votes
0 answers
51 views

How to transfer the list of parameters values into With [duplicate]

In the following case: With[{x=1,y=2},Print[x+y]] the values of x and y are declared in ...
Marek's user avatar
  • 51