# Homework Help: Problem with part of c program

1. Nov 24, 2008

### sulev8

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. Nov 24, 2008

### 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.

3. Nov 24, 2008

### sulev8

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;
i=0;
while (i<15)
{
xva=xva[i-1]+(pow(c,i-2)*h);
if (xva!=0)
{
/* if x aint 0 , calculate value*/
yva=(xva*xva)+(xva/2)-sqrt(1/(2*xva));
}
i++;
}
}

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

4. Nov 24, 2008

### sulev8

why cant u just comment my work ,and help me by giving me how it should be , and tell whats missing

5. Nov 24, 2008

### mgb_phys

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
6. Nov 24, 2008

### wildman

Well, one thing can cause you trouble:

sqrt(1/(2*xva));

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++)