write a pogram that computes the area between 2 curves
hi again. im doing this prgrm in java. i still have no idea on how to do it. i still have to research about functions. but the program is something like this.,
The user should have options for 3 different precisions.
Inputs are (f(x), g(x), a, b)
f(x) and g(x) are simple transcendental functions ?(has terms involving exponential and trigonometric.
if someone has the idea on how to do it, please help me and give me insights. it would be gladly appreciated.. thanks...
i will also post here what i research. thanks.
[554 byte] By [
grace_a] at [2007-10-3 4:16:42]

I can see that maybe the object representation of f(x) and g(x) might be a bit difficult. However, it shouldn't be too difficult to create a Polynomial class to represent them. After all, a polynomial can be represented by integer coefficients. Also, your Polynomial class will have to implement the arithmetic operations required to complete the calculation. I didn't really look too hard on Google, but it looks like other people have already done this sort of work for you, so it should be a simple matter of using the Polynomial class you find or create and performing the required arithmetic.
Brian
guys, thanks for the links. for the help. i figured out how computation is going to work.. ok, Simpson's rule approximate the area under the curve/function, say f(x) from interval [a,b].
now, we have two functions, f(x) and g(x). the idea now is, to solve for the areas under these two curves using Simpson's Rule and then, determine which function has the larger area and from that, subtract the other function, and alas! we have computed the area bounded by the two curves in the interva [a,b].my problem now is more on the function evaluation, say for example, evaluating a function f(x)=x^3-2 and g(x)=cos(x) + 3ln(x).. and so on... it's like how am i going to solve for these functions?
hi.guys iv'e figured out what to do.
im going to use the simpson rule.
here's the algo:
1.ask for the function f(x). (functions are mathematical expressions with 2.variables that will be replaced later by the values of the interval.) example input is e^n*(cos (4*n)).
3.ask for fcn g(x).
4.ask for the interval, a,b.
5.set val1= simpson(f,a,b)
6.val2=simpson(g,a,b).
if val1 is greater than val2,
val=val1-val2.
else, val=val2-val1
that's it. now we will make the function
simpson( string f, double a, double b).{
double h=(b-a)/2
then
f0= eval(f,a);
f1= eval(f, a+h);
f2=eval(f, a+h+h);
simp= h/3(f0+f1+f2);
return simp;
}
by the way, eval() first convert the infix expression of function into postfix before evaluating it.
in that, i willgoing to use stacks...
how am i going to implement stacks if im going to store string as array of chars.