Click here to Skip to main content
15,896,549 members

Comments by MalDrHoop (Top 38 by date)

MalDrHoop 26-Mar-14 15:46pm View    
I did as indicated in the algorithm... I do not know how to fix this.
MalDrHoop 26-Mar-14 13:13pm View    
I edited my program as you described:

#include <stdio.h>
#include <math.h>
#define num 20

double f(double x)
{
return (1/(x*sin(x*x)));
//return (2*x*x);
}

int main()
{
int i=1, N;
double b, APP, TOL[num], a[num], h[num], FA[num], FB[num], FC[num], S[num], S1, S2, L[num], FD, FE, v[num];

printf("Left Endpoint: ");
scanf("%lf", &a);

printf("Right Endpoint: ");
scanf("%lf", &b);

printf("Desired Tolerence: ");
scanf ("%lf", &TOL);

printf("Number of Levels: ");
scanf("%d", &N);

APP = 0;
TOL[num] = 10.0*TOL;
a[num] = a;
h[num] = (b-a)/2;

FA[num] = f(a);
FC[num] = f(a+h[num]);
FB[num] = f(b);

S[num] = h[num]*(FA[num]+4*FC[num]+FB[num])/3; //Simpsons approximation
L[num] = 1;

while (i>0)
{
FD = f(a[num] + h[num]/2);
FE = f(a[num] + 3*h[num]/2);

S1 = h[num]*(FA[num]+4*FD+FC[num])/6;
S2 = h[num]*(FC[num]+4*FE+FB[num])/6;

v[1] = a[num];
v[2] = FA[num];
v[3] = FC[num];
v[4] = FB[num];
v[5] = h[num];
v[6] = TOL[num];
v[7] = S[num];
v[8] = L[num];

i=i-1;

if (abs(S1 + S2 - v[7])<v[6])
{
="" app="APP" +="" (s1="" s2);
="" }
="" else
="" if="" (v[8]="">=N)
{
printf("Level Exceeded");
return;
}

else
{
i++;
a[num] = v[1] + v[5];
FA[num] = v[3];
FC[num] = FE;
FB[num] = v[4];
h[num] = v[5]/2;
TOL[num] = v[6]/2;
S[num] = S2;
L[num] = v[8] + 1;

i++;
a[num] = v[1];
FA[num] = v[2];
FC[num] = FD;
FB[num] = v[3];
h[num] = h[num-1];
TOL[num] = TOL[num-1];
S[num] = S1;
L[num] = L[num-1];
}
}
}

printf("The Integral Approximation is %lf." , APP);

}


Still Obtaining:

C:\Users\Mal\Desktop\MTH 415\Adaptive Quadrature 2.c||In function 'main':|
C:\Users\Mal\Desktop\MTH 415\Adaptive Quadrature 2.c|35|error: invalid operands to binary * (have 'double' and 'double *')|
C:\Users\Mal\Desktop\MTH 415\Adaptive Quadrature 2.c|36|error: incompatible types when assigning to type 'double' from type 'double *'|
C:\Users\Mal\Desktop\MTH 415\Adaptive Quadrature 2.c|37|error: invalid operands to binary - (have 'double' and 'double *')|
C:\Users\Mal\Desktop\MTH 415\Adaptive Quadrature 2.c|39|error: incompatible type for argument 1 of 'f'|
C:\Users\Mal\Desktop\MTH 415\Adaptive Quadrature 2.c|11|note: expected 'double' but argument is of type 'double *'|
C:\Users\Mal\Desktop\MTH 415\Adaptive Quadrature 2.c|40|error: invalid operands to binary + (have 'double *' and 'double')|
||=== Build finished: 5 errors, 0 warnings (0 minutes, 0 seconds) ===|
MalDrHoop 14-Feb-14 20:54pm View    
Both outputs are similar cause the two codes are different. They aren't quite the same. If I copied and pasted the same outputs its because I got all jumbled trying to get everything straightened up lol. My bad on that part. I knew the tolerance was too big, I had just chose one to try and type the inputs quickly to have the results here for someone to look at. I had been running about .00001. All of my stuff came from my numerical analysis textbook and class. My class is using Faire's and Burden 7th edition. I don't have it with me right now to look it up
MalDrHoop 14-Feb-14 20:46pm View    
Beginner's mistake!
MalDrHoop 14-Feb-14 16:18pm View    
Did you see any problems?