Tag Info

New answers tagged

2

If you know what the JSON you receive looks like your own approach might work well enough. On the other hand JSON might not necessarily contain just nested "Objects" but also arrays, in which case it will cause errors or invalid unevaluated Assocation-expressions if one assumes that every list resulting from the imported JSON is a list of rules (or even has ...


1

Because I actually had this problem but eventually solved it I thought I'd question and answer it myself. Feel free to submit a better solution! First, import the data using: json = Import["example.json","JSON"] The function that does all the magic is: JSONToAssociation[list_] := Association[ Table[ If[ ListQ[i[[2]]], i[[1]] -> ...


2

Method 1 gcdList[x_, y_] := FixedPointList[ # /. {a_, b_} /; b != 0 :> {b, Mod[a, b]} &, {x, y}] gcdList[25,45] {{25, 45}, {45, 25}, {25, 20}, {20, 5}, {5, 0}, {5, 0}} Another solution gcd[a_, b_] := Module[{x, y}, {x, y} = {a, b}; While[y != 0, {x, y} = {y, Mod[x, y]}; ]; x ] gcd[15,10] 5 Method 2 gcdList2[a_, b_] ...


4

As I mentioned in my comment, of course Mathematica has a built-in function to calculate the GCD, called GCD (docs). My understanding, however, is that you are using the GCD as an example to learn how to apply a function recursively for a number of times that is not decided a priori, but that depends on the inputs and the path of the calculation. The ...


1

Since your examples shows your function outputting a simple numeric vector is not not make sense to apply your two-argument function to this result. Presumably you want to keep a constant f_ parameter for every application of nS. The best way to do that is to define a parameterized function: nS[f_][xk_List] := Developer`PartitionMap[f, xk, 3, 1] Basic ...


1

Edit Because you do not provide definitions for nS an t, I can not provide a solution based on your code, so I will contrive my own example. f[fnc_, data_List] := fnc /@ data sq[x_] := x^2 f[sq, Range @ 3] {1, 4, 9} Now to use f with Nest, I simply write Nest[f[sq, #] &, Range @ 3, 3] {1, 256, 6561} The 1-st argument of Nest is a function ...


1

Here is a possible approach. Would need some work to generalize to higher degree though. recursiveSum[fac_.*Sum[term_*x_[i_], {i_, n_}]] := Module[ {topterm, c, genterm, soln}, topterm = fac*term*x[i] /. i -> n; genterm = Table[fac*term /. n -> nn, {nn, n - 1, n}]; soln = c /. First[Solve[{c, 1}.genterm == 0, c]]; topterm + ...


4

b.gatessucks solution given in a comment should be recorded answer. aux = RecurrenceTable[{a[n - 1] == 3 a[n], a[1] == x}, a, {n, 10}] {x, x/3, x/9, x/27, x/81, x/243, x/729, x/2187, x/6561, x/19683} First[aux /. Solve[Last[aux] == 7, x]] {137781, 45927, 15309, 5103, 1701, 567, 189, 63, 21, 7} But, of course, in this simple case there is ...


0

EDIT: Corrections VBA to Mathematica code translation optval[vol_, intrate_, expn_, payoff_, strike_, Etype_, NAS_] := Module[{S, vold, Vnew, Dummy, ds, dt, NTS, q, gamma, Delta, Theta}, S = Table[0, {NAS + 1}]; vold = Table[0, {NAS + 1}]; Vnew = Table[0, {NAS + 1}]; Dummy = Table[0, {NAS + 1}, {3}]; ds = 2*strike/NAS; dt = 0.9/vol^2/NAS^2; ...


0

I have not found a general solution but one that does hint at it. Based on this post http://stackoverflow.com/questions/8073530/get-mathematica-to-simplify-expression-with-another-equation I have tried the following for t=5: ElEq=Eliminate[{A==EV[5],EV[4]==B},Table[x[i],{i,1,4}]] Flatten[Collect[Solve[ElEq,A],{B,x[5]}]] This gives {A->(B ...



Top 50 recent answers are included