Solving an Integral equation with uncertainties

In summary, you are trying to solve an integral that contains an unknown variable with corresponding uncertainty. You have done research and attempted to solve the problem using the `quad` function, but it is not compatible with uncertainties. Instead, you could try using the `ufloat` and `umath` functions from the `uncertainties` package, and the `fsolve` function from the `scipy.optimize` package. Good luck!
  • #1
Arman777
Insights Author
Gold Member
2,168
193
TL;DR Summary
Solving an Integral equation with uncertainties, by using fsolve and uncertainties packages in Python
I have some variables that are uncertain, these are

Python:
w_m = u.ufloat(0.1430, 0.0011)
z_rec = u.ufloat(1089.92, 0.25)
theta_srec = u.ufloat(0.0104110,  0.0000031)
r_srec = u.ufloat(144.43, 0.26)

and some constant values

Python:
c = 299792.458  # speed of light in [km/s]
N_eff = 3.046
w_r = 2.469 * 10**(-5) * (1 + (7/8)*(4/11)**(4/3) * N_eff)

My problem is I need to solve an integral defined by this functions

Python:
def D_zrec(z):
            return (c/100) / sqrt(w_m * (1+z)**3 + w_r * (1+z)**4 + (h**2 - w_m - w_r))

This function is evaluated for ##dz## but it also contains an unknown ##h## that we need to find, with corresponding uncertainty. So I need to write a code that solves h.

Here is my full code

Python:
from numpy import sqrt, vectorize
    from scipy.integrate import quad
    import uncertainties as u
    from uncertainties.umath import *
    from scipy.optimize import fsolve

    ####  Important Parameters #####
    c = 299792.458  # speed of light in [km/s]
    N_eff = 3.046
    w_r = 2.469 * 10**(-5) * (1 + (7/8)*(4/11)**(4/3) * N_eff)
    w_m = u.ufloat(0.1430, 0.0011)
    z_rec = u.ufloat(1089.92, 0.25)
    theta_srec = u.ufloat(0.0104110,  0.0000031)
    r_srec = u.ufloat(144.43, 0.26)

    D_zrec_true = r_srec / theta_srec

    @u.wrap
    def D_zrec_finder(h, w_m, z_rec):
        def D_zrec(z):
            return (c/100) / sqrt(w_m * (1+z)**3 + w_r * (1+z)**4 + (h**2 - w_m - w_r))
        D_zrec_test, error = quad(D_zrec, 0, z_rec)
        return D_zrec_true - D_zrec_test    def h0_finder(w_m, z_rec):
        sol = fsolve(D_zrec_finder, 0.67, args=(w_m, z_rec))[0]
        return sol

    print(h0_finder(w_m, z_rec))

So to summarize I have an integral named as D_zrec` that is a function of ` ##z## but also contains an unknown number `## h## that we need to find by using fsolve.

I have found 3 sites that might be useful for the coder. Please look at them if you want to help

https://kitchingroup.cheme.cmu.edu/blog/2013/03/07/Another-approach-to-error-propagation/

https://kitchingroup.cheme.cmu.edu/blog/2013/07/10/Uncertainty-in-an-integral-equation/

https://kitchingroup.cheme.cmu.edu/blog/2013/01/23/Solving-integral-equations-with-fsolve/

I have looked at them to write my code but no luck.

Thanks for the help
 
Technology news on Phys.org
  • #2
!

Hi there,

Thank you for sharing your problem and code. It seems like you have already done a lot of research and have a good understanding of the problem you are trying to solve. However, I have a few suggestions that may help you find a solution.

First, it may be helpful to break down your problem into smaller parts. For example, you could first try to solve the integral without the uncertainty in h, and then add in the uncertainty later. This will help you understand the code and make it easier to troubleshoot any errors.

Second, I noticed that you are using the `quad` function from `scipy.integrate` to solve the integral. However, this function is not compatible with uncertainties. Instead, you could try using the `uncertainties` package's `ufloat` and `umath` functions to handle the uncertainties in your calculations. You can also use the `vectorize` function to make your function compatible with the uncertainties package.

Finally, I would suggest trying to solve the integral using a different method, such as the `scipy.optimize` package's `fsolve` function. This function allows you to solve for a root of a function, which may be more appropriate for your problem.

I hope these suggestions are helpful. Good luck with your code!
 

FAQ: Solving an Integral equation with uncertainties

How do you define an integral equation with uncertainties?

An integral equation with uncertainties is a mathematical equation that involves an unknown function within an integral, and also includes uncertainties or errors in the equation's parameters or variables. This type of equation is commonly used in scientific and engineering fields to model real-world systems.

What methods can be used to solve an integral equation with uncertainties?

There are several methods that can be used to solve integral equations with uncertainties, including numerical methods such as Monte Carlo simulation, Gaussian quadrature, and numerical integration techniques. Analytical methods, such as Laplace transforms and perturbation theory, can also be used in certain cases.

How do uncertainties affect the solution of an integral equation?

Uncertainties in the parameters or variables of an integral equation can affect the accuracy and reliability of the solution. They can also introduce additional sources of error and make the solution more complex to obtain. Therefore, it is important to consider uncertainties carefully when solving integral equations in order to obtain reliable results.

Can uncertainties be incorporated into the integral equation itself?

Yes, uncertainties can be incorporated into the integral equation itself by using probabilistic approaches or by adding an uncertainty term to the equation. This allows for a more accurate and realistic representation of the underlying system and can help to improve the accuracy of the solution.

Are there any limitations to solving integral equations with uncertainties?

Yes, there are limitations to solving integral equations with uncertainties. These include the availability of reliable data for the uncertain parameters, the complexity of the equation and its solution, and the computational resources required. Additionally, some methods may not be suitable for certain types of uncertainties and may require additional assumptions or simplifications.

Similar threads

2
Replies
50
Views
5K
Replies
8
Views
35K
Replies
10
Views
10K
Replies
1
Views
1K
Replies
7
Views
2K
Back
Top