Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Find the area between y = 1 - x/π and y = Sin[x].

Here is what I have typed in so far into Mathematica:

Clear[f, g, x]
f[x_] := 1 - x/π
g[x_] := Sin[x]
Plot[{f[x], g[x]}, {x, 0, 2 π}, 
  PlotStyle -> {Red, Blue}, PlotRange -> {-1.2, 1.2}, Filling -> {1 -> {2}}]

The graph worked, so I have that. However, when I try to do the next step, Solve[f[x] = g[x], x], it will not give me the intersects. I have even tried retyping the equations in: Solve[Sin[x] = 1 - x/π, x], but nothing is working. What am I doing wrong?

share|improve this question
4  
Hi Alison. You need to use Pi (not pi), and == (not =). And try specifying Reals for Solve's domain. (Although that might not be the real problem.) And I wonder, section 6.1 of what? –  cormullion Dec 16 '13 at 14:37
1  
Works for me with Solve[f[x] == g[x], x, Reals]. –  m_goldberg Dec 16 '13 at 14:51
2  
The real problem is that it is a trancedental equation and no analytical solutions to these types of equations are known in general (though the x=Pi solution can be readily seen here). Try NSolve instead for a numerical solution. –  Sjoerd C. de Vries Dec 16 '13 at 14:59
    
FYI you can just integrate the thing without explicitly finding the roots.. Integrate[Abs[f[x] - g[x]], {x, 0, 2 Pi}] // N –  george2079 Dec 16 '13 at 16:43
    
@george2079, I wrote this answer with little more explanation. –  caya Dec 16 '13 at 22:10

1 Answer 1

This

Plot[Abs[f[x] - g[x]], {x, 0, 2 Pi}, Filling->Axis]

should convince you that this measures the high between the two curves (*), regardless of which one is at the top. So, as pointed already by @george2079, use NIntegrate like

NIntegrate[Abs[f[x] - g[x]], {x, 0, 2 Pi}]

%= 2.43935

(*) Note that Mathematica has powerful integration mechanisms, but you need to gain insight in what you are doing to unleash its power. Abs is a measure of magnitude in the real line and that's why is being used above.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.