Writing linear interpolation code
2 ビュー (過去 30 日間)
古いコメントを表示
I need to write a matlab function lin_interpol(x_pt,y_pt) which, given vectors of data points x pt, y pt, returns the linear interpolating function f. I need to use find(x > x pt) to find the locations of the entries in x pt which are > x. I also need to compare the output with that of the matlab function interp1(x_pt,y_pt,xx), which evaluates the linear interpolant through x_pt, y_pt at the points in xx.
0 件のコメント
回答 (1 件)
Image Analyst
2020 年 5 月 12 日
編集済み: Image Analyst
2020 年 5 月 12 日
You can't have spaces in variable names, or two input arguments to a function without a comma between them, so lin_interpol(x pt,y pt) really needs to be lin_interpol(xpt, ypt) or lin_interpol(x, ypt, y, ypt) depending on if you're passing in 2 or 4 arguments.
And when you say interp1(x pt,y pt,xx) is that 3 arguments, or 5? If you're going to have a variable number of arguments (which complicates things) you're going to have to do
function interp1(varargin)
and then look at nargin and extract out the correct things depending on how many arguments nargin tells you are there.
Is pt or xpt a scalar? Or another vector? If it's another vector, then I presume you have an x vector to compare xpt against? If xpt is a scalar, then you still need an x vector that you can plot, unless you're going to assume some range and create one.
See my attached polyfit demo.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!