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?

 채택된 답변

KSSV
KSSV 2020년 6월 1일
편집: KSSV 2020년 6월 1일

0 개 추천

load ("Daten_Wurfparabel.mat") ;
yi = 0 ;
xi = interp1(y,x,0) ;
[xi yi]
plot(x,y,'b')
hold on
plot(xi,yi,'*r')

댓글 수: 5

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2020년 6월 1일

댓글:

2020년 6월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by