Manishearth
Reputation
Next privilege 250 Rep.
 Aug15 asked EquationTrekker-like behavior for state space? Jan31 awarded Citizen Patrol Jan16 comment How can I simulate this toggle mechanism? I think you first have to choose the length of the rod so that it fits in the distance between the two centers, and subsequently use trigonometry to calculate the position of the point on the lower circle. Jan3 awarded Talkative Dec17 accepted How should I go about writing more functional and list based code? Dec17 comment How should I go about writing more functional and list based code? @rm-rf Yep, it is. Hadn't looked at the second answer, and it is really relevant. Thanks :) Dec17 comment How should I go about writing more functional and list based code? Hmm, this is interesting :) I haven't used Fold much but I can see how it would be useful here. (Also, I don't "come from" Lisp, I just am comfy with it but I am much more at ease with procedural things). Dec17 comment How should I go about writing more functional and list based code? @Nasser Thing is, I am reasonably comfortable with Lisp. But Mathematica has its own style, and the problems faced are different. Plus, there are many in-built commands that work well with functional programming or lists. Dec17 asked How should I go about writing more functional and list based code? Nov4 awarded Commentator Nov4 awarded Teacher Oct30 comment Writing NDSolve-like functions Oh wait, nevermind. It's only being used on the symbol inputs, now I think I got it. Thanks :) Oct30 comment Writing NDSolve-like functions Ah, thanks. Why does it work in this case though? When I try t = 5; Print[t]; Block[{t}, Print[t]; t = 6;]; Print[t], the t in the block is taken as a fresh variable. Whereas here it seems to be substituted in from the outside. Oct30 comment Writing NDSolve-like functions It seems to work both ways, though. What's the difference? Is it preventing the variables from messing with outside variables? Oct30 comment Writing NDSolve-like functions Thanks! I didn't know about SetAttributes, (or Block, I've been using Module which is lexical.), which must be where I went wrong. I also didn't know about the ability to use lists in the function declaration itself. I think that there may be a syntax error here, though, the t,xvar,yvar shouldn't be in the Block statement. Not sure. Oct30 accepted Writing NDSolve-like functions Oct29 revised Writing NDSolve-like functions added 153 characters in body Oct29 comment Writing NDSolve-like functions @rm-rf Well, if that can be genericized I don't mind, but when I use this set of code I usually don't need much of a range for t -- in fact, none at all. I'll add that bit, though. Oct29 revised Writing NDSolve-like functions added 50 characters in body Oct29 comment Writing NDSolve-like functions @rm-rf The ICs are the ParametricNDSolve parameters, they get substituted with x,y later on. The vector plot is a plot of $(v'(t),\omega'(t))$ at various initial conditions. The plot ranges are specified in the {{v[t],-2,1}, {ω[t],-1.2,0.5}} (i.e. the {{var1,varmin,varmax},{var2,varmin,varmax}}) part.