How can I plot just one line of the hyperbola? Can somebdoy help me with fsolve?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Dayal Kewalramani
am 10 Jul. 2015
Kommentiert: Dayal Kewalramani
am 12 Jul. 2015
This is my main code. I want to plot just the 3 lines of the hyperbola, the ones they are intersecting (Xt,Yt). Ho can I do it?
Xt=randi([-10 10],1,1);
Yt=randi([-10 10],1,1);
[Xtx, Ytx] = meshgrid(-40:1:40, -40:1:40);
R = Xtx + j*Ytx;
for i = 1:3
X(i)=randi([-10 10],1,1);
Y(i)=randi([-10 10],1,1);
x=[X(i) Xt];
y=[Y(i) Yt];
D(i)=sqrt((Xt-X(i))^2+(Yt-Y(i))^2);
figure(1)
line(x,y,'LineWidth',2);
hold on;
axis equal;
plot(x,y,'*',Xt,Yt,'s');
end
Delay1=D(2)-D(1);
Delay2=D(3)-D(1);
D1P = abs(R-(X(1)+j*Y(1)));
D2P = abs(R-(X(2)+j*Y(2)));
D3P = abs(R-(X(3)+j*Y(3)));
figure (1);
contour(Xtx,Ytx,D1P-D2P,[0 0]);
contour(Xtx,Ytx,abs(D1P-D2P));
contour(Xtx,Ytx,D3P-D2P,[0 0]);
contour(Xtx,Ytx,abs(D3P-D2P));
% for m=1:3
% DP(m)=abs(R-(X(m)+j*Y(m)));
% figure(1);
% contour(Xtx,Ytx,DP(m)-DP(m+1));
% end
Xtt=-10;
x0=[0;0];% Make a starting guess at the solution
options = optimoptions('fsolve','Display','iter'); % Option to display output
[x,fval]=fsolve(@position(Y,X,Delay1,Delay2);x0;options); % Call solver
I also want to generate a for loop with DP but it gives me an error with size of matrix I need some help also in these lines of the code.
Now i want to call this function with fsolve:
function P=position(Y,X,Delay1,Delay2)
X0=X(1);
X1=X(2);
X2=X(3);
Y0=Y(1);
Y1=Y(2);
Y2=Y(3);
Xt=-10:10;
Yt=-10:10;
P=[(Delay1)-sqrt((Xtxx-X1).^2+(Ytxx-Y1).^2)+sqrt((Xtxx-X0).^2+(Ytxx-Y0).^2); (Delay2)-sqrt((Xtxx-X2).^2+(Ytxx-Y2).^2)+sqrt((Xtxx-X0).^2+(Ytxx-Y0).^2)];
end
I have an bracket error with the fsolve. My output of the funcion are (Xtxx,Ytxx). Need help in this.
Than you.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 11 Jul. 2015
I think possibly you want
[x,fval] = fsolve(@(txx) position(txx, Y,X,Delay1,Delay2);x0;options); % Call solver
with
function P = position(txx, Y,X,Delay1,Delay2)
Xtxx = txx(1);
Ytxx = txx(2);
X0=X(1);
X1=X(2);
X2=X(3);
Y0=Y(1);
Y1=Y(2);
Y2=Y(3);
Xt=-10:10;
Yt=-10:10;
P=[(Delay1)-sqrt((Xtxx-X1).^2+(Ytxx-Y1).^2)+sqrt((Xtxx-X0).^2+(Ytxx-Y0).^2); (Delay2)-sqrt((Xtxx-X2).^2+(Ytxx-Y2).^2)+sqrt((Xtxx-X0).^2+(Ytxx-Y0).^2)];
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!