wolfram-mathematica

Translating the map command and few others from Mathematica to MATLAB

牧云@^-^@ 提交于 2019-12-29 01:29:50
问题 I did these so far: EDIT--------------- steps=@ (m) 2*randi([0,1],[1,m])-1; Walk1D =@ (n) [0,cumsum(steps(n))]; findend=@ (x) x(end); LastPoint1D=@(n) findend(Walk1D(n)); nsteps=200; nsq=floor(sqrt(nsteps)); MeanSquareDistance1D= @ (n,m) m.*sum((LastPoint1D(n)).^2)./m; r2D=MeanSquareDistance1D(100,1000) data=[ ]; for i=10:20:90 data=[data; i , MeanSquareDistance1D(i,2000)] end The only problem now,is that the 2nd column of "data" must give me values around 10 30 50 70 90 but not exactly.Only

Translating the map command and few others from Mathematica to MATLAB

我只是一个虾纸丫 提交于 2019-12-29 01:29:12
问题 I did these so far: EDIT--------------- steps=@ (m) 2*randi([0,1],[1,m])-1; Walk1D =@ (n) [0,cumsum(steps(n))]; findend=@ (x) x(end); LastPoint1D=@(n) findend(Walk1D(n)); nsteps=200; nsq=floor(sqrt(nsteps)); MeanSquareDistance1D= @ (n,m) m.*sum((LastPoint1D(n)).^2)./m; r2D=MeanSquareDistance1D(100,1000) data=[ ]; for i=10:20:90 data=[data; i , MeanSquareDistance1D(i,2000)] end The only problem now,is that the 2nd column of "data" must give me values around 10 30 50 70 90 but not exactly.Only

conditional Product mathematica

痞子三分冷 提交于 2019-12-25 08:21:04
问题 I am trying to replicate Lagrange Interpolating Polynomials in Mathematica. The wiki for an explanattion of them can be seen here. This is my code (sorry I don't know how to place mathematica code in SO so I have an image): My problem is that I want a conditional product. if j = m I just want to skip over that product and evaluate the next one. That's why I put the false evaluation as 1. Any suggestions? 回答1: All built-in functions start with a capital letter. So the conditional is If[...]

Finding i-th row in a matrix in wolfram mathematica

不打扰是莪最后的温柔 提交于 2019-12-25 04:49:08
问题 I have trying to multipy a column matrix and a row matrix in mathematica. But mathematica gives row matrix as a column matrix. so multipy function doesnt work. My codes are `Y = Inverse[S]; Print["Y=", MatrixForm[Y]]; For[i = 1, i <= n, i++, Subscript[P, i] = MatrixForm[S[[All, i]].Y[[i]]]; Print["CarpimS=", MatrixForm[S[[All, i]]]]; Print["CarpimY=", MatrixForm[Y[[i]]]]; Print["P=", Subscript[P, i]]; ]; If anyone know this situation please answer 回答1: This is a badly written question, so I'm

Writing Runge-Kutta ODE solver using gsl

社会主义新天地 提交于 2019-12-25 04:08:39
问题 It's been some time since I did any C/c++, but I wanted to write an ODE solver using the gsl library to solve the following ODE set $$ u'(r)=up(r)$$ $$ up'(r)=-(2*(r-1)/(r*(r-2)))*up(r)-((r*r/((r-2)*(r-2)))-(2/r*(r-2)))*u(r) $$ so in the gsl notation my y[0]=u, y[1]==up, and the RHS of the above defines f[0] and f[1]. From these definitions one can then compute the Jacobian and dfdr (usually their 'time' variable is called 't' not 'r'). The reason for doing this is because I am having speed

Mathematica Not Saving Variable

被刻印的时光 ゝ 提交于 2019-12-25 03:48:51
问题 I try to perform this nested loop but it is not working. It's not saving the result in each stage. But if I replace listInitial with Print[ ] I observer that all changes are made. Any suggestions?? For[b = 1, b < 4, b = b + 1, For[a = 1, a < 4, a = a + 1, For[x = 1, x < 4, x = x + 1, For[z = 1, z < 4, z = z + 1, listInitial = If[Random[] > psurvival, ReplacePart[ InitialMatrix[3, 3, 3, 3], {b, a, x, z} -> InitialMatrix[3, 3, 3, 3][[b]][[a]][[x]][[z]] - 1], InitialMatrix[3, 3, 3, 3], {b, a, x,

ShowGraph[ { {e1,e2}, {e1, e3} }, {e1,e2,e3} ]; // what is the problem here?

喜你入骨 提交于 2019-12-25 02:28:48
问题 doesn't show specified graph in Mathematica Graph Theory package 'Combinatorica'. 回答1: An important thing to note is that Mathematica has two more or less independent graphing frameworks: the one included in the Combinatorica package and the GraphUtilities package. I my limited experience, the Combinatorica package is quite a big machine to swing into action and you really have to grok the framework to use it. GraphUtilities on the other hand is quite intuitive, has more customization options

Mathematica problems with certain differential equations and DSolve

霸气de小男生 提交于 2019-12-25 01:14:40
问题 Im having trouble getting started. I am in a Financial Engineering program, and I am trying to use a book written in 2003 to help me model partial differential equations, the black scholes model, etc. But in the introductory chapter there is a very basic ODE interest rate problem, and my output is very different from the book. DSolve[{y'[t] == ry[t], y[0] == P}, y[t], t] is what I put in. The book has a very neat solution of {{y(t)->P*exp^(rt)}} What I get is something like (Note, I can't

How to check if hand contains one pair of cards in poker game using Mathematica?

二次信任 提交于 2019-12-24 21:27:55
问题 In a poker where each player gets 5 cards from a 32 card deck, I am trying to calculate how many subsets contain exactly one pair using Mathematica. I created a deck with four suits and created subsets of all possible combinations of the cards and now I am trying to filter out all the wrong combinations using different methods to exclude the four of a kind and three of a kind and the full house. but the filter is still showing higher values than it actually is. The out put of my program is

using nested arrays and lists in mathematica

我的梦境 提交于 2019-12-24 14:45:55
问题 Absolute beginner question here. I have two lists in mathematica. The first one was generated by the Table command: Table[QP[[i]], {i, 10}] which generates the list: {52.5, 45., 37.5, 30., 22.5, 15., 7.5, 0., -7.5, -15.} the second is a Range Range[0, 9, 1] which generates {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} I need to get these into a list of lists. i.e. {{0,52.5},{1,45} ... } etc. But I can't seem to get it. Do you need to use loops? Because I think that what I want can be generated with the