wolfram-mathematica

different result with scipy integrate.tplquad

泄露秘密 提交于 2019-12-02 08:58:13
问题 With Matematica this integral gives me 3. wolfram alpha With integrate.tplquad I get -3. This is Matematica code. Integrate[1-x, {(0,2),(0,3-1.5*x),(0,6-3*x -2*y)}] I can't see what I am doing wrong with ntegrate.tplquad f = lambda x,y,z: 1-x x1, x2 = 0,2 y1, y2 = lambda x : 0 , lambda x:3-1.5*x z1, z2 = lambda x,y:0, lambda x,y: 6 -3*x -2*y print(integrate.tplquad(f,x1,x2, y1, y2, z1, z2)[0]) -3.0 回答1: Double-check the tplquad docstring; you'll see that the signature of the function f is f(z

Return equality from Mathematica function

夙愿已清 提交于 2019-12-02 05:56:42
I have a function that returns equalities, which I want to print, for example, x==y, or 2x+5==10. These usually have no meaning for mathematica, it cannot simplify it furhter. However, sometimes the both sides are equal, but I want to be able to print the equality in unevaluated form: that is, I want Mathematica to print x==x, and not True. A very simple example: Print[printableEqual[x,y]] should print x==y, while Print[printableEqual[x,x]] should print x==x Edit: The reason is that I have a relation among graphs. I would like to return things like G1 == t*G2 + s*G3 where t,s are integers, and

Mathematica: subscript simplification under noncommutative multiplication

烈酒焚心 提交于 2019-12-02 04:29:38
Using Subscript[variable, integer] in Mathematica 7.0+, I have expressions of the following form: a_-4 ** b_1 ** a_-4 ** b_-4 ** a_1 ** c_-4 ** c_1 ** c_5 I would like to simplify this expression. Rules: * Variables with the same subscript to don't commute, * variables with different subscripts do commute. I need a way to simplify the expression and combine like terms (if possible); the output should be something like: (a_-4)^2 ** b_-4 ** c_-4 ** b_1 ** a_1 ** c_1 ** c_5 The most important thing I need is to order the terms in the expression by subscripts while preserving the rules about what

Equation of a helix parametrized by arc length between two points in space

允我心安 提交于 2019-12-02 03:18:44
What is the equation of a helix parametrized by arc length (i.e. a function of arc length) between any two points in space? Is there any function for this ? How do i implement the same using matlab or mathematica ? To find the arc length parameterization of the helix defined by r(t) = cos t i + sin t j + t k Arc Length = s = Integral(a,b){sqrt((dx/dt)^2 + (dy/dt)^2 + (dz/dt)^2) dt} First find the arc length function s(t) = Integral(0,t) { sqrt((sin u)^2 + (cos u)^2 + 1) du } = Integral(0,t) { sqrt(2) du } = sqrt(2) * t Solving for t gives t = s / sqrt(2) Now substitute back to get r(s) = cos(s

Force function evaluation on declaration

夙愿已清 提交于 2019-12-02 03:03:05
I have a function f[x_,y_,z_]:=Limit[g[x+eps,y,z],eps->0]; and I plot f[x,y,z] in the next step. Earlier, I used to evaluate the limit and copy the expression in the definition of f . I tried to make it all in one step. However, the evaluation of the Limit is done only when I try to plot f . As a result, every time I change around the variables and replot, the limit is evaluated all over again (it takes about a min to evaluate, so it becomes annoying). I tried evaluating the limit first, and then doing f[x_,y_,z_]:=% . But that doesn't work either. How do I get the function to evaluate the

How to make an analog of InString[]?

旧时模样 提交于 2019-12-01 22:07:18
I have discovered that InString[] does not work in MathLink mode when sending input with EnterExpressionPacket header. So I need to define my own function that returns previous input line. One way I have developed here does not work in some cases: In[1]:= Unevaluated[2 + 2] With[{line = $Line - 1}, HoldForm[In[line]]] /. (DownValues[In]) Out[1]= Unevaluated[2 + 2] Out[2]= 2 + 2 This is because RuleDelayed has no HoldAllComplete attribute. Adding this attribute makes this OK: In[1]:= Unprotect[RuleDelayed]; SetAttributes[RuleDelayed, HoldAllComplete]; Protect[RuleDelayed]; Unevaluated[2 + 2]

Calculating expectation for a custom distribution in Mathematica

感情迁移 提交于 2019-12-01 20:04:30
This question builds on the great answers I got on an earlier question: Can one extend the functionality of PDF, CDF, FindDistributionParameters etc in Mathematica? To start I have PDFs and CDFs for two custom distributions: nlDist and dplDist as you can see from the code dplDist builds upon nlDist. nlDist /: PDF[nlDist[alpha_, beta_, mu_, sigma_], x_] := (1/(2*(alpha + beta)))*alpha* beta*(E^(alpha*(mu + (alpha*sigma^2)/2 - x))* Erfc[(mu + alpha*sigma^2 - x)/(Sqrt[2]*sigma)] + E^(beta*(-mu + (beta*sigma^2)/2 + x))* Erfc[(-mu + beta*sigma^2 + x)/(Sqrt[2]*sigma)]); nlDist /: CDF[nlDist[alpha_,

The logic of Message internals

允我心安 提交于 2019-12-01 19:52:02
I am trying to figure out the logic of Message behavior. Consider evaluation of the following: On[] Sin[1,1] After evaluating the above you will get about 830 (!) Messages (in Mathematica 7). All these Messages have arisen during producing the one: Sin::argx: Sin called with 2 arguments; 1 argument is expected. >> (this is one but last Message ). The last Message Message::trace: Message[Sin::argx,Sin,2] --> Null. >> corresponds to finishing of the work of internal Mathematica 's Message function. Most of the other Messages go from evaluation of $NewMessage and $MessagePrePrint . My questions

Specifics of usage and internal work of *Set* functions

纵然是瞬间 提交于 2019-12-01 18:21:14
I just noticed one undocumented feature of internal work of *Set* functions in Mathematica . Consider: In[1]:= a := (Print["!"]; a =.; 5); a[b] = 2; DownValues[a] During evaluation of In[1]:= ! Out[3]= {HoldPattern[a[b]] :> 2} but In[4]:= a := (Print["!"]; a =.; 5); a[1] = 2; DownValues[a] During evaluation of In[4]:= ! During evaluation of In[4]:= Set::write: Tag Integer in 5[1] is Protected. >> Out[6]= {HoldPattern[a[b]] :> 2} What is the reason for this difference? Why a is evaluated although Set has attribute HoldFirst ? For which purposes such behavior is useful? And note also this case:

Using Position correctly

亡梦爱人 提交于 2019-12-01 17:16:44
In the mma help docs for Position , the following is listed under "Possible Issues" In[1]:= Position[Range[-1, 1, 0.05], 0.1] Out[1]= {} There is no explanation given though. Why does this happen? So if I really need to find the position of 0.1 in Range[-1,1,0.05] , how do I do it? It is a numeric precision issue: 0.1 in the Range is not internally the same as 0.1 typed in. The normal way to resolve this is to compare with Equal rather than the implicit SameQ . Position[Range[-1, 1, 0.05], x_ /; x == 0.1] 来源: https://stackoverflow.com/questions/5750623/using-position-correctly