Solving Loop in Mathematica for (u,i) Pairs

In summary, a loop in Mathematica is a programming structure used for repeating instructions multiple times. To create a loop, the <code>Do</code> or <code>For</code> function can be used. To solve for (u,i) pairs, the <code>Solve</code> function can be used, and loops can also be used to solve for (u,i) pairs by iterating through different values of variables. Loops can be used for more complex problems in Mathematica, making them a useful tool for mathematical and scientific problem-solving, as well as data analysis and manipulation.
  • #1
Juliane
8
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
  • #2
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).
 
  • #3
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.
 
  • #4
Thank you so much, now it works.
 
  • #5
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
 
  • #6
Oh, okay thanks
 

Question 1: What is a loop in Mathematica?

A loop in Mathematica is a programming structure that allows you to repeat a set of instructions multiple times. It is a useful tool for solving problems that require repetitive calculations.

Question 2: How do I create a loop in Mathematica?

To create a loop in Mathematica, you can use the Do or For function. These functions allow you to specify the number of iterations and the instructions to be repeated.

Question 3: How do I solve for (u,i) pairs in Mathematica?

To solve for (u,i) pairs in Mathematica, you can use the Solve function. This function allows you to specify the equations and variables to solve for, and it will return a list of solutions.

Question 4: How do I use loops to solve for (u,i) pairs in Mathematica?

To use loops to solve for (u,i) pairs in Mathematica, you can first define the equations and variables, and then use a loop to iterate through different values of the variables. Within the loop, you can use the Solve function to find the corresponding values of (u,i).

Question 5: Can loops be used for more complex problems in Mathematica?

Yes, loops can be used for more complex problems in Mathematica. They are a powerful tool for solving a variety of mathematical and scientific problems, as well as for data analysis and manipulation.

Similar threads

  • Introductory Physics Homework Help
Replies
19
Views
665
  • Introductory Physics Homework Help
3
Replies
88
Views
4K
  • Introductory Physics Homework Help
Replies
2
Views
227
  • Introductory Physics Homework Help
Replies
2
Views
803
  • Introductory Physics Homework Help
Replies
6
Views
785
  • Introductory Physics Homework Help
Replies
2
Views
240
  • Introductory Physics Homework Help
Replies
2
Views
456
  • Introductory Physics Homework Help
Replies
12
Views
187
  • Introductory Physics Homework Help
Replies
7
Views
1K
  • Introductory Physics Homework Help
Replies
4
Views
997
Back
Top