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 commentaires

Straightforward:
lv = find(y1 <= z, 1, 'last');
isx = interp1(y1(lv+[-1 1]),x(lv+[-1 1]),z)
producing:
isx =
-99.9323
Q.E.D.!
madhan ravi
madhan ravi le 14 Juil 2020
Right ;)
Star Strider
Star Strider le 14 Juil 2020
Of course!
Star Strider
Star Strider le 15 Juil 2020
Kenneth Bisgaard Cristensen —
With respect to my code, the (x,y) coordinates of the intercept are (isx,z).
Kenneth Bisgaard Cristensen
Kenneth Bisgaard Cristensen le 15 Juil 2020
Yeah, got that. Thanks for the help :)
Star Strider
Star Strider le 15 Juil 2020
My pleasure!

Connectez-vous pour commenter.

 Réponse acceptée

madhan ravi
madhan ravi le 14 Juil 2020

0 votes

x=[-150:5:0, 5:100];
INTERSECTION = interp1(y1,x,z)

3 commentaires

Kenneth Bisgaard Cristensen
Kenneth Bisgaard Cristensen le 14 Juil 2020
Modifié(e) : Kenneth Bisgaard Cristensen le 15 Juil 2020
Thank you so much, I have tried to apply it to this. But I get an error I don't undestand. It says:
Error using griddedInterpolant
The number of input coordinate arrays must match the dimensions of the sample values.
Error in interp2>makegriddedinterp (line 228)
F = griddedInterpolant(varargin{:});
Error in interp2 (line 112)
F = makegriddedinterp({X,Y},V,method,extrap);
Error in Impact_Temp (line 23)
p2=interp2(y2,x,z)
x=[-20:5:0, 5:80]
hold on
z=50
yline((z),'--r');
f1=[-9E-05 0.0016 1.2251 23.754]
f2=[-1E-06 5E-06 0.0141 0.1642 -3.5317]
y1=polyval(f1,x)
y2=polyval(f2,x)
y1(y1<0)=0;
y2(y2<0)=0;
plot(x,y1,'g')
plot(x,y2,'g')
p1=interp1(y1,x,z)
plot(p1,z,'bx')
p2=interp2(y2,x,z)
plot(p2,z,'bx')
grid on
hold off
p2 = interp1(y2,x,z)
Kenneth Bisgaard Cristensen
Kenneth Bisgaard Cristensen le 14 Juil 2020
It still gives me this error:
Error using matlab.internal.math.interp1
Sample points must be unique and sorted in ascending order.
Error in interp1 (line 154)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
Error in Impact_Temp (line 23)
p2 = interp1(y2,x,z)

Connectez-vous pour commenter.

Plus de réponses (1)

neil jerome
neil jerome le 14 Juil 2020

0 votes

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

Catégories

En savoir plus sur Labels and Annotations dans Centre d'aide et File Exchange

Produits

Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by