Multiplying constant to an expression - wolfram-mathematica

I am multiplying constant to an expression which can be seen from below. But the final expression is getting reduced. I just want it to be multiplied.
(x^2 (-((1. (2 - 1/x)^3 x^5)/(
Sqrt[1 - x^2] (0. + 1. x^2)^1.5)) + ((2 - 1/x)^3 x^5)/((1 - x^2)^(
3/2) (0. + 1. x^2)^0.5) + (3 (2 - 1/x)^2 x^2)/(
Sqrt[1 - x^2] (0. + 1. x^2)^0.5) + (4 (2 - 1/x)^3 x^3)/(
Sqrt[1 - x^2] (0. + 1. x^2)^0.5)))/(3 (2 - 1/x)^2) * (4)
Kindly help. Thanks in advance.

It simplifies ok.
expr = (x^2 (-((1. (2 - 1/x)^3 x^5)/
(Sqrt[1 - x^2] (0. + 1. x^2)^1.5)) +
((2 - 1/x)^3 x^5)/
((1 - x^2)^(3/2) (0. + 1. x^2)^0.5) +
(3 (2 - 1/x)^2 x^2)/
(Sqrt[1 - x^2] (0. + 1. x^2)^0.5) +
(4 (2 - 1/x)^3 x^3)/
(Sqrt[1 - x^2] (0. + 1. x^2)^0.5)))/
(3 (2 - 1/x)^2)*(4);
Simplify[expr] // InputForm
(-2.6666666666666665*x^4*(-1.5*x^6*(x^2)^0.5 + 1.x^7(x^2)^0.5 + 1.5*x*(x^2)^1.5 -
4.5*(x^2)^2.5 + x^5*(-0.25*(x^2)^0.5 - 3.(x^2)^1.5) +
x^4(1.375*(x^2)^0.5 + 3.(x^2)^1.5) + x^3(-0.75*(x^2)^0.5 + 3.25*(x^2)^1.5)))/
((0.5 - 1.x)^2(x^2)^2.Sqrt[1 - x^2](-1. + x^2))

Related

Solving Large System of Non-Linear Equations Using Mathematica

So I'm trying to create a graph of mu as a function of a variable A, where mu is part of a solution to the following system of 17 non-linear equations (with lambda, A, and r as parameters). However, I can't seem to find a way for Mathematica to solve this. Does anyone know how to solve a large system of non-linear equations? Have been researching methods for almost a month now but still no luck.
Also, to graph mu versus A, do I need Mathematica to solve this, or is there another method?
Solve[
mu*(yB - xB) = (1 - mu)*(xS - yS) &&
0 == -lambda*xB*yS - lambda*xB*(A - xS) + mu*(A*(1 - A - yB) - (1 - A)*xB) &&
0 == -lambda*yB*xS + lambda*(1 - A - yB)*yS + mu*((1 - A)*(A - xB) - A*yB) &&
0 == -lambda*xS*yB + lambda*(A - xS)*xB + (1 - mu)*(A*(1 - A - yS) - (1 - A)*xS) &&
0 == -lambda*yS*xB - lambda*yS*(1 - A - yB) + (1 - mu)*((1 - A)*(A - xS) - A*yS) &&
r*VBhn == lambda/mu*yS*(VBho - VBhn - PSB) + lambda/mu*(A - xS)*(VBho - VBhn - PACh) + (1 - A)*(VBln - VBhn) &&
r*VBlo == lambda/mu*xS*(VBln - VBlo + PBS) + A*(VBho - VBlo) + (1 - delta) &&
r*VBln == lambda/mu*yS*(VBlo - VBln - PACl) + A*(VBhn - VBln) &&
r*VBho == (1 - A)*(VBlo - VBho) + 1 &&
r*VShn == lambda/(1 - mu)*yB*(VSho - VShn - PBS) + (1 - A)*(VSln - VShn) &&
r*VSlo == lambda/(1 - mu)*xB*(VSln - VSlo + PSB) + lambda/(1 - mu)*(1 - A - yB)*(VSln - VSlo + PACl) + A*(VSho - VSlo) + (1 - delta) &&
r*VSln == A*(VShn - VSln) &&
r*VSho == lambda/(1 - mu)*xB*(VShn - VSho + PACh) + (1 - A)*(VSlo - VSho) + 1 &&
VBho - VBhn - PSB == VSln - VSlo + PSB &&
VBln - VBlo + PBS == VSho - VShn - PBS &&
VBho - VBhn - PACh == VShn - VSho + PACh &&
VBlo - VBln - PACl == VSln - VSlo + PACl,
{mu, xS, xB, yS, yB, VBhn, VBlo, VBln, VBho, VShn, VSlo, VSln, VSho, PSB, PBS, PACh, PACl}
]

Plotting a derivative

