Why Is My Solve Function Not Working in Mathematica?

  • Thread starter 215
  • Start date
  • Tags
    Function
In summary, the conversation discusses using the Solve function in Mathematica to solve for multiple constants in a user-defined function. However, due to the complexity of the function, it is difficult to obtain a solution and alternative methods such as nsolve and findroot may be necessary. Additionally, the proper format for using the Solve function is important, as it requires a list of expressions and variables.
  • #1
215
39
0
I am trying to solve a function using Solve in mathmatica.
I am solving for multiple constants.

Can i use a solve on a function i have made in Mathmatica... I mean
a function like this
L2[n_, q_] :=
Total[(Range[0, IntegerPart[n/((4.1/100)/q)]]*q + 0.0038)*\[Pi]*(4.1/
100)/q] + (((IntegerPart[n/((4.1/100)/q)] + 1)*q) +
0.0038)*\[Pi]*(n - IntegerPart[n/((4.1/100)/q)]*(4.1/100)/q)

And use the solve function like this

Solve[30 == 0.0175*10^-6*L2[n, q]/((q/2)^2*\[Pi]) &&
L2[n, q] == 29.918420573509337`, {L, n}]

Or how should i use it?
 
Physics news on Phys.org
  • #2
You're really asking something that's too hard here. A function with a summation in it with a variable number of terms. You could try nsolve, but the only thing Mathematica could do with a discontinuous function is trying random values.

I would substitute r = n/((4.1/100)/q and then try solve for
0<=k < 1, 1 <=k <2, 2 <= k <3, ...
 
  • #3
But is it posible to solve function with solve..

I mean like
L[n_,q_,E_]:= ...n...q...E
Solve[L[n_,q_,E_]==5444,{n,q,E}]
 
  • #4
215 said:
But is it posible to solve function with solve..

I mean like
L[n_,q_,E_]:= ...n...q...E
Solve[L[n_,q_,E_]==5444,{n,q,E}]

The problem is not the user defined function, but the summation with a variable number of terms. Nsolve won't work either, the only thing that might work is findroot, but you'll have to give a good enough initial quess for n and q.
 
  • #5
Hmm... ok why isn't this one working then..
http://snag.gy/j41zD.jpg

The bold letters is constant..
 
  • #6
215 said:
Hmm... ok why isn't this one working then..

Probably because you have a mixture of && and ,

In[1]:= Solve[0.5 == v/R && B == \[Mu]0*v/R*n/(lj/\[Mu]j + 2*x) && 2*B^2/(2 \[Mu]0*a*(4*x/(lj/\[Mu]j + 2 x) - 1)) == 2 && R == 0.0175*10^-6*L/((g/2)^2*Pi), {L, B, v, q, n, R}]

During evaluation of In[1]:= Solve::ratnz: Solve was unable to solve the system with inexact coefficients. The answer was obtained by solving a corresponding exact system and numericizing the result. >>

During evaluation of In[1]:= Solve::svars: Equations may not give solutions for all "solve" variables. >>

Out[1]= {{L -> 4.4879895051282756*^7*g^2*R, B -> (-1.4142135623730951*Sqrt[-1.* a*lj*\[Mu]0 + 2.*a*x*\[Mu]0*\[Mu]j])/Sqrt[lj + 2.*x*\[Mu]j], v -> 0.5*R, n -> (2.*((-1.4142135623730951*lj* Sqrt[-1.*a*\[Mu]0*(lj - 2.*x*\[Mu]j)])/Sqrt[lj + 2.*x*\[Mu]j] - (2.8284271247461903*x*\[Mu]j* Sqrt[-1.*a*\[Mu]0*(lj - 2.*x*\[Mu]j)])/Sqrt[lj + 2.*x*\[Mu]j]))/(\[Mu]0*\[Mu]j)},
{L -> 4.4879895051282756*^7*g^2*R, B -> (1.4142135623730951*Sqrt[-1.* a*lj*\[Mu]0 + 2.*a*x*\[Mu]0*\[Mu]j])/Sqrt[lj + 2.*x*\[Mu]j], v -> 0.5*R, n -> (2.*((1.4142135623730951*lj*Sqrt[-1.* a*\[Mu]0*(lj - 2.*x*\[Mu]j)])/Sqrt[lj + 2.*x*\[Mu]j] + (2.8284271247461903*x*\[Mu]j*Sqrt[-1.* a*\[Mu]0*(lj - 2.*x*\[Mu]j)])/Sqrt[lj + 2.*x*\[Mu]j]))/(\[Mu]0*\[Mu]j)}}

In[2]:= Reduce[0.5 == v/R && B == \[Mu]0*v/R*n/(lj/\[Mu]j + 2*x) && 2*B^2/(2 \[Mu]0*a*(4*x/(lj/\[Mu]j + 2 x) - 1)) == 2 && R == 0.0175*10^-6*L/((g/2)^2*Pi), {L, B, v, q, n, R}]

During evaluation of In[2]:= Reduce::ratnz: Reduce was unable to solve the system with inexact coefficients. The answer was obtained by solving a corresponding exact system and numericizing the result. >>

Out[2]= (x == 0 && (B == (0. - 1.4142135623730951*I)* Sqrt[a]*Sqrt[\[Mu]0] || B == (0. + 1.4142135623730951*I)* Sqrt[a]*Sqrt[\[Mu]0]) && g != 0 && v == (1.1140846016432675*^-8*L)/g^2 && B*\[Mu]j != 0 && n == (-4.*a*lj)/(B*\[Mu]j) && R == 2.*v && L*lj != 0) || (lj + 2.*x*\[Mu]j != 0 && (B == (-1.4142135623730951* Sqrt[-1.*a*lj*\[Mu]0 + 2.*a*x*\[Mu]0*\[Mu]j])/Sqrt[lj + 2.*x*\[Mu]j] || B == (1.4142135623730951* Sqrt[-1.*a*lj*\[Mu]0 + 2.*a*x*\[Mu]0*\[Mu]j])/Sqrt[lj + 2.*x*\[Mu]j]) && g != 0 && v == (1.1140846016432675*^-8* L)/g^2 && B^2 + 2.*a*\[Mu]0 != 0 && n == (16.*a*B*x)/(B^2 + 2.*a*\[Mu]0) && R == 2.*v && L*lj - 2.*L*x*\[Mu]j != 0)
 
  • #7
&& is just And, it should give a problem?
 
  • #8
215 said:
&& is just And, it should give a problem?

From your picture
Solve[expression&&expression,expression,{variablelist}]
which is not
Solve[expression&&expression&&expression,{variablelist}]
and is not
Solve[{expression,expression,expression},{variablelist}]

Read the Mathematica documentation carefully.
Mathematica does not have a "figure out what my problem actually is and what I should have asked and do that for me instead of what I actually wrote" button.

WolframAlpha.com will accept an undocumented sort of more english description of what the problem is and try to figure out what you meant and try to come up with some answer.
 

FAQ: Why Is My Solve Function Not Working in Mathematica?

Why is my solve function not working?

The most common reason for a solve function not working is that there may be a syntax error or incorrect input in the function. Make sure to check the syntax and input before troubleshooting further.

What can cause a solve function to stop working?

There are a few potential reasons for a solve function to stop working. These include changes in the underlying code or programming language, incorrect function usage, or issues with the input data. It's important to carefully examine and test each potential cause to find the root of the problem.

How can I fix my solve function if it's not working?

First, double check the syntax and input of your function to ensure they are correct. If those are not the issue, try stepping through the function with a debugger to identify where the problem is occurring. You may also want to consult documentation or ask for help from other programmers.

What is the best way to troubleshoot a solve function that isn't working?

One of the best ways to troubleshoot a solve function is to use a debugger or step through the code line by line to see where the function is breaking. It can also be helpful to consult documentation or ask for help from other programmers who may have experience with similar issues.

How can I prevent my solve function from not working in the future?

To prevent future issues with your solve function, it's important to write clear and concise code and to thoroughly test your function before using it in a production setting. Additionally, staying up to date on any changes in the programming language or library you are using can help prevent unexpected issues with your function.

Similar threads

Replies
5
Views
2K
Replies
2
Views
2K
Replies
2
Views
1K
Replies
1
Views
1K
Replies
2
Views
702
Replies
1
Views
2K
Replies
2
Views
473
Back
Top