八度函数的多项式插值

时间:2016-03-20 23:36:56

标签: matlab octave interpolation linear-interpolation

我需要使用多项式插值来插值函数,但我不确定如何将该部分编码为 get 多项式及其系数:

enter image description here

我的功能:

xs = 0:0.5:4;
ys = fx(xs);

我的9个样本值:

n = 2;
x(1) = xs; # not sure if this is correct

for k=1:n-1

    for j=k+1:n

        p = ((x(1) - x(j)) / x(1) - x(j))* fx(x(j));
    endfor

endfor

我的尝试:

#Months
#January=0
#February=31
#March=60
#April=91
#May=121
#June=152
#July=182
#August=213
#September=244
#October=274
#November=305
#December=335

monthvalue = -1

#Title
print("Convert: Date to day and day to date.")

#user inputs a date
month = input("\nPick a Month (Make sure to capitalize the first letter): ")
month = month.lower()
month = month[:1].capitalize() + month[1:]

if(month=="January"):
    monthvalue = 0

if(month=="February"):
    monthvalue = 31

if(month=="March"):
    monthvalue = 60

if(month=="April"):
    monthvalue = 91

if(month=="May"):
    monthvalue = 121

if(month=="June"):
    monthvalue = 152

if(month=="July"):
    monthvalue = 182

if(month=="August"):
    monthvalue = 213

if(month=="September"):
    monthvalue = 244

if(month=="October"):
    monthvalue = 274

if(month=="November"):
    monthvalue = 305

if(month=="December"):
    monthvalue = 335

if(monthvalue<0):
    print("Error, you have not entered a valid month.")
    xwdwa=input("\nPress any key to continue...")
    exit(0)

day=int(input("Pick the day of the date you wish to input: "))
if day<1 or day>31:
    print("Error, no months have greater than 31 days or less than 1 day.")

total = monthvalue + day

print("Your date is ", total, " days into a leap year.")
exitvar = input("Press any key to continue.")

但是我觉得很失落,我不太明白。有人可以帮助我吗?

0 个答案:

没有答案