wolfram-mathematica

Mathematica: How to clear the cache for a symbol, i.e. Unset pattern-free DownValues

梦想与她 提交于 2019-12-17 09:33:49
问题 I'm a bad cacher: Sometimes, when no one is watching, I'll cache results without including the full context like so: f[x_]:=f[x]=x+a; a=2; f[1]; DownValues[f] Out[2]= {HoldPattern[f[1]]:>3,HoldPattern[f[x_]]:>(f[x]=x+a)} This leads to horribly subtle bugs, and, more importantly, to the need for clearing the cache when I change the context. One way of clearing the cache is to completely Clear the symbol and repeat the definitions, but this is not really a solution. What I would really like is

The best way to construct a function with memory

两盒软妹~` 提交于 2019-12-17 06:25:21
问题 Good day, I have some very slooooow and complicated function, say f[x,y] . And I need to construct detailed ContourPlot of it. Moreover the function f[x,y] sometimes fails due to lack of physical memory. In such cases I have to stop evaluation and investigate the problem case of the point {x,y} by myself. Then I should can add the element {x,y,f[x,y]} to a list of computed values of f[x,y] (say "cache") and restart evaluation of ContourPlot . ContourPlot must take all already computed values

Customizing Mathematica shortcuts

偶尔善良 提交于 2019-12-17 03:25:10
问题 Is there a place I can view/change global shortcut options like Command + 9 (turn into Input style)? In particular, I need a faster way of creating bulleted lists. It's the style "Item" in the Cell context menu which doesn't have its own shortcut. 回答1: Here is a nice article. Also, FROM HERE (unchecked) Question: How do I modify the front end to add new keyboard shortcuts? Answer: (mathgroup May 2005, trevor baca:) I've been mucking around in KeyEventTranslations.tr setting up keyboard

Solve two variable recursive equation in Mathematica, is that possible?

只谈情不闲聊 提交于 2019-12-14 04:25:24
问题 I tried to use RSolve to solve a two variable recursive equation in Mathematica , but it simply repeats what I type. Is it possible to solve two variable recursive equations in Mathematica ? 回答1: Perhaps you should include the equation in your question, as it is possible you are simply using RSolve incorrectly. Mathematica can solve some two-variable recurrence equations, but not all. Sometimes the free package Guess.m can solve what RSolve cannot. (You must request access to the file;

non-negative integer solutions to system of linear equations in mathematica

老子叫甜甜 提交于 2019-12-14 03:57:41
问题 Related to my previous question, just wonder how to solve a system of linear equations with non-negative integral solutions, for example: c11*x+c12*y+c13*z=d1 c21*x+c22*y+c23*z=d2 Thanks a lot! Edit I meant efficiently. For example, I could have used FrobeniusSolve to get two solution lists and try to find the intersection. But sometimes, the individual solution list is probably hugely large. Or try to verify each individual solution returned by one FrobeniusSolve to see whether they satisfy

How can I use Piecewise[] with a variable number of graphs/intervals

瘦欲@ 提交于 2019-12-14 03:53:59
问题 I'm writing a program to do cubic spline interpolation. Basically the program will piece together cubic polynomials over certain intervals. I would like to graph this result if all possible with piecewise[] or another similar function. In my code I have my equations in an array that outputs like this (for example): {2+3/4 (-1+X$6836)+1/4 (-1+X$6836)^3,3+3/2 (-2+X$6836)+3/4 (-2+X$6836)^2-1/4 (-2+X$6836)^3} I also have another array that stores the specific intervals to graph over for each

TableForm with TableHeadings aligned to Left but the content of table aligned to Right

北战南征 提交于 2019-12-14 03:48:16
问题 TableForm with TableHeadings option is a quick and easy way to display good-looking classical table in Mathematica FrontEnd. The only problem is that it is common to display such a table with headings aligned to the left but the content of the table aligned to the right. Is it possible to force TableForm to behave in this way? Or if not, what is the best way to make an analog of TableForm that behaves in this way? 回答1: You can use Grid and Alignment . Here is one way: a = Map[Mod

How should I write a function to be used in Apply in Mathematica?

左心房为你撑大大i 提交于 2019-12-14 03:42:20
问题 I am wondering how I can write a function to be used in the Apply function in Mathematica? For example, I want to trivially re-implement the Or function, I found the following Apply[(#1 || #2)&,{a,b,c}] is not okay since it only Or 'ed the first two elements in the list. Many thanks! 回答1: This will work, no matter how many vars, and is a general pattern: Or[##]&, for example In[5]:= Or[##] & @@ {a, b, c} Out[5]= a || b || c However, in the case of Or , this is not good enough, since Or is

Change two different parts in a table according to the same random value

半城伤御伤魂 提交于 2019-12-14 03:29:48
问题 I am trying to change 2 different rows in my table according to one random variable each time, For example I want if a random number>0.5 then to change one row with the value in it +1 and the other row with its value -1, otherwise do nothing. I tried the following code but I am confused, Can anyone please help me? InitialMatrix[3, 3, 3, 3] + MapAt[f, MapAt[g, Table[0, {3}, {3}, {3}, {3}], Flatten[Table[{i, j, 1, k}, {i, 3}, {j, 3}, {k, 3}], 2]], Flatten[Table[{i, j, 2, k}, {i, 3}, {j, 3}, {k,

Permanent changing FrontEnd behavior to force aborting evaluation of the full sequence of inputs

妖精的绣舞 提交于 2019-12-14 02:30:15
问题 This sub-question comes from the question on aborting evaluation of the full sequence of inputs together with previous sub-question. How should we change the file KeyEventTranslations.tr (and/or MenuSetup.tr) to force aborting evaluation of the full sequence of inputs? One possible method to achieve this is described in the previous sub-question associated with another approach: temporary changing of FrontEndEventActions for the current session. I think these questions should be separated as