I have an implicit function, and I'm trying to plot the derivative of the solution of this function.
The function is:
p = \[Phi]/(1/\[Beta]) + ((1 - \[Phi]) \[Phi] (1 - \[Lambda]) \
\[Beta])/(((W - A) 1/\[Beta] + \[Phi] A/
p) 1/\[Beta] + \[Phi]*(1 - \[Phi]) A/p)/(
1/\[Beta] (\[Lambda]/((W - A) 1/\[Beta] + \[Phi] (A/
p) ) + (1 - \[Lambda])/(((W - A) 1/\[Beta] + \[Phi] A/
p) 1/\[Beta] + \[Phi] (1 - \[Phi]) A/p)))
And I would like to plot the derivative of the following expression w.r.t \[Phi]
\[Phi]/p ((1-\[Phi]) A + 1/\[Beta] A )
I've been trying to first solve for p explicitly, and plug the solution into the expression above and plot the derivative of the expression, but kept getting an error. My code is :
Manipulate[
ans = p /.
Solve[p - \[Phi]/(
1/\[Beta]) - ((1 - \[Phi]) \[Phi] (1 - \[Lambda]) \[Beta])/(((W \
- A) 1/\[Beta] + \[Phi] A/p) 1/\[Beta] + \[Phi]*(1 - \[Phi]) A/p)/(
1/\[Beta] (\[Lambda]/((W - A) 1/\[Beta] + \[Phi] (A/
p) ) + (1 - \[Lambda])/(((W - A) 1/\[Beta] + \[Phi] A/
p) 1/\[Beta] + \[Phi] (1 - \[Phi]) A/p))) == 0, p],
Plot[Evaluate[
D[f[\[Phi]] == \[Phi]/
ans[[2]] ((1 - \[Phi]) A + 1/\[Beta] A), \[Phi]]], {\[Phi],
0.01, 1}], {A, 10, 500}, {\[Beta], 0.001, 1}, {W, 100,
10^9}, {\[Lambda], 0.01, 1}]
The error I'm getting is:
"Manipulate:Manipulate argument \
Plot[Evaluate[\!\(\*SubscriptBox[\(\[PartialD]\), \(\[Phi]\)]\((f[\
\[Phi]] == \((\[Phi]\\\ Power[<<2>>])\)\\\ \((Times[<<2>>] +
Times[<<2>>])\))\)\)],{\[Phi],0.01,1}] does not have the correct \
form for a variable specification"
What am I doing wrong?
Thank you!

find the complexity for loop

what is the time complexity T(n) of the following potion of the code? for simplicity you may assume that n is power of 2. that is n=2^k . for some positive integer k.
for(i=1;;I<=n;i++)
for(j=n/2;j<n;j++)
print x;
choose the correct answer:
T(n)=n+1
T(n)=n^2+2n
T(n)=n
T(n)=n^3
T(n)=n(n/2 +1)
So lets write some iterations:
i j
1 0 to n-1
2 1 to n-1
3 1 to n-1
4 2 to n-1
5 2 to n-1
.
.
.
n-2 (n-2)/2 to n-1
n-1 (n-2)/2 to n-1
n n/2 to n-1
Now lets remember 1st and nth and calculate sum of ranges(end - start + 1) from i = 2 till i = n-1.
S = (n-1 - 1 + 1) + (n-1 - 1 + 1) + (n-1 - 2 + 1) + (n-1 - 2 + 1) + ... + (n-1 - (n-2)/2 + 1) + (n-1 - (n-2)/2 + 1)
...
S = (n - 1) + (n - 1) + (n - 2) + (n - 2) + ... + (n - (n-2)/2) + (n - (n-2)/2)
...
S = 2*(n - 1) + 2*(n - 2) + ... + 2*(n - (n - 2)/2)
...
S = 2*((n - 1) + (n - 2) + ... + (n - (n - 2)/2))
...
S = 2*(n*(n-2)/2 - (1 + 2 + 3 + ... + (n - 2)/2 ))
...
Last is arithmetic progression which is calculated by formula:
N*(A1 + A2)/2
where:
N = (n - 2)/2, A1 = 1, A2 = (n - 2)/2
So we end up with:
1 + 2 + 3 + ... + (n - 2)/2 = n*(n - 2)/8
...
S = n^2 - 2*n - 2*(n*(n - 2)/8)
...
S = n^2 - 2*n - n*(n - 2)/4
Now lets add 2 values that we remembered:
S = n + n/2 + n^2 - 2*n - n*(n - 2)/4
...
S = (4*n + 2*n + 4*n^2 - 8*n)/4 - n*(n - 2)/4
...
S = (4*n + 2*n + 4*n^2 - 8*n - n^2 + 2*n)/4
...
S = (3/4)*n^2
I am getting none of the above. I have checked and rechecked but can not find the error.

Google interview, can somebody confirm this bit string algorithm, pure hypothesis

