Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6921409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:16:23+00:00 2026-05-27T10:16:23+00:00

for (int i= 0; i<10; i++) { phi0 = phi0 * (L / L0);

  • 0
for (int i= 0; i<10; i++)
{
    phi0 = phi0 * (L / L0);
    X0 = R * Math.Sin(2 * phi0) * Math.Cos(phi0);
    L0 = X0 * (1 + (Math.Pow(Math.Tan(phi0), 2)) / 10 - (Math.Pow(Math.Tan(phi0), 4)) / 72 + (Math.Pow(Math.Tan(phi0), 6)) / 208);
    if ((Math.Abs(L0 - L)) < (0.003 * Math.Sqrt(L)))
        break;
}

Usually after 2,3 iterations the condition is met, but I need a message to show the number of iterations after which the condition is met and also if its exceeds the total amount of 10.

If there is something to explain fell free to ask.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:16:24+00:00Added an answer on May 27, 2026 at 10:16 am

    Move the declaration of i outside the loop and you can use it’s value afterwards. Remember that the value of i will be one less than the number of iterations used since you’re starting at 0 — in fact since you don’t use i in any of the expressions in the loop, you may want it to from from 1 to 10 instead of 0 to 9.

    Note you can also make a small optimization to make things faster. The compiler might do it for you, but you can make sure by storing the intermediate calculation of tan(phi0) in a local varaiable.

    int i = 1;
    for (; i<=10; i++)
    {
        phi0 = phi0 * (L / L0);
        var tanPhi0 = Math.Tan(phi0);
        X0 = R * Math.Sin(2 * phi0) * Math.Cos(phi0);
        L0 = X0 * (1 + (Math.Pow(tanPhi0, 2)) / 10 - (Math.Pow(tanPhi0, 4)) / 72 + (Math.Pow(tanPhi0, 6)) / 208);
        if ((Math.Abs(L0 - L)) < (0.003 * Math.Sqrt(L)))
            break;
    }
    
    if (i <= 10)
    {
        Console.WriteLine( "The loop took {0} iterations", i );
    }
    else
    {
        Console.WriteLine( "It did not converge" );
    }
    

    In fact, if this gets executed many times, you may want to carry it one step further and try computing the powers of tan(phi0) in stages as well instead of calling Pow each time. I’m making the assumption here that multiplication is faster than calling the Pow method, which seems reasonable, but you’ll want to test it to make sure. There’s also no reason to compute the error bound each time.

    var epsilon = 0.003 * Math.Sqrt(L);
    int i = 1;
    for (; i<=10; i++)
    {
        phi0 = phi0 * (L / L0);
        var tanPhi0 = Math.Tan(phi0);
        var tanPhi0_2 = tanPhi0 * tanPhi0;
        var tanPhi0_4 = tanPhi0_2 * tanPhi0_2;
        var tanPhi0_6 = tanPhi0_4 * tanPhi0_2;
        X0 = R * Math.Sin(2 * phi0) * Math.Cos(phi0);
        L0 = X0 * (1 + tanPhi0_2 / 10 - tanPhi0_4 / 72 + tanPhi0_6 / 208);
        if ((Math.Abs(L0 - L)) < epsilon)
            break;
    }
    
    if (i <= 10)
    {
        Console.WriteLine( "The loop took {0} iterations", i );
    }
    else
    {
        Console.WriteLine( "It did not converge" );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

int X = a-b; int d = Math.Abs(X); I am pretty sure that .NET
int main(){ char ch; fork(); cin >> c; } After calling fork() I should
Int(11) is 4 bytes, correct? Decimal(5,0) - 5 before decimal and 0 after decimal...
int x = n / 3; // <-- make this faster // for instance
int x; printf(hello %n World\n, &x); printf(%d\n, x);
int[] mylist = { 2, 4, 5 }; IEnumerable<int> list1 = mylist; list1.ToList().Add(1); //
int n = 5; for(int i = 0;i!=n;i++)//condition != { //executing 5times } int
int main(void) { char tmp, arr[100]; int i, k; printf(Enter a string: ); scanf_s(%s,
int somefunction(bool a) { try { if(a) throw Error(msg); return 2; } catch (Error
int main() { int var = 0;; // Typo which compiles just fine }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.