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 件のコメント

madhan ravi
madhan ravi 2020 年 6 月 1 日
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 ExchangeResizing and Reshaping Matrices についてさらに検索

製品

リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by