Intersection point of yline
13 ビュー (過去 30 日間)
古いコメントを表示
Kenneth Bisgaard Cristensen
2020 年 7 月 14 日
コメント済み: Star Strider
2020 年 7 月 15 日
Hi,
I have tried some diffrent metods, but so far without any luck. Is there a way to show the x,y coordinates of the intersection point of yline and the f1?
x=[-150:5:0, 0:5:100]
hold on
z=50
yline((z),'--r');
f1=[5E-08 -3E-05 -0.0058 1.0479 177.56]
y1=polyval(f1,x)
plot(x,y1)
grid on
6 件のコメント
採用された回答
その他の回答 (1 件)
neil jerome
2020 年 7 月 14 日
the code below shows how to 'brute force' a numerical answer, down to a precision you can adjust, by iteratively 'zooming in' on the region. for an analytical answer, matlab probably isn't the right tool :)
good luck!
n.
%% converge by using smaller increments
thresh = 0.000000000001; % choose precision of stopping criterion for 'y1 = z'
increment = 5;
x = -150:increment:100;
f1 = [5E-08 -3E-05 -0.0058 1.0479 177.56];
z = 50;
iteration = 1;
residual = 1;
while residual > thresh
y1 = polyval(f1,x);
% find closest point in current x vector
signal = y1-z;
smallestDiff = min(abs(signal));
closestPoint = find(abs(signal) == smallestDiff);
closestCoord = [x(closestPoint) y1(closestPoint)];
residual = smallestDiff;
% plot to show progressive zooming in
figure; hold on;
yline(z, 'r--');
plot(x, y1);
plot(x(closestPoint), y1(closestPoint), 'ro');
grid on;
pause; % press any key to continue
close;
% show progress
disp([ num2str(iteration) ' ' num2str(closestCoord(1)) ', ' num2str(closestCoord(2)) ', residual: ' num2str(residual)]);
% iterate
increment = increment/10;
x = x(closestPoint - 10):increment:x(closestPoint+10);
iteration = iteration + 1;
end
format long;
disp('converged at:');
closestCoord
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!