#define (MAX_SIZE) = 10000 void main(void); double y[], x[]; printf("this program demonstrates the formula for a standing wave on a string") printf("the formula used is y(x) = Asin(n*pi*x/L)"); //while writing the code, will call y(x) just y// // this is the algorithm, it should output values of y// // each time x increases +0.05 and a new y is found// y=A*sin((n*PI*x)/L); for (x=0;x<=20;x = x+0.05) y=A*sin((n*PI*x)/L); //i would now like to store the values of y in an array, and x in an array// // here i print the values of the arrays// printf("the values of y for the corresponding x values are %lf",y[]); printf("the values of x are %lf,x[]); }
8 Replies  772 Views  Last Post: 14 October 2008  08:10 AM
#1
increment x in the calculation
Posted 13 October 2008  03:01 PM
would like to output the value of y, each time x is increased by 0.05
Replies To: increment x in the calculation
#2
Re: increment x in the calculation
Posted 13 October 2008  03:27 PM
Think you might need some { } in there somewhere to indicate how long you want your for() to go on for, otherwise it just does the first action.
#3
Re: increment x in the calculation
Posted 13 October 2008  04:52 PM
#4
Re: increment x in the calculation
Posted 13 October 2008  11:37 PM
I am not sure whether this thing even compiles properly, there are many small mistakes there...
I have just modified few of the mistakes, there are still many doubts in my mind. Like from where you get values of n,L and x array?
what are those values? how come you are using x as a variable even after it's being an array.
So explain the complete problem properly, again. with what you expect out of it. Put your updated code and tell us what problems you are facing after the changes [and discoveries you made while doing them ].
#define MAX_SIZE = 1000 void main(void) { double y[MAX_SIZE], x[MAX_SIZE]; // array must have max elements value while declaring it. else it will give error. int i=0; printf("this program demonstrates the formula for a standing wave on a string") printf("the formula used is y(x) = Asin(n*pi*x/L)"); //while writing the code, will call y(x) just y// // this is the algorithm, it should output values of y// // each time x increases +0.05 and a new y is found// y[i]=A*sin((n*PI*x)/L); // if every time you find a new y and you have an array as y then you must be expecting to store every new y in array right? for (x=0;x<=100;x = x+0.05) // you wanted it to go till 100, that's why I changed the condition. y[i++]=A*sin((n*PI*x)/L); // as you said earlier, every time new y is found so store it as a new value in array. //i would now like to store the values of y in an array, and x in an array// // here i print the values of the arrays// printf("the values of y for the corresponding x values are %lf",y[]); printf("the values of x are %lf,x[]); }
I have just modified few of the mistakes, there are still many doubts in my mind. Like from where you get values of n,L and x array?
what are those values? how come you are using x as a variable even after it's being an array.
So explain the complete problem properly, again. with what you expect out of it. Put your updated code and tell us what problems you are facing after the changes [and discoveries you made while doing them ].
#5
Re: increment x in the calculation
Posted 14 October 2008  03:40 AM
hello!
well heres the deal,
n, L, and A are constants.
The program, when run, should give 2 outputs
1) output for x increasing in 0.05 increments, i.e;
x= 0.05
x=0.01
x=0.15 etc
and 2) output for y. y is calculated by a formula which has x in it.
each time y is calculated x should increase by 0.05
so for e.g
y = 2
y= 3
y =3
so and ideal output would be
x = 0.05 y = 2
x= 0.01 y=3
ps: just checked your post now and replied, but will reply with my code very shortly. !
well heres the deal,
n, L, and A are constants.
The program, when run, should give 2 outputs
1) output for x increasing in 0.05 increments, i.e;
x= 0.05
x=0.01
x=0.15 etc
and 2) output for y. y is calculated by a formula which has x in it.
each time y is calculated x should increase by 0.05
so for e.g
y = 2
y= 3
y =3
so and ideal output would be
x = 0.05 y = 2
x= 0.01 y=3
ps: just checked your post now and replied, but will reply with my code very shortly. !
AmitTheInfinity, on 13 Oct, 2008  11:37 PM, said:
I am not sure whether this thing even compiles properly, there are many small mistakes there...
I have just modified few of the mistakes, there are still many doubts in my mind. Like from where you get values of n,L and x array?
what are those values? how come you are using x as a variable even after it's being an array.
So explain the complete problem properly, again. with what you expect out of it. Put your updated code and tell us what problems you are facing after the changes [and discoveries you made while doing them ].
#define MAX_SIZE = 1000 void main(void) { double y[MAX_SIZE], x[MAX_SIZE]; // array must have max elements value while declaring it. else it will give error. int i=0; printf("this program demonstrates the formula for a standing wave on a string") printf("the formula used is y(x) = Asin(n*pi*x/L)"); //while writing the code, will call y(x) just y// // this is the algorithm, it should output values of y// // each time x increases +0.05 and a new y is found// y[i]=A*sin((n*PI*x)/L); // if every time you find a new y and you have an array as y then you must be expecting to store every new y in array right? for (x=0;x<=100;x = x+0.05) // you wanted it to go till 100, that's why I changed the condition. y[i++]=A*sin((n*PI*x)/L); // as you said earlier, every time new y is found so store it as a new value in array. //i would now like to store the values of y in an array, and x in an array// // here i print the values of the arrays// printf("the values of y for the corresponding x values are %lf",y[]); printf("the values of x are %lf,x[]); }
I have just modified few of the mistakes, there are still many doubts in my mind. Like from where you get values of n,L and x array?
what are those values? how come you are using x as a variable even after it's being an array.
So explain the complete problem properly, again. with what you expect out of it. Put your updated code and tell us what problems you are facing after the changes [and discoveries you made while doing them ].
#6
Re: increment x in the calculation
Posted 14 October 2008  04:42 AM
Based on what I understood, these are the changes I have done. See if this helps you.
You might need to correct some silly mistakes or syntax errors as I did this on the fly.
I hope this will help you.
#define MAX_SIZE = 10000 void main(void) { double y[MAX_SIZE]; // array must have max elements value while declaring it. else it will give error. double x; // because as per your description, you have predefined increments for it and we can handle it as a single variable. int i=0; printf("this program demonstrates the formula for a standing wave on a string") printf("the formula used is y(x) = Asin(n*pi*x/L)"); //while writing the code, will call y(x) just y// // this is the algorithm, it should output values of y// // each time x increases +0.05 and a new y is found// // y[i]=A*sin((n*PI*x)/L); // I don't think this will be required if you start x from 0 in your loop. for (x=0;x<=100;x = x+0.05) // you wanted it to go till 100, that's why I changed the condition. { y[i]=A*sin((n*PI*x)/L); // as you said earlier, every time new y is found so store it as a new value in array. printf("x= %lf\ty=%lf",x,y[i]); // printing what you want to print. i++; } //i would now like to store the values of y in an array, and x in an array// // here i print the values of the arrays// //printf("the values of y for the corresponding x values are %lf",y[]); these are not necessary now as we print it inside the loop. //printf("the values of x are %lf,x[]); }
You might need to correct some silly mistakes or syntax errors as I did this on the fly.
I hope this will help you.
#7
Re: increment x in the calculation
Posted 14 October 2008  05:18 AM
hey amit, what do you think of this? , i can't see my output because for some reason my screen closes down once i enter the value for data!! haha...born C problematic!
//program to determine string height versus position for a standing wave// //for 0.05 increment steps for x// #include<stdio.h> #include<math.h> #define n 2 #define L 2 #define A 0.1 #define PI 3.14 void main(void); #define MAX_SIZE 10000 void main(void) { double y[MAX_SIZE]; double x; int i=0; int data,step; printf("\n This program demonstrates the formula for a standing wave on a string\n"); printf("\n The formula used is"); printf(" \n y(x) = Asin(n*pi*x/L)\n"); printf("\n Please enter the amount of data you would like?\n\n");// i've decided to add in this extra option for the user// //for e.g user enters 20 ,so will go 20 increment steps// scanf("%d",&data); step=0.05*data; for (x=0;x<=step;x = x+0.05) { y[i]=A*sin((n*PI*x)/L); printf("x= %lf\ty=%lf",x,y[i]); i++; } }
AmitTheInfinity, on 14 Oct, 2008  04:42 AM, said:
Based on what I understood, these are the changes I have done. See if this helps you.
You might need to correct some silly mistakes or syntax errors as I did this on the fly.
I hope this will help you.
#define MAX_SIZE = 10000 void main(void) { double y[MAX_SIZE]; // array must have max elements value while declaring it. else it will give error. double x; // because as per your description, you have predefined increments for it and we can handle it as a single variable. int i=0; printf("this program demonstrates the formula for a standing wave on a string") printf("the formula used is y(x) = Asin(n*pi*x/L)"); //while writing the code, will call y(x) just y// // this is the algorithm, it should output values of y// // each time x increases +0.05 and a new y is found// // y[i]=A*sin((n*PI*x)/L); // I don't think this will be required if you start x from 0 in your loop. for (x=0;x<=100;x = x+0.05) // you wanted it to go till 100, that's why I changed the condition. { y[i]=A*sin((n*PI*x)/L); // as you said earlier, every time new y is found so store it as a new value in array. printf("x= %lf\ty=%lf",x,y[i]); // printing what you want to print. i++; } //i would now like to store the values of y in an array, and x in an array// // here i print the values of the arrays// //printf("the values of y for the corresponding x values are %lf",y[]); these are not necessary now as we print it inside the loop. //printf("the values of x are %lf,x[]); }
You might need to correct some silly mistakes or syntax errors as I did this on the fly.
I hope this will help you.
#8
Re: increment x in the calculation
Posted 14 October 2008  05:32 AM
1. You have step as integer but the result of the multiplication you are doing is float [or double ] so step should be a double or float variable.
2. You can put something like getch() in the end of your main if you think the screen immediately disappears after showing the results. [It's a practical adjustment and not something important] Actually this happens only when you run it from your IDE. if you call executable of your program from prompt. such things won't happen as you are already on prompt.
2. You can put something like getch() in the end of your main if you think the screen immediately disappears after showing the results. [It's a practical adjustment and not something important] Actually this happens only when you run it from your IDE. if you call executable of your program from prompt. such things won't happen as you are already on prompt.
#9
Re: increment x in the calculation
Posted 14 October 2008  08:10 AM
you are an intelligent guy.
i am a doorknob when i comes to C.
so yup, the program works like a charm!
now i'll just pretty it up , like have each new x and y value on a new line!
woot woot!!
i am a doorknob when i comes to C.
so yup, the program works like a charm!
now i'll just pretty it up , like have each new x and y value on a new line!
woot woot!!
//program to determine string height versus position for a standing wave// //for 0.05 increment steps for x// #include<stdio.h> #include<math.h> #define n 2 #define L 2 #define A 0.1 #define PI 3.14 void main(void); #define MAX_SIZE 10000 void main(void) { double y[MAX_SIZE]; double x,step; int i=0; int data; printf("\n This program demonstrates the formula for a standing wave on a string\n"); printf("\n The formula used is"); printf(" \n y(x) = Asin(n*pi*x/L)\n"); printf("\n Please enter the amount of data you would like?\n\n");// i've decided to add in this extra option for the user// //for e.g user enters 20 ,so will go 20 increment steps// scanf("%d",&data); step=0.05*data; for (x=0;x<=step;x = x+0.05) { y[i]=A*sin((n*PI*x)/L); printf("x= %lf\ty=%lf",x,y[i]); i++; getch(); } }
AmitTheInfinity, on 14 Oct, 2008  05:32 AM, said:
1. You have step as integer but the result of the multiplication you are doing is float [or double ] so step should be a double or float variable.
2. You can put something like getch() in the end of your main if you think the screen immediately disappears after showing the results. [It's a practical adjustment and not something important] Actually this happens only when you run it from your IDE. if you call executable of your program from prompt. such things won't happen as you are already on prompt.
2. You can put something like getch() in the end of your main if you think the screen immediately disappears after showing the results. [It's a practical adjustment and not something important] Actually this happens only when you run it from your IDE. if you call executable of your program from prompt. such things won't happen as you are already on prompt.
Page 1 of 1
