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
 
Thread 'Variable mass system : water sprayed into a moving container'
Starting with the mass considerations #m(t)# is mass of water #M_{c}# mass of container and #M(t)# mass of total system $$M(t) = M_{C} + m(t)$$ $$\Rightarrow \frac{dM(t)}{dt} = \frac{dm(t)}{dt}$$ $$P_i = Mv + u \, dm$$ $$P_f = (M + dm)(v + dv)$$ $$\Delta P = M \, dv + (v - u) \, dm$$ $$F = \frac{dP}{dt} = M \frac{dv}{dt} + (v - u) \frac{dm}{dt}$$ $$F = u \frac{dm}{dt} = \rho A u^2$$ from conservation of momentum , the cannon recoils with the same force which it applies. $$\quad \frac{dm}{dt}...
I was thinking using 2 purple mattress samples, and taping them together, I do want other ideas though, the main guidelines are; Must have a volume LESS than 1600 cubic centimeters, and CAN'T exceed 25 cm in ANY direction. Must be LESS than 1 kg. NO parachutes. NO glue or Tape can touch the egg. MUST be able to take egg out in less than 1 minute. Grade A large eggs will be used.
Back
Top