Log in

View Full Version : numerical computation challenge


Ether
15-05-2013, 07:50
Find the area between these two curves, accurate to 6 decimal places:


y=10*ln(x+1)/exp(x+1)

x=10*ln(y+1)/exp(y+1)


Use whatever computer tools you want. Show your work.

Michael Hill
15-05-2013, 12:56
I think I solved it....

I got 0.536594(7|8)
My strategy was to use the fact that it was symmetric about x=y.

I took the initial y=... function and rotated it by pi/4 (45 degrees) using the transformation matrix:

[y'] [cos(pi/4) sin(pi/4)] [y]
[ ] = [ ] [ ]
[x'] [cos(pi/4) -sin(pi/4)] [x]

That allows me to essentially take the integral above the new y' and simply multiply it by 2. I used MATLAB to get it.


clear

xmin = eval(evalin(symengine, 'numeric::solve(0==y-10*log(y+1)/exp(y+1), y=-0.5..0.5)'));
xmax = eval(evalin(symengine, 'numeric::solve(0==y-10*log(y+1)/exp(y+1), y=0.5..2)'));

error = 1;
stepsize = 3000000;
prevsum = 0;
while (abs(error > 0.000000001))
stepsize = stepsize + 10000;
th = pi/4
x0min = xmin;
x0max = xmax;
y0min = xmin;
y0max = xmax;

x0 = linspace(x0min,x0max,stepsize);
y0 = linspace(y0min,y0max,stepsize);
y = 10*log(x0+1)./exp(x0+1);
x = 10*log(y0+1)./exp(y0+1);
xp = x*cos(th) + y0*sin(th);
yp = y*cos(th) - x0*sin(th);
xp0 = x/cos(th);
plot(x0,y,x,y0,xp,yp);
axis equal
axis square
grid on
sum = 0;
for i=1:stepsize-1
sum = sum + (xp0(i+1)-xp0(i))*yp(i);
end
sum = sum*2;
error = sum - prevsum;
disp('step size');
disp(stepsize);
disp('sum');
disp(sum);
disp('error');
disp(error);
end

MechEng83
15-05-2013, 13:05
I took the initial y=... function and rotated it by pi/4 (45 degrees) using the transformation matrix:

y' [cos(pi/2) sin(pi/2)] [y]
=
x' [cos(pi/2) -sin(pi/2)] [x]

That allows me to essentially take the integral above the new y' and simply multiply it by 2.

Rather than going through the trouble of transforming it, I just subtracted the integral of y=x, as that's the symmetry line.

I got 0.536595 for the area -- found the second intercept at .95012, then just took the integral from 0 to .95012 of [10*ln(x)/exp(x)-x] and multiplied by 2.

Ether
15-05-2013, 13:29
Nice job guys. The key was using the y=x symmetry line.

In the attached graph (http://www.chiefdelphi.com/forums/attachment.php?attachmentid=14826&stc=1&d=1368638913), the red and green lines are the two curves. The cyan line y=x is the axis of symmetry. If you subtract the cyan line from the red curve, you get the black curve.

I used Maxima (http://www.chiefdelphi.com/forums/attachment.php?attachmentid=14825&stc=1&d=1368638689) to find the X-axis intercept of the black curve, and then numerically integrate the black curve from zero to that value and double it.

Michael Hill
15-05-2013, 22:14
Of course I go the complicated route. This transcends to my ideas for robots as well. I need to learn to be more elegant. :-P