How can I substitute constants into this set of equations? (Mathematica) - wolfram-mathematica

I'm new to Mathematica and I'm trying to solve this set of trig equations (I'm not exactly sure if the syntax looks correct):
Solve[Tan[(delta + beta)/2] == nz*Tan[theta/2] &&
ny*Tan[(delta - beta)/2] == nx &&
Cos[(delta + beta)/2]*Cos[gamma/2] == Cos[theta/2], {delta, beta,
gamma}, Reals]
The goal is to solve for delta, beta and gamma. I want to substitute different values of nx,ny,nz,theta into these equations and get the solutions. How can I substitute those values in there? Thanks:)

Related

Why is an empty list returned when solving for this linear system in Maxima?

I'm trying to solve a simple linear system in Maxima using solve like so:
/*Standard form*/
eq1 : x1 + 3*x2 + s1 = 6;
eq2 : 3*x1 + 2*x2 + s2 = 6;
base1 : solve([eq1,eq2],[s1,s2]);
This however returns an empty list and I don't know why. Any ideas? I'm pretty sure the system has a solution, so that shouldn't be the issue.
EDIT:
I attempted to insert the equations explicitly into solve in place of eq1 and eq2, and now it works. Now the question is, why do I need to explicitly insert the equations to be solved for into the first argument of solve. An in-depth answer about how Maxima works in this case would be welcome.
This happened to me when one of the variables in the equation was previously defined.
E.g., if z was previously defined:
Then simply changing z to, e.g., p returns the solutions:

How to simplify fractional powers in Mathematica?

I was wondering how to make Mathematica simplify (x^2(y^2+1))^(5/2)*(y^2+1)^(3/2) to x^5(y^2+1)^4?
Simplify
FullSimplify
You can use FullSimplify[<expression>] to cause Mathematica to attempt to simplify your expression using a variety of strategies. You might need to include some of your assumptions about x and y to get the result you expect. For example, are x and y both real numbers? Then you could try:
FullSimplify[(x^2(y^2+1))^(5/2)*(y^2+1)^(3/2), {Element[{x,y},Reals]}]
In:
(x^2 (y^2 + 1))^(5/2)*(y^2 + 1)^(3/2) // Assuming[Element[{x,y},Reals], Simplify[#]] &
Out:
(1 + y^2)^4 Abs[x]^5

Analytical solution of driven damped oscillator with aperiodic conditions using DSolve from Wolfram Mathematica

I derived a solution for a driven damped oscillator using the DSolve functionality of Wolfram Mathematica. I chose the following Ansatz:
DSolve[{
0 == -Fmax (1 - Cos[t]) + k x[t] +
d Derivative[1][x][t] +
m Derivative[2][x][t],
x[0] == xStart, x'[0] == vStart}, x[t], t]
Mathematica is able to solve this analytically and I can derive solutions if I pass parameters to the variables.
Anyhow, the derived solution fails at the moment, the given parameters for mass (m), spring constant (k) and dampening (d) fulfill the condition for aperiodic behavior
d=2*Sqrt[m*k]
due to the fact, that a division by zero occurs. The overall solution is given by a big fraction with a denominator containing the following factor
Sqrt[d^2 - 4 k m]
This factor becomes zero in case aperiodic conditions occur which leads to a devision by zero.
Now the fun starts ...
I case I pass the aperiodic conditions before giving the system to DSolve:
DSolve[{
0 == -Fmax (1 - Cos[t]) + k x[t] +
2 Sqrt[k m] Derivative[1][x][t] +
m Derivative[2][x][t],
x[0] == xStart, x'[0] == vStart}, x[t], t]
DSolve easily derives a working solution without dividing by zero.
It seems to me, as Mathematica is simplifying the more general solution, in a way that I can't use the aperiodic conditions anymore, even though there is a working solution for that case. My question is, can I somehow tell DSolve, to take into account the aperiodic conditions?
Sure, I can workaround the problem with Piecewise[], but for further calculations a general solution without Piecewise[] would be more suitable.
Thanks in advance for you time and help,
Greetings
Tschibi

Solving a Nonlinear equation with Julia

I am trying to solve a nonlinear equation with Julia,
I have the following nonlinear equation
Nfoc(k,k1,z,n)=(1-α)*exp(z)*(k/n)^α/(exp(z)*(k^α)*(n^(1-α))+k*(1-δ)-k1) - A/(1-n)
and I have a grid of values for k,k1 and z and I am trying to find the values of x that are the roots of this equation for each k,k1, and z, by using this loop:
MatrixN=zeros(nkk,M,nkk)
for i=1:nkk,j=1:M
for i2=1:nkk
MatrixN[i,j,i2]=roots(Nfoc[K[i],K[i2],z(j),n])
end
end
However, its obvious that the command roots its not functioning.
I would deeply appreciate any help in the less techical way possible!
I don't have enough knowledge to work on your use case, but in general, one way to find roots of a parametric function could be:
using FastAnonymous # Creating efficient "anonymous functions" in Julia
using Roots
f(x,k,k1,z,n) = exp(x) - x^4 + k + k1 + z + n
function f_gen(k,k1,z,n)
#anon x -> f(x,k,k1,z,n)
end
fzero(f_gen(0,0,0,0), 1) # => finds x so f(x,0,0,0,0) = 0 using a derivative free method

How is `(d*a)mod(b)=1` written in Ruby?

How should I write this:
(d*a)mod(b)=1
in order to make it work properly in Ruby? I tried it on Wolfram, but their solution:
(da(b, d))/(dd) = -a/d
doesn't help me. I know a and b. I need to solve (d*a)mod(b)=1 for d in the form d=....
It's not clear what you're asking, and, depending on what you mean, a solution may be impossible.
First off, (da(b, d))/(dd) = -a/d, is not a solution to that equation; rather, it's a misinterpretation of the notation used for partial derivatives. What Wolfram Alpha actually gave you was:
, which is entirely unrelated.
Secondly, if you're trying to solve (d*a)mod(b)=1 for d, you may be out of luck. For any value of a and b, where a and b have a common prime factor, there are an infinite number of values of d that satisfy the equation. If a and b are coprime, you can use the formula given in LutzL's answer.
Additionally, if you're looking to perform symbolic manipulation of equations, Ruby is likely not the proper tool. Consider using a CAS, like Python's SymPy or Wolfram Mathematica.
Finally, if you're just trying to compute (d*a)mod(b), the modulo operator in Ruby is %, so you'd write (d*a)%(b).
You are looking for the modular inverse of a modulo b.
For any two numbers a,b the extended euclidean algorithm
g,u,v = xgcd(a, b)
gives coefficients u,v such that
u*a+v*b = g
and g is the greatest common divisor. You need a,b co-prime, preferably by ensuring that b is a prime number, to get g=1 and then you can set d=u.
xgcd(a,b)
if b = 0
return (a,1,0)
q,r = a divmod b
// a = q*b + r
g,u,v = xgcd(b, r)
// g = u*b + v*r = u*b + v*(a-q*b) = v*a+(u-q*v)*b
return g,v,u - q*v

Resources