1
$\begingroup$

I have the following equation. It involves variables: Delta, n1, n2, n3, and fi. Delta, n1, n2, n3 are real and positive. fi is real too. I would like to have n1 expressed as a function of Delta, n2, n3 and fi, so that I will be able to use n1[Delta,n2,n3,fi] in other functions. What needs to be done to this end?

Delta^2 = 2*M^2*(n2^2 + 0.5*(n1^2 - 2*n1*n2^2*n3^2*Cos[fi] + n2^4*n3^4 + n3^4) + n2*Sqrt[n2^2 + 2*n1*n3^2*Cos[fi] - 2*n2^2*n3^4]) 
$\endgroup$
13
  • 1
    $\begingroup$ use == for equation and not =. Then use Solve command, screen shot i.sstatic.net/19PXygO3.png and better avoid decimal numbers with exact solvers like Solve, so I changed your 0.5 with 1/2. Mathematica is not like Matlab. $\endgroup$ Commented Nov 28, 2024 at 18:59
  • $\begingroup$ If n1 is a positive real, what does n1[Delta,n2,n3,fi] mean? $\endgroup$ Commented Nov 28, 2024 at 19:03
  • 1
    $\begingroup$ Oh, you're just using that to mean "a solution for n1 in terms of ...", right? $\endgroup$ Commented Nov 28, 2024 at 19:04
  • $\begingroup$ Thank you. I have modified my question a little bit. Will your answer hold true in this case as well? $\endgroup$ Commented Nov 28, 2024 at 19:05
  • $\begingroup$ @Nasser Thank you. I have modified my question a little bit. Will your answer hold true in this case as well? $\endgroup$ Commented Nov 28, 2024 at 19:08

1 Answer 1

2
$\begingroup$

This seems to work

eq = Delta^2 == 2*M^2*(n2^2 + 1/2*(n1^2 - 2*n1*n2^2*n3^2*Cos[fi] + n2^4*n3^4 + n3^4) + n2*Sqrt[n2^2 + 2*n1*n3^2*Cos[fi] - 2*n2^2*n3^4]); sol = First@Solve[eq, n1]; n1[Delta_, n2_, M_, n3_, fi_] = n1 /. sol; 

And now you can use your function n1

n1[1,2,3,4,5]//N (*16.7734 + 63.7064 I*) n1[1, 99, 3, 0, Pi] // N (*-6.7435*10^-7 - 140.007 I*) 

etc..

ps. It might be better/safer to name the function something other than n1.

May be n1F, so the above becomes

 n1F[Delta_, n2_, M_, n3_, fi_] = n1 /. sol; 

And now use n1F as the function instead of n1

This equation is a 4th order equation with respect to n1 and has four solutions. You provided one solution. How can I find the rest?

I used First to pick the first solution. If you want to make function for each solution, you could do

eq = Delta^2 == 2*M^2*(n2^2 + 1/2*(n1^2 - 2*n1*n2^2*n3^2*Cos[fi] + n2^4*n3^4 + n3^4) + n2*Sqrt[n2^2 + 2*n1*n3^2*Cos[fi] - 2*n2^2*n3^4]); sol = Solve[eq, n1]; Dimensions[sol] (*{4,1}*) 

So there are 4 solutions. You can now write

n1F[Delta_, n2_, M_, n3_, fi_] = n1 /. sol[[1]]; n2F[Delta_, n2_, M_, n3_, fi_] = n1 /. sol[[2]]; n3F[Delta_, n2_, M_, n3_, fi_] = n1 /. sol[[3]]; n4F[Delta_, n2_, M_, n3_, fi_] = n1 /. sol[[4]]; 

And now use each function to represent each solution

enter image description here

Reference: How do I make a function from a solution?

$\endgroup$
4
  • $\begingroup$ Thank you. It certainly seems to be working. I just need to check this out myself. Thanks. $\endgroup$ Commented Nov 28, 2024 at 19:34
  • $\begingroup$ your code works perfectly well. One more question: This equation is a 4th order equation with respect to n1 and has four solutions. You provided one solution. How can I find the rest? $\endgroup$ Commented Nov 28, 2024 at 20:05
  • 1
    $\begingroup$ @neutrino updated for all 4 solutions $\endgroup$ Commented Nov 28, 2024 at 20:28
  • $\begingroup$ This is exactly what I need. Thank you! $\endgroup$ Commented Nov 28, 2024 at 21:10

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.