Clear Filters
Clear Filters

How to find a coordinate of a circle with a given equation tangent to the circle

7 views (last 30 days)
How do I find the center coordinate Y (where X coordinate is equal to 0) of a circle tangent to an equation 𝑦=ln(𝑥^4) using root finding method. Please help.
This is the code I tried but it's giving me a (0,0) center coordinate... It should be 3.236
f = @(x) log(x^4) - sqrt (4^2 - (x^2)); % Define f(x)
df = @(x) 4./x + x./sqrt (16-x.^2); % Define f (x)
x0 = 20; Tol = 1e-6; % Initial guess
x=linspace(-10,10,200); % x ∈ [1,3] for plot
ay = log(x.^4); % f(x) for plot
plot(x,ay) % plot the equation
xlabel('x') % show label at x axis
ylabel('f(x)') % show label at y axis
title('Roots of f(x)= log(x^4)') % show Title
grid on; % show grid
hold on; % hold plot for the next plot
xnew = x0;
xold = Inf;
c = 0;
fprintf ('Iter %d: %.6f\n', c,xnew ); % Print x0
while abs( xnew-xold ) > Tol % Newton's Method
xold = xnew ;
xnew = xold- f( xold ) / df(xold); % Main equation
fprintf ('Iter %d: %.6f\n', c,xnew ); % Print xi
end
plot(xnew,f(xnew),'r*', 'Markersize', 10); % plot the xnew points
grid on; % show grid
hold on; % hold plot for the next plot
fprintf ('The root is: %.6f\n', xnew ); % Print answer
  2 Comments
