Find x for y=0 using interpolation

Hello there,
I was given the task to find the x value where y is 0 using interpolation. And I just can not figure it out on my own.
First of all: Here is my complete code:
load Daten_Wurfparabel.mat
h_index = find(y<0,1) ;
index = [ h_index-1 h_index] ;
xx = x(index) ;
yy = y(index) ;
x0 = xx(1)+1 ;
y0 = 0 ;
w = interp1( x , y , xx ) ;
% Plot
figure (1), clf
subplot(2,1,1)
hold on , grid on
plot(x ,y ,'ko-')
plot(xx,yy,'r*','markersize',10)
xlabel('x [m]'), ylabel('y [m]')
title('Wurfparabel y über x')
subplot(2,1,2)
hold on , grid on
plot(xx ,yy ,'ko-')
plot(xx,yy,'r*','markersize',10)
plot(x0, y0, 'ko')
xlim([19 21]), ylim([-0.5 1])
xlabel('x [m]'), ylabel('y [m]')
title('Vergrößerung des Nulldurchgangs')
% Ausgabe im CW
disp('Wurfweite [m] = x-Wert bei Nulldurchgang y = 0')
disp(x0(1))
As you can see. I'm loading data from a .mat file (x is a 21x1 matrix and y is a 21x1 matrix). I have attached the file below. If you paste my code into matlab, you can see that I'm off by a few centimeters. The solution should be 20.2479m and mine is currently 20.3990m.
Can someone please help me out?

 Respuesta aceptada

KSSV
KSSV el 1 de Jun. de 2020
Editada: KSSV el 1 de Jun. de 2020
load ("Daten_Wurfparabel.mat") ;
yi = 0 ;
xi = interp1(y,x,0) ;
[xi yi]
plot(x,y,'b')
hold on
plot(xi,yi,'*r')

5 comentarios

Perhaps you meant
[xi,yi] % ?
KSSV
KSSV el 1 de Jun. de 2020
Yes...edited the answer.
Valentin Messerle
Valentin Messerle el 1 de Jun. de 2020
I'm sorry but I can't get this to work inside my code... :(
KSSV
KSSV el 1 de Jun. de 2020
Edited the code.
Valentin Messerle
Valentin Messerle el 1 de Jun. de 2020
Thank you so so much. Got it now.

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2018b

Preguntada:

el 1 de Jun. de 2020

Comentada:

el 1 de Jun. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by