This was a Google question i didn't figure out was right or wrong but a 2nd opinion never hurt. but the question is "given an n length bit-string solve for the number of times "111" appeared in all possible combinations."
now i know to find total combinations is 2^n what took me trouble was figuring out the number of occurrences i did find a pattern in occurrences but who knows for sure what happens when n becomes vast.
My logical solution was
#Level (n length) # combos # strings with "111" in it
_________________ ________ _____________________________
0 0 0
1("1" or "0") 2 0
2("11","01" etc. 4 0
3 8 1("111")
4 16 3
5 32 8
6 64 20
------------------------------------Everything before this is confirmed
7 128 49
8 256 119
9 512 288
10 1000 696
etc.. i can post how i came up with the magical fairy dust but yeah
I can help you with a solution:
Call the function to calculate number of string with n bit contains 111 is f(n)
If the first bit of the string is 0, we have f(n) += f(n - 1)//0 + (n - 1 bits)
If the first bit of the string is 1, we have f(n) += f(n - 2) + f(n - 3) + 2^(n - 3)
More explanation for case first bit is 1
If the first bit is 1, we have three cases:
10 + (n - 2 bits) = f(n - 2)
110 + (n - 3 bits) = f(n - 3)
111 + (n - 3 bits) = 2^(n - 3) as we can take all combinations.
So in total f(n) = f(n - 1) + f(n - 2) + f(n - 3) + 2^(n - 3).
Apply to our example:
n = 4 -> f(4) = f(3) + f(2) + f(1) + 2^1 = 1 + 0 + 0 + 2 = 3;
n = 5 -> f(5) = f(4) + f(3) + f(2) + 2^2 = 3 + 1 + 0 + 4 = 8;
n = 6 -> f(6) = f(5) + f(4) + f(3) + 2^3 = 8 + 3 + 1 + 8 = 20;
n = 7 -> f(7) = f(6) + f(5) + f(4) + 2^4 = 20 + 8 + 3 + 16 = 47;
n = 8 -> f(8) = f(7) + f(6) + f(5) + 2^5 = 47 + 20 + 8 + 32 = 107;
n = 9 -> f(9) = f(8) + f(7) + f(6) + 2^6 = 107 + 47 + 20 + 64 = 238;

Mathematica - DSolve spits out #1 in output

I'm not quite certain how to go about interpreting this.
I'm solving a fairly large system of differential equations, DSolve sometimes spits out a list of replacement rules that include terms that have a #1 . I know that #1 is a placeholder for an argument, but I just have no clue where it comes from.
If I have a system of equations similar to
eqs = {
x1'[t] = a1*x1[t] + b1*y1[t]
x2'[t] = a2*x2[t] + b2*y2[t]
...
y1'[t] = c1*y1[t] + d1*x1[t]
y2'[t] = c2*y2[t] + d2*x2[t]}
DSolve[eqs,vars,t] spits out something like
x1 -> e^(-ta1)
x2 -> e^(-t)RootSum[a1a2+a3b4#1 + a3a1b2#1]
...
Obviously a little more complicated but you get the point.
Nothing in the documentation hints as to why this is occurring, And it only happens under certain permuations of parameters (e.g. when I play around with parameters in the original system it either works or doesn't)
This RootSum may be generated by Integrate, which is used by DSolve internally, like so:
In[511]:= Integrate[1/(1 + x + x^2 + x^3 + x^4), x]
Out[511]= RootSum[1 + #1 + #1^2 + #1^3 + #1^4 &,
Log[x - #1]/(1 + 2 #1 + 3 #1^2 + 4 #1^3) &]
It represents a symbolic expression that is the Sum[ Log[x-t]/(1+2*t+3 t^2+4 t^3), {t, {"roots of 1+t+t^2+t^3+t^4"}] (caution, invalid syntax intentional). You can recover the expected normal form using Normal:
In[512]:= Normal[%]
Out[512]=
Log[(-1)^(1/5) + x]/(1 - 2 (-1)^(1/5) + 3 (-1)^(2/5) - 4 (-1)^(3/5)) +
Log[-(-1)^(2/5) + x]/(
1 - 4 (-1)^(1/5) + 2 (-1)^(2/5) + 3 (-1)^(4/5)) +
Log[(-1)^(3/5) + x]/(
1 - 3 (-1)^(1/5) - 2 (-1)^(3/5) + 4 (-1)^(4/5)) +
Log[-(-1)^(4/5) + x]/(1 + 4 (-1)^(2/5) - 3 (-1)^(3/5) + 2 (-1)^(4/5))
Or using the Sum directly:
In[513]:= Sum[
Log[x - t]/(1 + 2*t + 3 t^2 + 4 t^3), {t,
t /. {ToRules[Roots[1 + t + t^2 + t^3 + t^4 == 0, t]]}}]
Out[513]=
Log[(-1)^(1/5) + x]/(1 - 2 (-1)^(1/5) + 3 (-1)^(2/5) - 4 (-1)^(3/5)) +
Log[-(-1)^(2/5) + x]/(
1 - 4 (-1)^(1/5) + 2 (-1)^(2/5) + 3 (-1)^(4/5)) +
Log[(-1)^(3/5) + x]/(
1 - 3 (-1)^(1/5) - 2 (-1)^(3/5) + 4 (-1)^(4/5)) +
Log[-(-1)^(4/5) + x]/(1 + 4 (-1)^(2/5) - 3 (-1)^(3/5) + 2 (-1)^(4/5))
In[514]:= % - %% // FullSimplify
Out[514]= 0

Resources