New answers tagged

2

The form in question I meant the form Function[Null, body-using-slots, attrs] as ciao correctly noted. At least at the time when I wrote the book, this form hasn't been documented. I learned about it from Roman Maeder's book "Programming in Mathematica". OTOH, this form is very useful in some cases, particularly with Hold - attributes. Use cases I ...


1

Activate@Replace[Inactive[f][3],3->1, Infinity] 1 or Replace[Hold@f[3], 3 -> 1, Infinity] // ReleaseHold 1


4

According to this MathGroup post the function SpaceForm was documented only via Information (i.e. the SpaceForm::usage Message) even in Mathematica 3.0. With current version 10.4.1 the situation is still the same: ? SpaceForm SpaceForm[n] prints as n spaces. So you shouldn't worry: this function is in the current situation right from the start, ...


3

f = OpenWrite["test.txt"]; nsp[n_] := OutputForm[StringJoin[ConstantArray[" ", n]]] Write[f, 1, nsp[3], 2, nsp[1], 3]; Close[f] FilePrint["test.txt"] 1 2 3


0

You probably need to distribute every product over sums in your expression in order for Conjugate to propagate properly: distributeProducts[expr_] := Replace[expr, t : Times[___] :> Distribute[t], {0, \[Infinity]}] distributeProducts@ Conjugate[ fc (2 c E^((2 I fc \[Pi] (R1 + R2))/\[ConstantC]) mu1 + d E^((4 I fc \[Pi] R1)/\[ConstantC]) mu2)] ...


5

