Solving Loop in Mathematica for (u,i) Pairs

  • Thread starter Thread starter Juliane
  • Start date Start date
  • Tags Tags
    Loop Mathematica
AI Thread Summary
The discussion focuses on solving a numerical integration problem in Mathematica to find pairs (u, i) that yield a specific value. The original program stops execution once it finds a valid pair, leading to a request for assistance on how to continue searching through all values of u. A suggestion is made to use a Table expression to iterate over u while maintaining the existing logic for i. The proposed solution successfully allows the program to evaluate all desired pairs. The conversation concludes with a recommendation to post such queries in a more appropriate forum section for better assistance.
Juliane
Messages
8
Reaction score
0
Hi, can anyone help me?

I have the following expression:

NIntegrate[
Exp[-((2 t^2 u^2)/i^4)] t^2 BesselI[0, t/
i^4] (BesselI[-1, t/i^4] + BesselI[1, t/i^4]), {t, 0,
1}]/(2 NIntegrate[
Exp[-((2 t^2 u^2)/i^4)] + BesselI[0, t/i^4]^2, {t, 0, 1}])

For (u,i)=(0,4) it gives 0.000244141. What I won't is to find the pairs (u,i) which also give this value.
Because of the Besselfunktions it must be done numerically.

I have written the following program in mathematica:

Catch[Do[If[
NIntegrate[
Exp[-((2 t^2 u^2)/i^4)] t^2 BesselI[0, t/
i^4] (BesselI[-1, t/i^4] + BesselI[1, t/i^4]), {t, 0, 1}]/(
2 NIntegrate[
Exp[-((2 t^2 u^2)/i^4)] + BesselI[0, t/i^4]^2, {t, 0, 1}]) <
0.000244141, Throw[{u, i}]], {u, 0, 4}, {i, 3, 4, 0.001}]]

But it stops as soon as it finds values for (u,i) which fullfills the inequality. How do I make the program go on for u=2,3, 4...?

I think that maybe I can use Table to make this work, but I don´t know how to do it.
Please help me
Juliane
 
Physics news on Phys.org
If this is anything like Matlab then you need to use a for loop. An if statement will terminate as soon as the if condition is satisfied, whereas a for loop will continue to evaluate until told to stop by the user.

Try searching through the Mathematica help browser to see if you can do a for statement (it will have something like a for loop, though it may under a different name).
 
Juliane said:
I have written the following program in mathematica:

Catch[Do[If[
NIntegrate[
Exp[-((2 t^2 u^2)/i^4)] t^2 BesselI[0, t/
i^4] (BesselI[-1, t/i^4] + BesselI[1, t/i^4]), {t, 0, 1}]/(
2 NIntegrate[
Exp[-((2 t^2 u^2)/i^4)] + BesselI[0, t/i^4]^2, {t, 0, 1}]) <
0.000244141, Throw[{u, i}]], {u, 0, 4}, {i, 3, 4, 0.001}]]

But it stops as soon as it finds values for (u,i) which fullfills the inequality. How do I make the program go on for u=2,3, 4...?

I think that maybe I can use Table to make this work, but I don´t know how to do it.
Please help me
Juliane

If you want to keep that form of your program, you can wrap it in a Table expression like this:

Code:
Table[
Catch[Do[If[
   NIntegrate[
     Exp[-((2 t^2 u^2)/i^4)] t^2 BesselI[0, t/
       i^4] (BesselI[-1, t/i^4] + BesselI[1, t/i^4]), {t, 0, 1}]/(
    2 NIntegrate[
      Exp[-((2 t^2 u^2)/i^4)] + BesselI[0, t/i^4]^2, {t, 0, 1}]) < 
    0.000244141, Throw[{u, i}]], {i, 3, 4, 0.001}]]  ,{u,1,4}]

and it will find values for u=1,2,3,4.
 
Thank you so much, now it works.
 
Juliane said:
Thank you so much, now it works.

You're welcome! By the way, there is a better place here to post questions about mathematica. From the front page, choose the "computer science" forum, and then choose the "math & science software" subforum.

Or follow this link:

https://www.physicsforums.com/forumdisplay.php?f=189
 
Oh, okay thanks
 
Kindly see the attached pdf. My attempt to solve it, is in it. I'm wondering if my solution is right. My idea is this: At any point of time, the ball may be assumed to be at an incline which is at an angle of θ(kindly see both the pics in the pdf file). The value of θ will continuously change and so will the value of friction. I'm not able to figure out, why my solution is wrong, if it is wrong .
TL;DR Summary: I came across this question from a Sri Lankan A-level textbook. Question - An ice cube with a length of 10 cm is immersed in water at 0 °C. An observer observes the ice cube from the water, and it seems to be 7.75 cm long. If the refractive index of water is 4/3, find the height of the ice cube immersed in the water. I could not understand how the apparent height of the ice cube in the water depends on the height of the ice cube immersed in the water. Does anyone have an...
Back
Top