Mathematica: Problems with integrating and plotting a function

In summary, to integrate the given function, define a function that includes the integral and use Mathematica's numerical integration functions to evaluate it for varying values of the parameters.
  • #1
Bkkkk
12
0
Hey, I have been trying to make Mathematica integrate the following function:

[tex]r_{e}=\frac{c}{H_{0}}\int_{0}^{z}\frac{dz}{\left[\Omega_{NR}(1+z)^{3}+\Omega_n(1+z)^{3-n}+\Omega_{\Lambda}\right]^{\frac{1}{2}}}[/tex]

There are two cases for which this equation needs to be integrated, seperately;

(i) When [tex]\Omega_{\Lambda}=0[/tex]
(ii) [tex]\Omega_n=0 [/tex]

n is real, so is z and the sum of the density parameters is unity, thus if we take case (ii) [tex]\Omega_{\Lambda} = 1 - \Omega_{NR}[/tex]

However Mathematica outputs the formatted version of the input line. Next I thought I would just define a function which includes the above integral, and then plot it for varying values of [tex]\Omega_{NR}[/tex] and n, however the problem is that often times the Kernel crashes or the curves plotted have gaps in them and/or end unexpectedly.

I would of course prefer to have the integrated function as I presume it would save on plotting time as I need make plots for various values of n for case (i).

Thanks
 
Last edited:
Physics news on Phys.org
  • #2
for any help!The easiest way to do this would be to define a function that includes the integral, then use Mathematica's built-in numerical integration functions to evaluate the integral. For example, you could define the following function:f[z_, ωNR_, n_] := c/H0 * NIntegrate[1/((ωNR (1+z)^3 + (1 - ωNR) (1+z)^(3 - n))^(1/2)), {z, 0, z}]You can then plot the function for varying values of ωNR and n using the Plot command, e.g.:Plot[f[z, ωNR, n], {ωNR, 0, 1}, {n, 0, 3}]If you need more precise results, you can use Mathematica's built-in numerical integration functions such as NIntegrate, which will allow you to get greater accuracy in the results.
 
  • #3
for reaching out about this issue with Mathematica. Integrating and plotting functions can sometimes be tricky, especially when dealing with complex equations like the one you have provided.

First, let's address the issue with the formatted output of the input line. This could be caused by a few different things, such as a syntax error or incorrect use of Mathematica's functions. I would suggest double checking your input and making sure it follows the correct syntax for integrating and plotting functions in Mathematica. You may also find it helpful to consult Mathematica's documentation or online resources for guidance on how to properly input and format equations.

As for the crashes and gaps in the plotted curves, this could be due to the complexity of the function and the values you are using for \Omega_{NR} and n. It is possible that the function is taking a long time to integrate or that there are some numerical instabilities that are causing the crashes. In this case, it may be helpful to try using different values for \Omega_{NR} and n and see if that improves the plotting process. You could also try using Mathematica's built-in functions for numerical integration, such as NIntegrate, to see if that yields better results.

Alternatively, you could define the function and plot it for specific values of \Omega_{NR} and n, rather than trying to plot it for varying values. This may save on plotting time and help avoid any potential crashes.

I hope this helps and good luck with your research!
 

1. Why am I getting an error when trying to integrate a function in Mathematica?

The most common reason for an error when integrating a function in Mathematica is that the function is not defined properly. Make sure to use the correct syntax and that all necessary variables are included in the function.

2. How can I plot a complex function in Mathematica?

To plot a complex function in Mathematica, you can use the ComplexPlot function. This will create a plot in the complex plane, with the real and imaginary parts shown as different colors. You can also use the Abs function to plot the magnitude of the function.

3. What should I do if my plot is not showing up in Mathematica?

If your plot is not showing up in Mathematica, there could be a few reasons. First, make sure that you have included all necessary variables in your function. Also, check that the domain of your function is within the range of the plot. If the problem persists, try restarting Mathematica or updating your software.

4. How can I change the color or style of my plot in Mathematica?

To change the color or style of your plot in Mathematica, you can use the PlotStyle option in the Plot function. This allows you to specify the color, thickness, and other visual properties of your plot. You can also use the ColorFunction option to create a color gradient based on the values of your function.

5. Is it possible to integrate a function with multiple variables in Mathematica?

Yes, it is possible to integrate a function with multiple variables in Mathematica using the Integrate function. You can specify the variables and their limits of integration in the function. However, keep in mind that the integration may take longer and may require more advanced techniques if the function is complex.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
261
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
221
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
Back
Top