Introduction The first thing that I noticed is that the functional form for all of your CDD and LHS functions are identical. I propose that rather than defining six functions for each, we define one function and change the input arguments to cover the various cases. cdd[s_, a_, b_, c_] := 10^(a + b*c - b*s)*Exp[-10^(s - c)] lhs[s_?NumericQ, a_?NumericQ, ...


6

Below is an extended comment showing the effects that can happen when one ignores the correlations among parameter estimators (either on purpose or because journal authors or editors don't know enough about statistics to include necessary information). First I create some data with the same curve form as the function CDDHybrid and a set of predictor values ...


4

Could use Filling -> {4 -> {{1}, LightRed}, 1 -> {{3}, LightBlue}, 3 -> {{6}, LightRed}} and omit FillingStyle. Or Filling -> {1 -> {3}, 4 -> {6}}, FillingStyle -> {{LightBlue, Opacity[0.5]}, {LightRed, Opacity[0.5]}} which respectively produce the plots below.


3

To the best of my knowledge, the answer to your question is simply: no. Meta comments: I don't think your question ought to be closed as "out of scope", since you are not actually asking for anyone to write the function for you. My suggestion would be to write the function yourself and edit the question to include your attempt, making the focus of the ...


2

I learned a lot from WReach's and Leonid's answers and I'd like to make a small contribution: It seems worth emphasizing that the primary intention of the list-valued second argument of Flatten is merely to flatten certain levels of lists (as WReach mentions in his List Flattening section). Using Flatten as a ragged Transpose seems like a side-effect of ...


2

Just for reference, the sum depicted in the OP has a representation in terms of the $q$-hypergeometric function. In particular, $$\sum_{n=0}^{\infty}\frac{(-1)^nq^{6n^2}}{(q^3;q^3)_n(-q;q)_{3n}}={}_1\phi_4\left({{0}\atop{-q,-q^2,-q^3,0}}\mid q^3,-q^6\right)$$ Compare: Series[QHypergeometricPFQ[{0}, {-q, -q^2, -q^3, 0}, q^3, -q^6], {q, 0, 15}] 1 - q^6 + ...


8

Is there a way to get coordinate of just a particular point? You can convert Line into the corresponding set of Points each of which will be a Button which Prints the coordinates of that Point when you click on it (try this!): plot = BodePlot[1000/((1 + s/10^3)*(1 + s/10^6))]; plot /. Line[pts_] :> Map[Button[Point[#], Print[#]] &, pts, {-2}] ...


5

This does what I think you're after, fiddle with options as desired: With[{a = Interval[1.01 + .18 {-1, 1}], b = Interval[.92 + .11 {-1, 1}], c = Interval[2.2 + .2 {-1, 1}]}, Plot[{Min[a + b*x + c*x^2], 1.01 + .92 x + 2.2 x^2, Max[a + b*x + c*x^2]}, {x, -5, 5}, Filling -> {1 -> {3}}, FillingStyle -> Darker, PlotStyle -> {None, Red, ...


4

bp[s_] := 1000/((1 + s/10^3)*(1 + s/10^6)) mybp = BodePlot[bp[s]] Have a look at Short Cases Short[Cases[Normal@mybp, Line[s_] :> s, Infinity], 25] ...


3

Using Cases[] plot = BodePlot[1000/((1 + s/10^3)*(1 + s/10^6))] Cases[plot, Line[x___] :> x, Infinity] (*two group of data*)


0

What you want to do is actually very simple and can accomplished by a single line of code. With[{db = .01}, v = Interpolation[Table[{b, b^2}, {b, 0, 1, db}]]]; Then Plot[v[b], {b, 0, 1}]


0

I'm not very familiar with AR processes, but I suspect that you might be looking for the following syntax: ARProcess[c, {a1, ... , ap}, v] which, according to the documentation, represents an AR process with a "constant" $c$, which I think is the same as the intercept you are looking for. For instance, compare the following: (* Intercept value = 2 *) ...


5

You can do it by using the MessageName operator (::). Here is an example.


0

Thanks @rewi. I just write down the Wolfram Alpha version, (based on his answer). So I can remember. FourierTrigSeries[Piecewise[{{-Pi, -2 Pi < x <= 0}, {Pi, 0 < x <= 2 Pi}}], x, 3, FourierParameters -> {1, 1/2}] where FourierParameters' second parameter is $\omega = \frac{2\pi}{T}$


1

f[x_] = Piecewise[{{-Pi, -2 Pi < x <= 0}, {Pi, 0 < x <= 2 Pi}}]; T = 4 \[Pi]; fr = FourierTrigSeries[f[x], x, 3, FourierParameters -> {1, 2 \[Pi]/T}] (* 4 Sin[x/2] + 4/3 Sin[(3 x)/2] *)


4

You may start with this, add whatever you need and then remove the unnecessary manipulation parameters: Manipulate[Show[{ Graphics[{Opacity[0.5], Red, Rectangle[{1 + a, c + b}, {2 + a, 4 + b}]}, PlotRange -> {{0, 2}, {-3, 0}}, Axes -> True, AxesOrigin -> {1 + a, c}], Plot[{-(P*x^2/6) (3 - x), -k*x}, {x, 0, 1}, Axes -> ...


1

You can do this with the mathematica model connections. For the full list see http://reference.wolfram.com/language/guide/ModelConnections.html For example using the function SystemsModelSeriesConnect: tf = TransferFunctionModel[{{1/s}}, s]; SystemsModelSeriesConnect[TransferFunctionModel[k, s], tf] Output is the gain, k multiplied by the original ...


1

First note that with the way you defined f2, the error generated at the time of definition notwithstanding, f2 still works properly. The scope & context of your problem is not yet clear to me, but if it was me, I would make the code more general by making it more mathematical. Mathematica can usually handle efficiently most problems that can be ...


5

This could be done with a custom function for the first argument of Inner that treats a differently (it's just a more convenient form of expressing your original idea). For example, consider this: ClearAll[f]; f[a, x_] := a[x] f[x_, a] := a[x] f[x_, y_] := x y Now for your first example: Inner[f, {{a, b}, {c, d}}, {h, k}] (* {b k + a[h], c h + d k} *) ...


1

To see what it "does", use symbolic values as suggested by J.M. (tmatrix = Array[t, {2, 2}]) // MatrixForm (expr1 = Table[Sum[tmatrix[[i, j]], {i, 1, 2}], {j, 1, 2}]) // MatrixForm An alternate way to obtain this result expr1 === Plus @@@ Transpose[tmatrix] (* True *)


1

Example: (*arbitrary data*) x = Range[1, 5, 1] y = Range[5, 9, 1] z = Range[10, 14, 1] {1, 2, 3, 4, 5} {5, 6, 7, 8, 9} {10, 11, 12, 13, 14} (*process*) data = Outer[f, x, y, z]; Output (sample): Domain: {1,5,10}, {1,5,11}, {1,5,12}, {1,5,13}, {1,5,14} EDIT 1 This way may be not the best way how to achieve what you are after. There are ...


0

In[1]:= b=Range[0,.9,0.1]; Length@b p=Range[.25,.75,.05] Length@p Out[2]= 10 Out[3]= {0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75} Out[4]= 11 In[5]:= Information@Interpolation; Interpolation[{{{Subscript[x, 1],Subscript[y, 1],\[Ellipsis]},Subscript[f, 1]},{{Subscript[x, 2],Subscript[y, 2],\[Ellipsis]},Subscript[f, 2]},\[Ellipsis]}] constructs an ...


1

This works: hh @@ {3, 4} 7 This as well: myList = {3, 4} hh @@ myList 7 See: How to | Work with Lists Lists are at the core of the Wolfram Language. These "How tos" give step-by-step instructions for common tasks related to creating and manipulating lists. Applying Functions to Lists Many computations are conveniently specified in terms ...


3

Description The reason why your function doesn't execute as you'd expect is due to it expecting two arguments whilst you pass a single argument of type List containing two elements. Your function views it as hh[{3,4},y_]. Although, x parameter is passed successfully; y parameter is not available. Example: hh[3,4] Output: 7


1

points = {{0, 5.9}, {18, 5.56}, {22.32, 0}}; Graphics[{Red, PointSize[Medium], Point@points, Blue, BezierCurve[points, SplineDegree -> 1], Thick, Green, BezierCurve[points]}, Frame -> True, AspectRatio -> 1/GoldenRatio]


2

Physically motivated answer: points = {{0, 5.9}, {18, 5.56}, {22.32, 0}}; pointsSharp = {{0, 5.9}, {22.31, 5.89}, {22.32, 0}}; nmf = NonlinearModelFit[points, a (1/(1 + Exp[(x - b)/c]) - 1/2), {a, b, c}, x]; nmfSharp = NonlinearModelFit[pointsSharp, a (1/(1 + Exp[(x - b)/c]) - 1/2), {a, b, c}, x]; blue = RGBColor[17.6/100, 41.6/100, 63.1/100]; red = ...


2

As referred to in the comment (with link) there is a syntax error. The following defines the function, the negative gradient and visualizes it. f[x_, y_] := (x^2 + 2 x*y^2) E^(-x^2 - y^2) g[x_, y_] := -Grad[f[u, v], {u, v}] /. {u -> x, v -> y} sp = StreamPlot[g[x, y], {x, -3, 3}, {y, -3, 3}, StreamStyle -> Red]; cp = ContourPlot[f[x, y], {x, -3, ...


7

ClearAll[fuzzyLCS]; fuzzyLCS[strings__List] := Module[ {subsets, aligned, intersections}, subsets = Subsets[strings, {2, Length@strings}]; aligned = Select[SequenceAlignment[#[[1]], #[[2]]], StringQ[#] &] & /@ subsets; intersections = Intersection @@ (Subsets[#, {1, Length@#}] & /@ (Flatten[Characters[#]] & /@ ...


2

A little bit more general way: coeff[p_, x_] := Coefficient[p, x] /. (# -> 0 & /@ Variables[p]) p = x y^2 + 15 x^2 y + x + 3 y + 10; p2 = 3 t^2 + z; p3 = 3 t^2 x + z; coeff[p, x] coeff[p2, t^2] coeff[p3, t^2] coeff[p3, x t^2] (* 1 3 0 3 *)


1

I am not confident that the restrictions p > 0 && c > p && ((0 < l < p/(2 c) && 0 < s < (-2 c + p)/(4 c l - 2 p)) || (p/(2 c) <= l <= 1 && s > 0)) will ensure that the two functions will intersect. However to answer the question about how to implement these restrictions in ...


1

I am a little confused about the aim of the question. In the following I aim to show various ways of showing the zero set of $f(x,y)$ as defined in OP. f[x_, y_] := (x^2 + y^2 - 4) ((x - 1)^2 + y^2 - 4); p3d = Plot3D[f[x, y], {x, -3, 3}, {y, -3, 3}, MeshFunctions -> {#3 &}, Mesh -> {{0}}, MeshStyle -> {Red, Thick}, PlotPoints -> 50]; s = ...


3

Can use NDSolve to parametrize numerically. f[x_, y_] = x^2 + y^2 - 4; g[x_, y_] = x^2 - 3*y^2; pt = {2, 0}; xyvals = NDSolveValue[ Flatten[{D[f[x[t], y[t]], t] == 0, x'[t]^2 + y'[t]^2 == 1, Thread[{x[0], y[0]} == pt]}], {x[t], y[t]}, {t, 0, 11}]; (If you want to see the better part of a circle, do ParametricPlot[xyvals, {t, 0, 11}, AspectRatio ...


4

Plot3D[g[x, y], {x, -5, 5}, {y, -5, 5}, MeshFunctions -> {f[#, #2] &}, Mesh -> {{{0, Directive[Thick, Red]}}}, BoxRatios->1] Plot3D[g[x, y], {x, -5, 5}, {y, -5, 5}, PlotStyle -> None, BoundaryStyle -> None, MeshFunctions -> {f[#, #2] &}, Mesh -> {{{0, Directive[Thick, Red]}}}, BoxRatios->1] cp = ContourPlot[f[x, ...


2

If all the elements in the matrix are functions, you can also use Block[{Times = (# @ #2 &)}, {{a, b}, {c, d}}.{h, k}] {a[h] + b[k], c[h] + d[k]}


5

Picking up on Marius tip on Inner in the comments: Inner[Apply[#1, {#2}] &, {{a, b}, {c, d}}, {h, k}] And @ciao offered a better version in comments: Inner[#1[#2] &, {{a, b}, {c, d}}, {h, k}]


3

It doesn't do anything, it just formats in a certain way. You can assign your own definition if you like. References: Operators without builtin meanings


1

sample = RandomFunction[ARMAProcess[{-.3, .1}, {.4}, 1], {0, 100}]; data = sample["States"][[1]]; As observed by @Rashid, if the first argument of CorrelationFunction is a TemporalData object (like sample), everything work as expected: ListPlot[CorrelationFunction[#, {20}], AxesOrigin -> {0, 0}, BaseStyle -> PointSize[Large], FillingStyle -> ...


1

Assuming the functions beta and Yss are the ones defined in your other question, that is, beta[alpha_, sd_, rf_] := (1/2) - (alpha/(sd^2)) + Sqrt[(((alpha/(sd^2)) - (1/2))^2) + (2*rf/(sd^2))]; Yss[alpha_, sd_, rf_, iss_] := (1/2) - (alpha/(sd^2)) + Sqrt[(((alpha/(sd^2)) - (1/2))^2) + (2*(rf + iss)/(sd^2))]; optVS[wa_, ea_, ewi_, kapa_, alpha_, sd_, ...


5

This is simple enough to do analytically.. assuming l2>l1 you can readily find the transition points and invert each piece of the Piecewise expression: myfuninv[x_, l1_, l2_ /; l2 > l1] = Piecewise[{ {Sqrt[x], x <= l1^2}, {x + l1 - l1^2, l1^2 < x <= l2 + l1^2 - l1}, {Exp[x + l1 - l2 - l1^2] - 1 + l2, l2 + l1^2 - l1 < x}}] Plot[ ...


0

If you have a function that generated the contour and you know the contour value, then you could just evaluate the function at each point in the second list and know whether the each point is in the contour, on the contour, or outside the contour. (I'm not try to be facetious. It's just that sometimes I don't always see the forest for the trees.) ...


4

Use BoundaryDiscretizeGraphics, RegionDifference, Select, and MemberQ points1 = CirclePoints[3, 40]; points2 = CirclePoints[1, 40]; {region1, region2} = BoundaryDiscretizeGraphics@*ListCurvePathPlot /@ {points1, points2} region3 = RegionDifference[region1, region2] Show[ RegionPlot@region3, Select[RandomReal[{-5, 5}, {1000, 2}], RegionMember[region3]] ...


2

u[x1_, x2_] = Log[x1] + 2*Log[x2]; cp = ContourPlot[u[x1, x2], {x1, 0, 10}, {x2, 0, 10}, PlotPoints -> 100] Solve for x2 along the contours f[x1_, c_] = x2 /. Solve[c == u[x1, x2], x2, Reals][[1]] (* E^(c/2)/Sqrt[x1] *) Plot the contours plt = Plot[ Evaluate[ Table[ Tooltip[f[x1, c], c], {c, -2, 6, 2}]], {x1, 0, 10}, PlotRange ...


2

The following uses NDSolve to construct interpolations along lines in the domain. We then construct an interpolation between the solutions to NDSolve, which represents a as a function of l1 and l2. {dadl1, dadl2} = grad = PiecewiseExpand /@ (-D[myfun[a, l1, l2], {{l1, l2}}]/ D[myfun[a, l1, l2], a]) /. ComplexInfinity -> 0 // Quiet; sols = ...


7

Sure, try for example: pr[14709321003111578837870501266345370175409, 2, 2] There are many things in MMA where small cases/edge cases can be done much more quickly with user code, this is one of them. The advantage here is that PowersRepresentation can handle huge cases...


2

General Inversion You can use FindRoot to do a general inversion of a Piecewise function. The strategy will be to extract the smooth continuous function from the piecewise function and use that as input to FindRoot. Below is a copy of your function: myfun[a_, l1_, l2_] = Piecewise[{ {a^2, a < l1}, {a - l1 + l1^2, a >= l1 && a ...



Top 50 recent answers are included