I'm in my second programming class at school, thing is the last time I took programming was a year ago and it was a mix of basics for C, matlab and java, so I'm having trouble remembering anything.
Well anyways though I'm doing practice problems for our test and I'm having trouble with one... we're supposed to be using the bisection method to find roots of a polynomial. The algorithm for that isnt what im having trouble with, I have pseudocode for it in the book but in any case I'm not to that point yet. we're supposed to print a table of values for input and output angles and using a given polynomial print the "error" which is actually the function value (deviation from zero) Anyways we're supposed to be having the user enter a 10 degree long range of angles between 0 and 360 and so I'm doing a while statement to check if the range is valid... however I said if: (beta_u-beta_l==10) (where beta_u is the end of the range, and beta_l is the beginning) then I want it to call a function... however its not doing that and doesnt seem to even be executing my if statements... I'm guessing that its some issue with a break or something but I've tried adding one and its not helping. I'll post the whole code with a comment above the loop I'm having trouble with
insert
Code:
#include "stdio.h"
#include "math.h"
double Freudenstein(double alpha, double beta);
double bisection(double alpha, double beta_u, double beta_l);
double alpha=45;
int a=6;
int b=18;
int c=15;
double d=15.5;
void main () {
double beta=0;
enum{rows=20,cols=3};
double beta_l=-3;
double beta_u= 370;
printf("The input angle alpha is 45 degrees, and we will be computing the error for various output angles: beta=[0:18:360]\n");
printf("\nalpha(deg)\t, beta(deg)\t,error\n");
printf("\n");
while (beta<360) { //the minimum output angle under examination
// is 0, the max is 360, with increments of 18
beta=beta+18;
printf("%lf\t,%lf\t, %lf\n",alpha,beta,Freudenstein(alpha,beta));
}
printf("\nPlease input a 10 degree interval of output angles (Beta) to be checked, between Beta= 0 degrees and Beta= 360 degrees, in the follwing form: Beta lower Beta upper:\n");
scanf("%lf,%lf",&beta_l,&beta_u);
//HERES THE TROUBLE LOOP
while ((beta_u <0 || beta_l <0) || (beta_u>360 || beta_l>360) && beta_u-beta_l!=102 !=10 ) {
if ((beta_u-beta_l != 10)) {
printf("\n Please re-enter a valid 10 degree long interval for Beta between 0 and 360 degrees:\n");
scanf("%lf,%lf",&beta_l,&beta_u);
}
else if (beta_u-beta_l==10) {
printf("hi there! this is a cool number: %lf \n",bisection(alpha,beta_u,beta_l));
break;
}
}
}
double Freudenstein(double alpha,double beta) {
double error;
error= (pow(a,2)-pow(b,2)+pow(c,2)+pow(d,2)-(2*a*c*sin(alpha)*sin(beta))-(2*a*c*cos(alpha)*cos(beta))-(2*a*d*cos(alpha))+ (2*c*d*cos(beta)));
return(error);
}
//this function is where my root finding bisection method will be eventually
double bisection(double alpha, double beta_u,double beta_l) {
double m= 3.5+7.5;
return(m);
}
I know theres probably a better way to do this... I am pretty new at programming in general. another thing is is that because of my boolean operators if the (beta_u-beta_l !=10) it reprints
the printf statement twice... I honestly cant think of any way around that, so if any of you can any ideas would be appreciated.
thanks