# Solve for: When does the area bound by three curves == area desired

The program I've been making an attempt to write does the following:

1. Plot 2 lines, f(x) = –x and g(x,a) = e^(x – a) –a
2. Find area bound by the 2 lines and x-axis (shaded in red)
3. A "desired area" value can be defined.
4. By pressing the button, program will calculate the value of 'a' which the area (shaded in red) will equal to the value of area desired.

For an example, if the "area desired" was –0.227969, the program will return an "a" value of 1, as the area will equal exactly –0.227969 when a = 1. (This was calculated in desmos as seen below)

https://www.desmos.com/calculator/pd30drwnfr

So far I've got this code (which gives an error):

f = -x;
g[A_] = E^(x - A) - A;

Manipulate[
gIntersect = x /. Solve[g[A] == 0, {x, A}];
area = Integrate[f, {x, 0, A}] + Integrate[g, {x, A, gIntersect}];
solution = Solve[area == areaD, A];

Plot[{f, g[A]}, {x, 0, 5}, PlotLabel -> area,
PlotRange -> {{0, 5}, {-3, 3}}],

{{A, 1, "Initial value"}, 0, 5, 0.1, Appearance -> "Labeled"},
{{areaD, -1, "Area desired"}, -5, 5, 0.1, Appearance -> "Labeled"},
Button["Calculate value of 'a' to satisfy area desired", A = solution]
]


This code tries to figure out the intersection of g(x,a), then integrates the two curves to figure out the area bounded.

How will I be able to complete this program? Will appreciate any help or suggestions!

f[x_] := -x;
g[A_, x_] := Exp[x - A] - A;
xc[A_] := A + Log[A]
area[A_?NumericQ, gIntersect_?NumericQ] :=
NIntegrate[f[x], {x, 0, gIntersect}] +
NIntegrate[g[A, x], {x, gIntersect, A}];
Manipulate[gIntersect = xc[A];
solution = A /. FindRoot[area[A, xc[A]] == areaD, {A, 1}];
Plot[{f[x], g[A, x]}, {x, 0, 5},
PlotLabel ->
Grid[{{"area=", area[A, gIntersect]}, {"gIntersect=",
gIntersect}}], PlotRange -> {{0, 5}, {-3, 3}}], {{A, 1, "A"}, 1,
5, 0.1, Appearance -> "Labeled"}, {{areaD, -1, "Area desired"}, -5,
0, 0.1, Appearance -> "Labeled"},
Button["Calculate value of A to satisfy area desired", A = solution]]


• Thank you very much, will learn off of this! Dec 3, 2018 at 6:28
• Your code added the integral of f(x) from 0 to g(x)=0 plus integral of g(x) from g(x)=0 to A. Since this did not calculate the area, I made some improvements by adding in gIntercept: f(x)==g(x) and xIntercept: g(x)==0 which is pasted in this link: https://pastebin.com/Mr1kuDpn Dec 4, 2018 at 10:03