Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Problem with part of c program

  1. Nov 24, 2008 #1
    I have a problem with c program calculation part . i have a mathematic funxion which equals to y. And i need to calculate the value. While x has a conditon thats value will increase 15 times. Like x1=a ; x2=a+h x3=a+h+(c*h) ; x4=a+h+(c*h)+((c*c)*h) ; x5=a+h+(c*h)+((c*c)*h)+((c*c*c)*h) and so on to X15. x1 which = A ,c,h and Ymin value is inserted by the program user. I Have come to conclusion , that i can write a formula for x value increase , which is Xi=Xi-1 +(c^i-2 * H) and it goes from x2 to x15 .
    My problem is that how i can write this to c language , what line i should write that the program would calculate x1 by just adding to the y= formula and from x2 to x15 it would use the condition that Xi=Xi-1 +(c^i-2 * H).
    And please dont give me just advice with this , i would just like to know how should i mark this in C language.
  2. jcsd
  3. Nov 24, 2008 #2


    User Avatar

    Staff: Mentor

    Moved to Homework Help forums.

    sulev8, we do not give out answers to homework questions. Show us your attempt at the program first, and then we can offer tutorial help.
  4. Nov 24, 2008 #3
    i dont want u to solve the whole program , this is just the part of a program , i am asking how i should write these lines into my program .Its the calculation part of the program , and i need some help with it. As i wrote i gave out the solution , now i need help how to put it down , just these few lines.
    As i see it was another useless attempt to seek help from here , its like a basic answer in this forum.

    // calculation part
    void calculation (float xva[15], float yva[15])
    int i;
    while (i<15)
    if (xva!=0)
    /* if x aint 0 , calculate value*/

    this is what i have made , but i dont get if the program takes into count that x1 stays same as A and that it ( xva=xva[i-1]+(pow(c,i-2)*h);) should start from x2 to x15
  5. Nov 24, 2008 #4
    why cant u just comment my work ,and help me by giving me how it should be , and tell whats missing
  6. Nov 24, 2008 #5


    User Avatar
    Science Advisor
    Homework Helper

    What are c and h - where are the defined, initialised ?
    You can't call this with i<2, you start at i=0;
    Last edited: Nov 24, 2008
  7. Nov 24, 2008 #6
    Well, one thing can cause you trouble:


    You check for zero, but since xva is a float, it still can be a very small number (not zero) and blow up on you. Keep in mind that while a human would know that .000000000001 is basically zero, to a computer it is not.

    you also don't want to initialize i to zero. Otherwise, the i-2 factor will end up at -2. You want to initialize it to 2.

    Finally, use a for statement instead of a while: Like for(i=2;i < 15;i++)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook