I wrote this function, which should calculates the values of the linear interpolation

4 ビュー (過去 30 日間)
Ihor
Ihor 2022 年 12 月 10 日
編集済み: Matt J 2022 年 12 月 10 日
I wrote this function, which should calculates the values of the linear interpolation function x values given by Xl = [xmin,
xmax]:
function [ X, Y ] = linterp( a, b, Xl, n ) % Xl = [xmin, xmax]
x = linspace( Xl(1), Xl(2), n + 1 ) ;
result = a*x + b ;
X = result(1) ;
Y = result(2) ;
end
I compared the results with polyval
Y2 = polyval( [ a b ], X )
and in 2 out of 3 cases the function works...
What is going wrong?
for linterp( 1, 0, [0 1], 2 ) - the answer should be 0, but it 0.5
for other examples answers are great.
  3 件のコメント
Ihor
Ihor 2022 年 12 月 10 日
Thank you so much, I want my function to return me the same answer as Y2 = polyval( [ a b ], X ) for the same values.
I want that Y from my function will be equal to Y2 from polyval function. For other input data Y == Y2, but for 1, 0, [0 1], 2 - not.
Torsten
Torsten 2022 年 12 月 10 日
Y = polyval( [ 1 0 ], [0 1] )
Y = 1×2
0 1
This call to "polyval" evaluates the linear function p(x) = 1*x + 0 = x at x=0 and x=1.
What does this has to do with interpolation ?

サインインしてコメントする。

採用された回答

Matt J
Matt J 2022 年 12 月 10 日
編集済み: Matt J 2022 年 12 月 10 日
function [ X, Y ] = linterp( a, b, Xl, n ) % Xl = [xmin, xmax]
X = linspace( Xl(1), Xl(2), n + 1 ) ;
Y = a*X + b ;
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by