Generating a function using an array

17 ビュー (過去 30 日間)
Brian Kettering
Brian Kettering 2020 年 8 月 26 日
編集済み: esat gulhan 2020 年 8 月 26 日
If I have an array of data. Is there a way to generate a function from the data contained in the array? That if I evaluated the function, it would generate the data equivelent to the array. The generated function will be used to find the local min and max (critical points) of the function.

回答 (2 件)

esat gulhan
esat gulhan 2020 年 8 月 26 日
maybe like this. if you send data it can be easier to choose the way of function. I used sin data and choose pchip.
x=[ 0 0.3142 0.6283 0.9425 1.2566 1.5708 1.8850 2.1991 2.5133 2.8274 3.1416 3.4558 3.7699 4.0841]
y=[ 0 0.3090 0.5878 0.8090 0.9511 1.0000 0.9511 0.8090 0.5878 0.3090 0.0000 -0.3090 -0.5878 -0.8090]
t=pchip(x,y) %Piecewise Cubic Hermite Interpolating Polynomial function of x y
ppval(t,2) %the value of function at 2
ppval(t,0) %the value of function at 0
plot(x,ppval(t,x))
findpeaks(ppval(t,x)) %local maksimum points
  2 件のコメント
Brian Kettering
Brian Kettering 2020 年 8 月 26 日
Here' the .csv file:
Brian Kettering
Brian Kettering 2020 年 8 月 26 日
Thanks for helping, but I keep getting the following error
Error using chckxy (line 30)
The X vector should have real elements.
Error in pchip (line 58)
[x,y,sizey] = chckxy(x,y);
Error in Untitled2 (line 11)
t=pchip(x,y) %Piecewise Cubic Hermite Interpolating Polynomial function of x y

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


esat gulhan
esat gulhan 2020 年 8 月 26 日
編集済み: esat gulhan 2020 年 8 月 26 日
Hi
can you try this
clear all;clc;
x=[ 0 0.3142 0.6283 0.9425 1.2566 1.5708 1.8850 2.1991 2.5133 2.8274 3.141 3.4558 3.76 4.08]
y=[ 0 0.3090 0.5878 0.8090 0.9511 1 0.9511 0.809 0.5878 0.3090 0.0 -0.309 -0.58 -0.8]
t=pchip(x,y) %Piecewise Cubic Hermite Interpolating Polynomial function of x y
ppval(t,2) %the value of function at 2
ppval(t,0) %the value of function at 0
plot(x,ppval(t,x))
findpeaks(ppval(t,x)) %local maksimum points

カテゴリ

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