How to Calculate Xi in C Program for Mathematic Function?

  • Thread starter Thread starter sulev8
  • Start date Start date
  • Tags Tags
    Program
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
5 replies · 2K views
sulev8
Messages
5
Reaction score
0
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 that's 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 don't give me just advice with this , i would just like to know how should i mark this in C language.
 
Physics news on Phys.org
sulev8 said:
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 that's 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 don't give me just advice with this , i would just like to know how should i mark this in C language.

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.
 
i don't 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 don't 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
 
why can't u just comment my work ,and help me by giving me how it should be , and tell what's missing
 
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++)