# Fitting curves

• Oct 24th 2006, 05:48 AM
ditzafar
Fitting curves
I have an ellipse. In the ellipse I have a point that spreading hot. I know the hot spreading equation and I need to find the hot point.
To solve this I did the following steps:
1. Define an ellipse
a=2; b=3;
y1=b*(1-x^2/a^2)^0.5;
2. putting an hot point
x0=1.3; y0=1.5;
3. Find the distance of the surface from the hot point
d1=((x-x0)^2+(y1-y0)^2)^0.5;
4. Define of hot spreading equation
5. Find the line of the hot point. This line should be the vertical to the tangent in the maximum of HotSpreading1
• Find the maximum of HotSpreading1 by differentiate the hot spreading equation and find when it equal to zero.
• Find y of Xmax by putting it in the ellipse equation
Ymax=y1 (Xmax);
• Find the slope of the line which tangential to the line we are looking for by differentiate the ellipse equation and putting Xmax
m= (diff(y1));
m1=m(Xmax);
• Find the slope of the line by doing the opposite to the slope we find
mline=-1/m1;
• Find the line by position all the component in straight line equation
line=mline*(x-Xmax)+Ymax;
6. Going on the line finding the hot spreading equation of each point and compare the equation to the equation of the real hot point. when we got to the minimum of the difference between the two curves we find the interval of the hot point.

This steps works in some hot point but doesn't works in other as well. I assume something is wrong in the idea, but I can't find what. I be glad is someone have a clue how to solve the problem.
I am adding the matlab code if some one want to run and see.

clear all
clf
%Define an ellipse
%Parameters for the ellipse
a=2; b=3;
%Drowing half ellipse
syms x y
y1=b*(1-x^2/a^2)^0.5;
yinline=inline(y1)
ezplot(y1)
hold on

%putting an hot point
x0=1.3; y0=1.5;
plot(x0,y0,'r*')

%The distance from the hot point
d=((x-x0)^2+(y-y0)^2)^0.5;

d1=((x-x0)^2+(y1-y0)^2)^0.5;
ezplot (HotSpreading1); axis([-5 5 -1 5])

%Find the line of the hot point.
%This line should be the vertical to the tangent in the maximum of HotSpreading1

%Number of iteration
NumIter=10;
Ymax=yinline(Xmax);
m=inline(diff(y1));
m1=m(Xmax);
%If the slope is zero we are working on the line x0=0
if m1==0
plot([0 0],[b 0])
%Iteration on the point of line to find x0 y0
XIteration=zeros(1,NumIter-1);
YIteration=0:b/(NumIter-1):b
else
mline=-1/m1;
line=mline*(x-Xmax)+Ymax;
line=inline(line);
ezplot(line,[-2.5 2.5])
%Iteration on the point of line to find x0 y0
XIteration=-a:2*(a)/(NumIter-1):a;
YIteration=line(XIteration);
end

%The hot spreading of real x0 y0
figure; hold on
pause
%Preparation of point on Hot Spreading to comparison
XHot=-a:0.01:a;

%The comparison process
for LoopIndex=1:length(XIteration);
%Creating of the equation to comparision
d12=((x-XIteration(LoopIndex))^2+(y1-YIteration(LoopIndex))^2)^0.5;
%ploting the graph
ezplot (HotSpreading12); axis([-a-.5 a+.5 -0.5 8])
%The comparision
Difference=(YDiff-YRealHot).^2;
SumDifference(LoopIndex)=sum(Difference);
pause
end
%Find the Xrange of the hot point. check if the cruve is between the two
[MinDiff,MinIndex]=min(SumDifference);
%Definition of the interval of X0
%If the min of the differance is in the first XIteration then the interval
%is between the two first XIteration
if MinIndex==1
%If x0=0 the line will be x=0 and that why we want in such cases to get
%y and not x.
if m1==0
y0
YIteration(1)
YIteration(2)
else
x0
XIteration(1)
XIteration(2)
end
elseif MinIndex==length(SumDifference)
%If x0=0 the line will be x=0 and that why we want in such cases to get
%y and not x.
if m1==0
y0
YIteration(length(SumDifference)-1)
YIteration(length(SumDifference))
else
x0
XIteration(length(SumDifference)-1)
XIteration(length(SumDifference))
end
%We need to find if the value is between the min and the previous or
%between the min and the next.
elseif SumDifference(MinIndex-1)<SumDifference(MinIndex+1)
%The value is between the min and the previous
if m1==0
y0
YIteration(MinIndex-1)
YIteration(MinIndex)
else
x0
XIteration(MinIndex-1)
XIteration(MinIndex)
end
else
%The value is between the min and the next
if m1==0
y0
YIteration(MinIndex)
YIteration(MinIndex+1)
else
x0
XIteration(MinIndex)
XIteration(MinIndex+1)
end
end