mathematica, Simplify trig function - wolfram-mathematica

if say i have a function given :
singlepattern = Cosh[theta] + Cosh[3theta]
How do i get a rational expression in terms of x of the function if i want to substitute Cosh[theta] by
"Cosh[theta] = ( x )/ 2 "
expression?

I retagged the question as a homework. You should look into ChebyshevT polynomials. It has the property that ChebyshevT[3, Cos[th] ]==Cos[3*th]. So for your problem the answer is
In[236]:= x/2 + ChebyshevT[3, x/2]
Out[236]= -x + x^3/2
Alternatively, you could use TrigExpand:
In[237]:= Cos[th] + Cos[3*th] // TrigExpand
Out[237]= Cos[th] + Cos[th]^3 - 3 Cos[th] Sin[th]^2
In[238]:= % /. Sin[th]^2 -> 1 - Cos[th]^2 // Expand
Out[238]= -2 Cos[th] + 4 Cos[th]^3
In[239]:= % /. Cos[th] -> x/2
Out[239]= -x + x^3/2
EDIT The reason the above has to do with the explicit question, is that Cosh[theta] == Cos[I*u] for some u. And since u or theta are formal, results will hold true.

Use Solve to solve for theta, then substitute, Expand, and Simplify:
In[16]:= TrigExpand[Cosh[3 theta] + Cosh[theta]] /.
Solve[Cosh[theta] == (x)/2, theta] // FullSimplify
During evaluation of In[16]:= Solve::ifun: Inverse functions are being used by Solve,
so some solutions may not be found; use Reduce for complete solution information. >>
Out[16]= {1/2 x (-2 + x^2), 1/2 x (-2 + x^2)}

This might interest you:
http://www.wolframalpha.com/input/?i=cosh%28x%29+%2B+cosh%283*x%29

Related

How to display higher order terms first?

