New answers tagged

2 votes

Different answers when attempting replacement of function argument

The /. infix form is just syntactic sugar. The expression that gets evaluated here is ...
lericr's user avatar
  • 24.3k
0 votes

Different answers when attempting replacement of function argument

Using Hold and ReleaseHold does the job as well: ...
youyou's user avatar
  • 121
4 votes

Different answers when attempting replacement of function argument

fib1 should be limited not to evaluate unless $n$ is an explicit integer number, so let's redefine it as such (in the following I've also used a version with ...
MarcoB's user avatar
  • 65.7k
3 votes

Different answers when attempting replacement of function argument

Look at: fib1[n] -1 + n fib1[n] /. n->10 9 And for fib2: fib2[n] 2 Here the ReplaceAll does nothing.
Daniel Huber's user avatar
  • 47.1k
0 votes

Creating function with array input with desired coefficient and evaluate it

Using TakeList: ...
Syed's user avatar
  • 41.4k
2 votes

Simplify inverse of function

If you need to implement the result in Excel, you might want to consider solving the problem completely in Excel. Excel is certainly not the equivalent of Mathematica but it does have a lot of ...
JimB's user avatar
  • 40.3k
4 votes
Accepted

Simplify inverse of function

...
Bob Hanlon's user avatar
  • 151k
5 votes

Creating a list of functions with desired coefficients

Instead of using Subscript[x, 1], I suggest using x[1]. You can still use Format to display ...
Domen's user avatar
  • 18.9k
1 vote

Add a column to a matrix as a function of the other columns

list = Partition[Range @ 9, 3]; Query[All, {Splice, Apply @ f }] @ list gives the expected result: ...
eldo's user avatar
  • 47.5k
3 votes

Is there a neat code to swap elements of a list?

...
eldo's user avatar
  • 47.5k
7 votes

How to fit function with data?

NonlinearModelFit default settings work ok with simpler model and thena and b can be derived,...
ubpdqn's user avatar
  • 58.7k
4 votes

How to fit function with data?

Use a better search method: ...
Daniel Huber's user avatar
  • 47.1k
7 votes
Accepted

How to fit function with data?

Provide initial estimates for a and b ...
Bob Hanlon's user avatar
  • 151k
3 votes

Is there a neat code to swap elements of a list?