Matt J
Matt J on 19 Mar 2023
Edited: Matt J on 19 Mar 2023
The problem is ill-posed unless you also know the radius of the circle, or some other additional piece of constraining information.
At any point on the y-axis, you can center a tangent circle if you choose the radius correctly.
John D'Errico
John D'Errico on 19 Mar 2023
Edited: John D'Errico on 19 Mar 2023
Matt - I think the circle is supposed to be of radius 4, based on this line:
f = @(x) log(x^4) - sqrt (4^2 - (x^2));
It is not really the correct function to solve for as far as I can see. But the second half of that function is an arc of a circle of radius 4. The wrong arc. But an arc.
You are correct though, if the radius is unspecified, then there are infinitely many circles with center on the y-axis, and tangent to that curve.

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 19 Mar 2023
Edited: John D'Errico on 19 Mar 2023
You (apparently) want to find the circle of radius 4, with center at (0,y0), where y0 is unknown, that is tangent to the curve. I'll assume that is the case, based on the equations you wrote.
Rather than solve it as you have done, I might try a different approach.
There is a circle tangent to the curve at any point. The curve is given by
y = @(x) log(x.^4);
So for any point x, the curve is defined by the pair (x,log(x^4)). That is a point on the curve for any x. What is the slope of the tangent line at that point? That is just the derivative of the curve, at x. So the tangent line slope is 4/x. You already did that part.
Next, what is the line NORMAL to the curve at any point? That line would have a slope perpendicular to the tangent line. And how can we compute the slope of a line perpendicular to a known line? We take the negative reciprocal of the slope. The negative reciprocal of the slope is just -x/4.
This tells us the equation of the perpendicular line to that curve at some specific point (x0,log(x0^4)).
y - log(x0^4) = (-x0/4)*(x - x0)
Expand that relation, to get this equation of a line, perpendicular to the curve, at x0.
y = (-x0/4)*x + (x0^2/4 + 4*log(x0))
What is the y-intercept of that curve? That is, what is the point where it intercepts the y axis? That happens when x==0, so we would have the point at
(0,x0^2/4 + 4*log(x0))
as the y-intercept.
If the distance from that point to (x0,4*log(x0)) is exactly 4, then we have our solution. Simpler yet, we want the square of the distance to be 16. That gives us this relationship:
(0 - x0)^2 + (x0^2/4 + 4*log(x0) - 4*log(x0))^2 == 16
Of course, since this is a question of MATLAB, I'll let it do the work, even though pencol and paper would be adequate.
syms X0
assume(X0>0)
Dsquared = expand(sum(([0,X0^2/4 + 4*log(X0)] - [X0,4*log(X0)]).^2))
Dsquared = 
X0sol = solve(Dsquared == 16)
X0sol = 
And the y-intercept at that point is:
Y0 = X0sol^2/4 + 4*log(X0sol)
Y0 = 
Y0 = double(Y0)
Y0 = 7.0549
So the center of the circle tangent to the curve is at (0,7.0549). Plot it now.
fplot(y,[-10,10],'r')
Theta = linspace(0,2*pi);
hold on
plot(0 + 4*cos(Theta),Y0 + 4*sin(Theta),'b')
plot([0,double(X0sol)],[Y0,4*log(double(X0sol))],'g-o')
axis equal
grid on
hold off
So the point of tangency lies at:
double(X0sol)
ans = 3.1446
I don't know why you think 3.236 is the solution. I would note that my plot matches what you drew in your question nicely. It is possible that if the circle has radius 2, the solution might be 3.236 for y0. I'll not redo my analysis to confirm that guess. Sorry.
Having found the real solution, now I'll look at what you did. Is what you wrote the correct equation for the intersection of the circle and curve? No.
The equation of a circle of radius 4 at center (0,y0) would be
x^2 + (y - y0)^2 = 16
If we solve for the lower branch of that circle, we would get
y = y0 - sqrt(16 - x^2)
Next, it appears you equated that to the curve log(x^4). So we would be looking for a solution of the problem
log(x^4) == y0 - sqrt(16 - x^2)
So you made at least one mistake very early in the solution. That it gave you the wrong answer is not a surprise.
How would I solve this problem numerically? Above I showed how to solve the problem using symbolic tools, and as you can see from the plot, that is the solution you should find. (Really, I solved most of it on paper.) But now I'll formulate the problem in numerical terms. Even so, in order to solve a problem, you need to be able to write down, CORRECTLY using mathematics. The equation of a circle with center (0,y0) and radius 4 is:
x^2 + (y - y0)^2 = 4^2
Since the circle will touch the curve on the LOWER branch of the curve, we would have this, solving for y.
y = y0 - sqrt(16 - x^2)
And the curve itself is
y = log(x^4) = 4*log(x)
That gives us one equation at the point of intersection, by equating the y-values. Note that y0 is still in there, as the center point of the circle.
4*log(x) = y0 - sqrt(16 - x^2)
Next, we might decide to equate the slopes of the tangent lines at the point of intersection. The slope of the tangent line to the curve is
4/x
The slope of the tengent line to the circle is, fiddle, fiddle...)
x/sqrt(16-x^2)
Equating them, we have a second equation
4/x == x/sqrt(16-x^2)
Ah, so that is where that equation for f comes from.
f = @(x) 4./x - x./sqrt(16-x.^2);
fplot(f,[1,5])
yline(0,'r')
The solution where that curve crosses zero is:
[x0,fval] = fzero(f,[1,4-eps*100])
x0 = 3.1446
fval = 2.2204e-16
If you want to use Newton's method, feel free. And this is the same solution I found above. So now we can recover the center of the circle from the other relation, as
y0 = 4*log(x0) + sqrt(16 - x0^2)
y0 = 7.0549
And again, it should be no surprise that this is the same as we found above.
  2 Comments
John D'Errico
John D'Errico on 21 Mar 2023
And, so? I first showed how to solve the problem using pencil and paper. Then I showed how to solve the problem using fzero, but I won't do your homework for you. You can simply replace the call to fzero with your own bisection tool, or Newton's method, etc. I derived all of the equations, and verified thay allow you to solve the problem, so all you need to do is replace the call to fzero. Or, I can happily delete my answer. Your choice.
BG
BG on 21 Mar 2023
Didn't mean to offend you. I really do appreciate the help. Just didn't know where to replace it. Thank you again for the detailed explanation.

Sign in to comment.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!