Also, ich hatte Spaß mit dieser (danke dafür)!
Andere Frage, andere Antwort.
Die Lösung unter sucht zuerst die Konstanten, die die X
und Y
abfängt, wodurch Sie suchen (p1
und p2
). Für diejenigen Konstanten, die am besten zu dem Problem passen, wird ein Diagramm erstellt, das numerische Probleme berücksichtigt.
In der Tat brauchen Sie nicht eq. 1, weil das immer für jede Kurve gilt - es ist nur da, um Sie zu verwirren, und problematisch zu verwenden.
So, hier ist es:
function C = solve_for_F()
% Points of interest
px = 6;
py = 4.2;
% Wrapper function; search for those constants
% causing the correct X,Y intercepts (at px, py)
G = @(C) abs(F(0, px, C)) + ... % X intercept at px
abs(F(py, 0, C)); % Y intercept at py
% Initial estimate, based on your original equation
C0 = [5/33
1247745517111813/562949953421312
4243112111277797/4503599627370496
5/66];
% Minimize the error in G by optimizing those constants
C = fminsearch(G, C0);
% Plot the solutions
plot_XY(px, py, C);
end
function plot_XY(xmax,ymax, C)
% graininess of X
N = 100;
% Find solutions for all alphae
Y = zeros(1,N);
X = linspace(0, xmax, N);
y0 = linspace(ymax, 0, N);
options = optimset('Display', 'off',...,...
'TolX' , 1e-10);
% Solve the nonlinear equation for each X
for ii = 1:numel(X)
% Wrapper function for fzero()
fcn1 = @(y)F(y, X(ii), C);
% fzero() is probably the fastest and most intuitive
% solver for this problem
[Y(ii),~,flag] = fzero(fcn1, y0(ii), options);
% However, it uses an algorithm that easily diverges
% when the function slope is large. For those cases,
% solve with fminsearch()
if flag ~= 1
% In this case, the minimum of the absolute value
% is searched for (which should be zero)
fcn2 = @(y) abs(fcn1(y));
Y(ii) = fminsearch(fcn2, y0(ii), options);
end
end
% Now plot the X,Y solutions
plot(X, Y,...
'linewidth', 2,...
'color', [1 0.65 0]);
xlabel('X'), ylabel('Y')
axis([0 xmax+.1 0 ymax+.1])
end
function fval = F(Y, X, C)
% Unpack constants
b = C(1); d = C(3);
c = C(2); k = C(4);
% pre-work
V = atan2(2*Y, X) + c;
% Eq. 2
fval = sqrt((b*Y*sin(V) + k*X*(cos(V) + 1))^2 + ...
(b*Y*cos(V) - k*X* sin(V) )^2 ) - d;
end
Wenn es sich um eine halb-Parabel ist, warum Sie nicht die klassische lineare Form Y implementieren = a * x^2 + b * x + c (unter der Annahme, dass die Symmetrieachse der Parabel parallel zu Y ist, a> 0, wenn sie konkav ist, b = 0, wenn der Eckpunkt genau auf der Y-Achse liegt)? (Ich denke, wie man in Ihrem Fall antwortet) – marcoresk
Es ist nicht wirklich parabolisch. Da ich kein Bild anhängen konnte, wollte ich die Kurvenform califizieren. Wir haben seine Gleichung und die Grenze. –
Sie haben vergessen, eine Frage zu stellen. – Adriaan