list = Range[9]; swap = {{2, 5}, {3, 6}}; Fold[SubsetMap[RotateRight, #1, #2] &, list, swap] {1, 5, 6, 4, 2, 3, 7, 8, 9}
eldo's user avatar
  • 47.5k
4 votes

Pattern matching vs. condition in a function

For g4, your condition doesn't evaluate to True or False. Specifically, ...
lericr's user avatar
  • 24.3k
1 vote

SplineDegree->1 does not work with BezierFunction?

I've made a function like what @yu-sung-chang was suggesting. ...
kevind's user avatar
  • 41
6 votes
Accepted

Can I write a function that describes a hysteron?

To define a memory, you can define a variable and, for safety, put it in a separate name space, like e.g. ns`k. Further, you did not specify what k should be if x==a or x==b and what K shloud be the ...
Daniel Huber's user avatar
  • 47.1k
0 votes

Can I write a function that describes a hysteron?

y[x_]:= Which[x >= b, 1, x <= a, 0, a < x < b, k ]
David G. Stork's user avatar
0 votes
Accepted

Same code behaves differently as a pure function and a function, and insider another function

That's due to the renaming mechanism of nested scopings. When evaluating Transformer2[algebra_] := , the local variable algebra ...
Lacia's user avatar
  • 2,208
0 votes

Same code behaves differently as a pure function and a function, and insider another function

This doesn't really seem to have to do with Function versus SetDelayed, so it might warrant a separate question. Rather then ...
lericr's user avatar
  • 24.3k
3 votes

Plotting root locus - how to display 'k' values on the curve?

Using ColorFunction ...
Bob Hanlon's user avatar
  • 151k
4 votes
Accepted

Plotting root locus - how to display 'k' values on the curve?

...
Syed's user avatar
  • 41.4k
6 votes

How to draw an image similar to a periodic function (f [x+1]=2 f [x])?

...
Bob Hanlon's user avatar
  • 151k
7 votes

How to draw an image similar to a periodic function (f [x+1]=2 f [x])?

Plot[With[{qr = QuotientRemainder[x, 1]}, 2^First[qr] Last[qr] (Last[qr] - 1)], {x, 0, 3}]
Goofy's user avatar
  • 773
8 votes
Accepted

How to draw an image similar to a periodic function (f [x+1]=2 f [x])?

Edit For x<0,we rewrite f[x+1]=2f[x] to `f[x]=f[x+1]/2; ...
cvgmt's user avatar
  • 63.3k
5 votes
Accepted

Is it possible to ask Mathematica to give/find this largest (absolute value) argument of $\cosh$ in the expression?

...
Syed's user avatar
  • 41.4k
2 votes

How to apply a constant function to a vector of values?

Using Query func = {1 &, Cos, Sin}; xval = {a, b, c, d}; Query[Transpose, func] @ xval gives ...
eldo's user avatar
  • 47.5k
3 votes

Stopping mathematica from rearranging elements in a list

or use filter, in Mathematica it's Select {-(1/x), -(1/x) + x/2 - 2 Log[x] - Log[x]/x, 1} // Select[# =!= -1/x&]
AsukaMinato's user avatar
  • 8,785
5 votes

Stopping mathematica from rearranging elements in a list

set1 = {-1/x, -1/x + x/2 - 2 Log[x] - Log[x]/x, 1}; Fold[DeleteCases, set1, {-1/x}] (* {-1/x + x/2 - 2 Log[x] - Log[x]/x, 1} *)
Roman's user avatar
  • 45.9k
5 votes

Stopping mathematica from rearranging elements in a list

UniqueElements[{set1,{ -1/x}}][[1]] (* {-x^(-1)+x/2-2*Log[x]-Log[x]/x,1} *)
user1066's user avatar
  • 15.5k
3 votes

Stopping mathematica from rearranging elements in a list

Instead of applying "Complement" to the whole list set1, you may apply it to the single elements of set1 like: ...
Daniel Huber's user avatar
  • 47.1k
2 votes

Stopping mathematica from rearranging elements in a list

If I understand correctly, this is what you need set1 = {-(1/x), -(1/x) + x/2 - 2 Log[x] - Log[x]/x, 1} SortBy[Complement[set1, {-1/x}], Position[set1, #] &]
bmf's user avatar
  • 12.8k
8 votes

Stopping mathematica from rearranging elements in a list

You can use DeleteElements which came with V 13.1: ...
eldo's user avatar
  • 47.5k
3 votes

To draw a function within an interval

It is still a bit unclear exactly what kind of an answer would help you most. The way I read the last comment is that you want all $x,y,z$ to be plotted. In other words, you want a 3D-plot. The ...
Jyrki Lahtonen's user avatar
1 vote

Define function to test arguments and set value to 0 (application 0 Log [0] = 0)

Rather than define your function directly, you could define it based on the result of the log expression. ...
lericr's user avatar
  • 24.3k
2 votes

Define function to test arguments and set value to 0 (application 0 Log [0] = 0)

Maybe ClearAll @ g SetAttributes[g, Listable] Off[Infinity::indet] g[0, 0 | 0.] := 0 g[x_?NumericQ, y_?NumericQ] := Re[x Log @ y] g[__] := 0 g[10^-5, -10.^-8] -0....
eldo's user avatar
  • 47.5k
1 vote

Define function to test arguments and set value to 0 (application 0 Log [0] = 0)

I would define my own Log like e.g.: ClearAll[myLog] SetAttributes[myLog, Listable] myLog[x_] = If[x <= 0, 0, Log[x]]; Now zero arguments are defined: ...
Daniel Huber's user avatar
  • 47.1k
5 votes
Accepted

How can I zoom in on a specific region?

You could always implement your own poor's man zoom. Code ...
Nasser's user avatar
  • 137k
3 votes

Trying to plot the Fourier transform solution to the heat equation on Mathematica

See if this does what you want Code ...
Nasser's user avatar
  • 137k
1 vote

Grouping consecutive elements at specified positions

Question 1: ...
eldo's user avatar
  • 47.5k
1 vote

Listable (on certain level) custom function

$Version (* "13.3.1 for Mac OS X ARM (64-bit) (July 24, 2023)" *) ClearAll["Global`*"] Rather than use the attribute ...
Bob Hanlon's user avatar
  • 151k
2 votes

Listable (on certain level) custom function

pts = {{x1, y1}, {x2, y2}}; Just use Map: Map[myf, pts] {myf[{x1, y1}], myf[{x2, y2}]} Or ...
eldo's user avatar
  • 47.5k

Top 50 recent answers are included