Is there a way to make Mathematica display higher order terms first? I want x^3 to come before x^2 etc. but this is what I get:
In[1]:= A = x^2 + x
Out[1]= x + x^2
In[2]:= B = 2 x + 3
Out[2]= 3 + 2 x
In[3]:= A + B
Out[3]= 3 + 3 x + x^2
I really just want to reverse the display of terms. How can I get something like this?
In[3]:= A + B
Out[3]= x^2 + 3 x + 3
Multivariate polynomials display curiously as well. Despite the order of the terms of this expression:
x^2 + y^4 + 3 x + 3 + xy^2 + y + y^3
I get
3 + 3 x + x^2 + xy^2 + y + y^3 + y^4
I'm not entirely sure of the best way of displaying this, but I know I want higher order terms first. Can this be done?
TraditionalForm may help you
3+x+x^2//TraditionalForm
displays as
x^2+x+3
but you should be cautious because TraditionalForm items cannot have any further sensible math done to them. For example, because of TraditionalForm has higher precedence than = it turned the polynomial into traditional form and then assigned the result.
A=3+x+x^2//TraditionalForm
Solve[A==0,x]
And then the calculation on that traditional form gives you:
{{x->1/2 (-1-Sqrt[-11+4 TraditionalForm^(-1)[0]},
{x->1/2 (-1+Sqrt[-11+4 TraditionalForm^(-1)[0]}}
But if you carefully keep separate those things that are pretty to look at from those things you are using to do further calculations with then this may work for you.

Define a region in using MaxValue[] function in Mathematica

The following two gives completely different output from Mathematica.
The online document does not seem to require a pair of curly braces.
https://reference.wolfram.com/language/ref/MaxValue.html
Tau = 10;
Diff = 1/3;
phi[tau_] := 0.5 Sin[Pi tau/(Tau + 2 Diff)] + 0.5 Sin[Pi (tau + 2 Diff)/(Tau + 2 Diff)];
In[1]=MaxValue[phi[tau], {tau} \[Element] Interval[{0.0, 10.0}]]
In[2]=MaxValue[phi[tau], tau \[Element] Interval[{0.0, 10.0}]]
Output:
Output[1]=0.995185
MaxValue::objfs: The objective function {0.5 Sin[(3 \[Pi] Subscript[tau, 1])/32]+0.5 Sin[3/32 \[Pi] (2/3+Subscript[tau, <<1>>])]} should be scalar-valued. >>
Out[2]=MaxValue[0.5 Sin[(3 \[Pi] tau)/32] + 0.5 Sin[3/32 \[Pi] (2/3 + tau)], tau \[Element] Interval[{-2.22507*10^-308, 10.}]]
The documentation does specify that you need curly braces when using the region specification method to define the constrains. In the Details and Options section fourth method of defining constraints with a region specification shows that the curly brackets are necessary.
Hope this helps.

Using Dsolve with Assumptions/Conditions

I would like to solve the following equation:
DSolve[u''[x]+k^2 u[x], u[x],x]
if k^2<0 the solution is
u[x]-> C[1] e^(kx) + C[2] e^(-kx)
if k^2>0 the solution is
u[x] -> C[1] Sin [kx] + C[2] Cos[kx]
in my equation
k^2=(a-b)/(c-d)
when b >a and c >d, meaning k^2<0
when I plug the equation into Mathematica, it reverses the sign and given me the exponents solution and not the cosine one.
does anyone have an idea how to plug the Assumptions or Conditions into the equation? Or patch between the two so I'll get the true solution?
Cheers
introduce a constant k2n which is the negative of your assumed negative k^2:
First#DSolve[{u''[x] - k2n u[x] == 0 }, u[x], x]
E^(Sqrt[k2n] x) C[1] + E^(-Sqrt[k2n] x) C[2]
now we know k2n>0 so back substitute
% /. Sqrt[k2n] -> k
E^(k x) C[1] + E^(-k x) C[2]
As a general answer I don't think there is a way to tell DSolve to make assumptions about parameters.

How to replace implicit subexpressions in Mathematica?

I have this expression in Mathematica:
(a^2 (alpha + beta)^2)/(b^2 + c^2) + (a (alpha + beta))/(b^2 + c^2) + 1
As you can see, the expression has a couple of subexpressions that repeat throughout it.
I want to be able to replace a/(b^2+c^2) with d and alpha+beta with gamma.
The final expression should then be:
1+d*gamma+a*d*gamma^2
I have much more complicated expressions where being able to do this would greatly simplify my work.
I have tried Googling this question, and I only find answers that use FactorTerms and ReplaceRepeated, but do not work consistently and for a more complicated expression like this one. I am hoping that someone here has the answer.
The hard part for the case at hand is the rule for d. Perhaps, there are simpler ways to do it, but one way is to expand the powers to products, to make it work. Let's say this is your expression:
expr = (a^2 (alpha + beta)^2)/(b^2 + c^2) + (a (alpha + beta))/(b^2 + c^2) + 1
and these are the rules one would naively write:
rules = {a/(b^2 + c^2) -> d, alpha + beta -> gamma}
What we would like to do now is to expand powers to products, in both expr and rules. The problem is that even if we do, they will auto-evaluate back to powers. To prevent that, we'll need to wrap them into, for example, Hold. Here is a function which will help us:
Clear[withExpandedPowers];
withExpandedPowers[expr_, f_: Hold] :=
Module[{times},
Apply[f,
Hold[expr] /. x_^(n_Integer?Positive) :>
With[{eval = times ## Table[x, {n}]}, eval /; True] /.
times -> Times //.
HoldPattern[Times[left___, Times[middle__], right___]] :>
Times[left, middle, right]]];
For example:
In[39]:= withExpandedPowers[expr]
Out[39]= Hold[1+(a (alpha+beta))/(b b+c c)+((alpha+beta) (alpha+beta) a a)/(b b+c c)]
The following will then do the job:
In[40]:=
ReleaseHold[
withExpandedPowers[expr] //.
withExpandedPowers[Map[MapAt[HoldPattern, #, 1] &, rules], Identity]]
Out[40]= 1 + d gamma + a d gamma^2
We had to additionally wrap the l.h.s. of rules in HoldPattern, to prevent products from collapsing back to powers there.
This is just one case where we had to fight the auto-simplification mechanism of Mathematica, but for this sort of problems this will be the main obstacle. I can't assess how robust this will be for larger and more complex expressions.
Using ReplaceRepeated:
(a^2 (alpha + beta)^2)/(b^2 + c^2) + (a (alpha + beta))/(b^2 + c^2) +
1 //. {a/(b^2 + c^2) -> d, alpha + beta -> gamma}
Or using TransformationFunctions:
FullSimplify[(a^2 (alpha + beta)^2)/(b^2 +
c^2) + (a (alpha + beta))/(b^2 + c^2) + 1,
TransformationFunctions -> {Automatic, # /.
a/(b^2 + c^2) -> d &, # /. alpha + beta -> gamma &}]
Both give:
1 + gamma (d + (a^2 gamma)/(b^2 + c^2))
I modestly --- I am not a computer scientist --- think this is simpler than all other proposed solutions
1+a(alpha+beta)/(b^2 + c^2) +a^2(alpha+beta)^2/(b^2 + c^2) \\.
{a^2-> a z, a/(b^2 + c^2)-> d,alpha+\beta -> gamma,z-> a}

How to substitute an aggregate expression

For example, I have symbollically
1/n*Sum[ee[k] + 1, {k, j, n}]^2
And I want to substitute Sum[ee[k], {k, j+1, n}] to be x. How can I do this? May thanks for your help!
You may use the recurrence relation for the sum. For example:
f[j] := f[j + 1] + (ee[j] + 1);
1/N f[j]^2 /. f[j + 1] -> x
Out
(1 + x + ee[j])^2/N
Edit
Based on several questions you posted, I think you are somehow misinterpreting what the Replace[] command does. It is not "algebraic" based, but "pattern" based. It doesn't understand nor use more algebraic transformations than those already defined (by you or by Mma itself).
For example:
x/. (x-1)->y
will not match anything. But
(x-1) /. x->y-1
Will give you (y-2) because the pattern x is matched.
Moreover:
x = 3;
(x - 1) /. x -> y - 1
will give you 2 because x is evaluated before the possible match, and the x in the pattern is also evaluated (just paste, execute and look at the symbol color).
1/N*Sum[ee[k] + 1, {k, j, N}]^2 /. Sum[ee[k] + 1, {k, j, N}] -> x
Doesn't that work, or do I misunderstand? By the way, you shouldn't use N as a variable. It's a Mathematica function.

Resources