Mathematica: Printing Numeric Result

In summary, the conversation discusses the use of Mathematica to evaluate a complex integral and how to force it to output a numerical result. The speaker shares their attempts at breaking up the calculation to make it faster and asks for help in providing a numeric value for a variable. A potential solution using NIntegrate is also presented.
  • #1
Joel_662
1
0
Hey,

So I am fairly new to Mathematica (and the physics forums too). I am having a problem with mathematica not calculating the numeric result to an very complex integral. My question is, how do I force it to evaluate the integral as a number? I'm assuming that the integral of a square root is possible in mathematica as i checked the help files and it seems to suggest it is. I have tried the evaluation both with and without using n[A] which seems to be the suggested method of forcing a numeric evaluation.

K=1
R=1
VM=1
L=1
radius=1
z=-0.000000*x^6 - 0.000000*x^5 + 0.000049*x^4 + 0.000115*x^3 - 0.018528*x^2 - 0.033042*x + 2.964166
dzdx=D[z,x]
absdzdx=Abs[dzdx]
sqrtfactor=Sqrt[1+dzdx^2]
A=2*Pi*K*R*VM*L*(Integrate[(6.5+4.56*(absdzdx)+0.654*(absdzdx)^2)*x*sqrtfactor,{x,0,r}])*((2*Pi*\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(0\), \(r\)]\(\((x*sqrtfactor)\) \[DifferentialD]x\)\))/10000)


I have tried to break up the calculations so that mathematica doesn't take to long to calculate it but it still seems to take at least 3 or 4 mins of running before it displays an answer. The variables do unfortunately need to stay separate as they will be changed. I apologise in advance if it is just some stupid error of mine.
 
Physics news on Phys.org
  • #2
If you can supply a numeric value for r, perhaps like this

r = 1;

then this

In[1]:= A=2*Pi*K*R*VM*L* NIntegrate[((6.5+4.56*absdzdx+0.654*absdzdx^2)* x*sqrtfactor),{x,0,r}]*
2*Pi/10000*NIntegrate[x*sqrtfactor,{x,0,r}]]

Out[1]= 0.00669876

evaluates in a fraction of a second.

If you cannot provide a numeric value for r then I doubt you will get a satisfactory answer.
 
Last edited:

1. How do I print a numeric result in Mathematica?

To print a numeric result in Mathematica, you can use the Print function followed by the expression or value you want to print. For example, Print[2+2] will print the result 4.

2. Can I format the printed result in Mathematica?

Yes, you can format the printed result in Mathematica using the NumberForm function. This function allows you to specify the number of digits, decimal places, and other formatting options for the result. For example, Print[NumberForm[2/3, {4, 2}]] will print 0.67 with 4 digits and 2 decimal places.

3. How can I save the printed result to a file in Mathematica?

You can save the printed result to a file in Mathematica using the Export function. This function takes in the result or expression you want to print, the file path, and the file format as parameters. For example, Export["result.txt", 2+2, "Text"] will save the result 4 to a text file called "result.txt".

4. Is it possible to print multiple results in Mathematica?

Yes, you can print multiple results in Mathematica by using the Print function multiple times, separating each expression with a comma. Alternatively, you can use the Table function to generate a list of results and then use Print to print the entire list at once.

5. Can I change the output format of the printed result in Mathematica?

Yes, you can change the output format of the printed result in Mathematica by using the Format function. This function allows you to specify the format for different types of expressions, such as integers, floats, and fractions. You can also use the FormatType option to specify the output format, such as TraditionalForm or StandardForm.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
221
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top