Can anyone explain or provide reference to
ai X aj <= max(Ai + Ai+1 + .. + Aj)
I am unable to figure out the output of this expression, can you provide any explanation or example please.
Related
I'm trying to plot the following implicit formula in R:
1 = x^2 + 4*(y^2) + x*y
which should be an ellipse. I'd like to randomly sample the x values and then generate the graph based on those.
Here's a related thread, but the solutions there seem to be specific to the 3D case. This question has been more resistant to Googling that I would have expected, so maybe the R language calls implicit formulas something else.
Thanks in advance!
Two things you may not understand. When plotting implicit functions with that technique, you need to move all terms to the RHS of the function so that your implicit function becomes:
0 = -1+ x^2 + 4*(y^2) + x*y
Then using the contour value of zero will make sense:
x<-seq(-1.1,1.1,length=1000)
y<-seq(-1,1,length=1000)
z<-outer(x,y,function(x,y) 4*y^2+x^2+x*y -1 )
contour(x,y,z,levels=0)
I got a sign wrong on the first version. #mnels' was correct.
I am trying to help a friend in finance research. I wish to solve, for x, the equation that looks like :
g,h,c,p,a,b are all constants.
I guess the first step would be to find it's derivative. This I did, using an online derivative calculator at http://www.derivative-calculator.net/. I got this :
Further, I am trying to solve for x, assuming this is equal to zero. None of the online tools for 'solve for x' are able to do it. I have tried, Wolfram Alpha's online tool for 'solve-for-x', QuickMath, CynMath etc. All of them, 'cannot be solved'. I am looking for a solution like : x = blah-blah-blah. I have also tried the online Mathlab/Octave tools at CompileOnline/TutorialPoint. What can I do to solve for x, (preferably not having to install MathLab etc). Is there anything about these equations that render them incapable to be solved by Wolfram Alpha or such online tools for 'solve for x' ?
You could just write a function in R to solve your equation for a given value of x:
solvex <- function(x) {
g = 1
h = 1
c = 1
p = 1
b = 1
a = 1
g * (1 - exp(h*x + c)) + p * (1 - exp(b*x + a))
}
Then, to plot the solutions over some range, do something like:
x <- seq(-100,100,1)
yseq <- lapply(x, solvex)
plot(x, yseq, type = "l")
Finding a solution using Mathematica:
I was taking a derivative in Mathematica and the result containted the term Sqrt', and I was wondering what the ' on the end ment? I believe in means 1/Sqrt from doing the derivative by hand but if someone could confirm this is how the result is displayed I would appreciate it. Here is my input and output.
In f[p_] := cSqrt[(m^2)*(c^2) + (p - eA/c)^2] + e*phi
In f'[p]
Out 2 (-(eA/c) + p) Derivative[1][cSqrt][c^2 m^2 + (-(eA/c) + p)^2]
Best,
Ben
This may help:
http://blog.wolfram.com/2011/05/20/mathematica-qa-three-functions-for-computing-derivatives/
Apparently ' is the standard shorthand notation for the derivative.
Using code FullSimplify[Abs[q + I*w], Element[{q, w}, Reals]] results in
Abs[q + I w]
and not
Sqrt[q^2 + w^2]
What am I missing?
P.S. Assuming[{q \[Element] Reals, w \[Element] Reals},
Abs[q + I*w]] does not work either.
Note: Simplify[Abs[w]^2, Element[{q, w}, Reals]] and Simplify[Abs[I*q]^2, Element[{q, w}, Reals]] work.
The problem is that what you assume to be "Simple" and what MMA assumes to be simple are two different things. Taking a look at ComplexityFunction indicates that MMA primarily looks at "LeafCount". Applying LeafCount gives:
In[3]:= Abs[q + I w] // LeafCount
Out[3]= 8
In[4]:= Sqrt[q^2 + w^2] // LeafCount
Out[4]= 11
So, MMA considers the Abs form to be better. (One can visually explore the simplicity using either TreeForm or FullForm). What we need to do is tell MMA to treat MMA as more expensive. To do this, we take the example from ComplexityFunction and write:
In[7]:= f[e_] := 100 Count[e, _Abs, {0, Infinity}] + LeafCount[e]
FullSimplify[Abs[q + I w], Element[{q, w}, Reals],
ComplexityFunction -> f]
Out[8]= Sqrt[q^2 + w^2]
As requested. Basically, we are telling MMA through f[e] that the count of all parts of the form Abs should count as 100 leaves.
EDIT: As mentioned by Brett, you can also make it more general, and use _Complex as the rule to look for:
In[20]:= f[e_] := 100 Count[e, _Complex, {0, Infinity}] + LeafCount[e]
FullSimplify[Abs[q + I w], Element[{q, w}, Reals],
ComplexityFunction -> f]
Out[21]= Sqrt[q^2 + w^2]
I suggest using ComplexExpand, which tells the system that all variables are real.
In[28]:= Abs[q + I*w] // ComplexExpand
Out[28]= Sqrt[q^2 + w^2]
These comments are not helpful. Mathematica is failing to evaluate complex numbers, as in Abs[5+i20] is left unchanged. The i is coded correctly. Making abstract observations about 'what is or is not simple' is unrelated and wrong. There is a float that should result, not some algebra. N and ImportForm do not work, either.
Here is the setup. No assumptions for the values I am using.
n=2; % dimension of vectors x and (square) matrix P
r=2; % number of x vectors and P matrices
x1 = [3;5]
x2 = [9;6]
x = cat(2,x1,x2)
P1 = [6,11;15,-1]
P2 = [2,21;-2,3]
P(:,1)=P1(:)
P(:,2)=P2(:)
modePr = [-.4;16]
TransPr=[5.9,0.1;20.2,-4.8]
pred_modePr = TransPr'*modePr
MixPr = TransPr.*(modePr*(pred_modePr.^(-1))')
x0 = x*MixPr
Then it was time to apply the following formula to get myP
, where μij is MixPr. I used this code to get it:
myP=zeros(n*n,r);
Ptables(:,:,1)=P1;
Ptables(:,:,2)=P2;
for j=1:r
for i = 1:r;
temp = MixPr(i,j)*(Ptables(:,:,i) + ...
(x(:,i)-x0(:,j))*(x(:,i)-x0(:,j))');
myP(:,j)= myP(:,j) + temp(:);
end
end
Some brilliant guy proposed this formula as another way to produce myP
for j=1:r
xk1=x(:,j); PP=xk1*xk1'; PP0(:,j)=PP(:);
xk1=x0(:,j); PP=xk1*xk1'; PP1(:,j)=PP(:);
end
myP = (P+PP0)*MixPr-PP1
I tried to formulate the equality between the two methods and seems to be this one. To make things easier, I skipped the summation of matrix P in both methods .
where the first part denotes the formula that I used, and the second comes from his code snippet. Do you think this is an obvious equality? If yes, ignore all the above and just try to explain why. I could only start from the LHS, and after some algebra I think I proved it equals to the RHS. However I can't see how did he (or she) think of it in the first place.
Using E for expectation, the one dimensional version of your formula is the familiar:
Variance(X) = E((X-E(X))^2) = E(X^2) - E(X)^2
While the second form might be easier programming, I'd worry about ending up with a negative (or, in the multidimensional case, non positive definite) answer by using it, due to rounding error.