- TI nspire
[TI-nspire] (프로그램) 보간법 (선형, 다항식) Linear & Polynomial Interpolation
Linear & Polynomial Interpolation for TI-Nspire
Ver 1.2
by allcalc.org
-----
Usage
1. Input each x1,y1,x2,y2... var_x and var_y alternately
or matrix (2*n) type DATA at prompt for DATA.x
2. When you finished to insert DATA, type "end" at prompt for DATA.x
3. If there's no error with DATA sets, function i.linear() and i.polynomial() will be created.
4. Use functions to find unkown value "y"
5. Additionally, data.sub(matrix) and data.subx,data.suby(list) will be made too.
Caution
To stop a program that contains a Request command inside an infinite loop:
• Handheld: Hold down the "on" key and press "enter" repeatedly.
• Windows?: Hold down the "F12" key and press "Enter" repeatedly.
• Macintosh?: Hold down the "F5" key and press "Enter" repeatedly.
1. 기능
기본 데이터를 입력하여 선형 보간법에 따른 조각함수(Piecewise Function) i.linear(x) 와 다항식 보간법(라그랑주)에 따른 함수 i.polynomial(x) 를 생성합니다.
생성된 함수를 이용하여 특정 값(x)에서의, 보간법 예상치(y)를 구합니다.
2. 사용법
2-a. 기본 데이터 입력
- 프로그램의 실행 : inter()
- 기본 DATA 입력
방법 1 : 번갈아 입력 : x1, y1, x2, y2, x3, y3... , (입력이 끝나면 e 또는 end 를 입력)
혹은
방법 2 : 2×N 행렬을 한꺼번에 입력 : x값 입력시에 입력 - DATA 입력시
주의사항
* x 는 크기 순서로 입력할 필요 없음 (자동 sort 됨)
* (x,y) 데이터 쌍이 중복 되어도 괜찮으나, 하나의 x값에 둘 이상의 y값이 존재하면 에러 발생
2-b. 결과 함수의 이용
- 2-a의 입력이 끝나면 결과함수로 사용할 변수명을 물어봄
- 결과함수를 이용하여 추정값을 구함
ex) i.linear(3) 【Enter】 : x=3일 때의 추정값을 구함
2-c. 생성된 함수의 확인 http://www.allcalc.org/5752
- 【MENU】 【1】 【2】 (Action - Recall Definition) 명령으로 사용자 함수에 현재 정의되어 있는 내용을 확인할 수 있습니다.
3. 결과


4. 소스코드
Define LibPub inter()=
Prgm
:© Linear and Polynomial Interpolation for TI-nspire
:© Ver 1.2
:© by allcalc (allcalc.org)
:
:© Part A: Input DATA
:
:Local n,data.x,data.y,data
:n:=0
:Loop
: Request "data.x or matrix(2×n) or END",data.x,0
:
:© Exit Loop Condition
: If string(data.x)="end" or string(data.x)="END" or string(data.x)="e" Then
: Exit
: EndIf
:
:© Adding Data
: n+1→n
:© Adding Data with Matrix
: If getType(data.x)="MAT" Then
: n+dim(data.x)[2]-1→n
: If n=dim(data.x)[2] Then
: data.x→data
: Else
: augment(data,data.x)→data
: EndIf
:© Adding Each Data Pair
: Else
: Request "data.y for x="&string(data.x),data.y,0
: If string(data.y)="end" or string(data.y)="END" Then
: Exit
: EndIf
: If n=1 Then
:[[data.x][data.y]]→data
: Else
: augment(data,[[data.x][data.y]])→data
: EndIf
: EndIf
:EndLoop
:
:© Part B : Data Processing
:
:© Part B1 : Data Processing
:Local data.listx,data.listy
:mat▶list(data[1])→data.listx
:mat▶list(data[2])→data.listy
:SortA data.listx,data.listy
:colAugment(list▶mat(data.listx),list▶mat(data.listy))→data
:
:© Part B2 : Section Verification&Consolidation and Slope
:© Verification
:Local i,j,dup
:newList(n)→dup
:For i,1,n-1
: If data[1,i]=data[1,i+1] Then
: 1→dup[i+1]
: If data[2,i]≠data[2,i+1] Then
: Disp "Data Error : ",[["x"]["y"]],"=",subMat(data,1,i,2,i+1)
: Stop
: EndIf
: EndIf
:EndFor
:
:© Consolidation
:© Local data.sub : Make data.sub global var
:subMat(data,1,1,2,1)→data.sub
:For i,2,n
: If dup[i]=0 Then
: augment(data.sub,subMat(data,1,i,2,i))→data.sub
: EndIf
:EndFor
:
:mat▶list(data.sub[1])→data.subx
:mat▶list(data.sub[2])→data.suby
:Disp "data.sub",[["x"]["y"]],"=",data.sub
:
:© Slope for Linear Interpolation
:Local sub.slope,sub.n
:dim(data.sub)[2]→sub.n
:newList(sub.n-1)→sub.slope
:For i,1,sub.n-1
:((data.sub[2,i+1]-data.sub[2,i])/(data.sub[1,i+1]-data.sub[1,i]))→sub.slope[i]
:EndFor
:
:
:© Part C1 : Out Polynomial Function as i.polynomial(x)
:Local poly,f_name
:"i"→f_name
:Request "Input Function name",f_name,0
:If getType(f_name)="NUM" Then
:"i"&string(f_name)→f_name
:Else
: If getType(f_name)≠"STR" Then
: string(f_name)→f_name
: EndIf
:EndIf
:
:"Define "&f_name&".polynomial(var_x)="&string(∑(data.sub[2,i]*∏(when(i≠j,((var_x-data.sub[1,j])/(data.sub[1,i]-data.sub[1,j])),1),j,1,sub.n),i,1,sub.n))→poly
:expr(poly)
:
:© Part C2 : Out Piecewise Linear Interpolation Function as i.linear(x)
:
:Local pf,random.x
:"Define "&f_name&".linear(x)=piecewise("→pf
:For i,1,sub.n-1
: pf&string(sub.slope[i]*(x-data.sub[1,i])+data.sub[2,i])&","&string(data.sub[1,i]≤x≤data.sub[1,i+1])&","→pf
:EndFor
:left(pf,dim(pf)-1)&")"→pf
:expr(pf)
:
:© Part C3 : Display functions usage
:rand()*(data.sub[1,sub.n]-data.sub[1,1])+data.sub[1,1]→random.x
:Disp "Usage : "&f_name&".linear("&string(random.x)&")=",#(f_name&".linear")(random.x)
:Disp f_name&".polynomial("&string(random.x)&")=",#(f_name&".polynomial")(random.x)
:
:Disp "Linear function is =",pf
:Disp "Polynomial function is =",poly
:EndPrgm
댓글10
-
세상의모든계산기
이 프로그램은 선형 보간법과 라그랑주 보간법을 동시에 구하는 프로그램입니다.
간단하게 선형 보간법의 결과만 필요한 경우에는
별도의 프로그램 파일 혹은 라이브러리를 사용하기보다 statistics(통계) 의 Linear Regression 기능을 이용하는 것이 편합니다.(예제 : http://www.allcalc.org/7826 )
- 1
-
세상의모든계산기
예를 들어
http://www.allcalc.org/2387 의 댓글에 있는 예제를 푼다면
【inter()】
【200】【1250】
【300】【1890】
【e】【Enter】
순으로 DATA 입력을 마치고【i.linear(250)】
으로 목표값을 찾습니다.* 이렇게 DATA 가 2쌍 뿐인 경우에는 i.linear() 함수와 i.polynomial() 함수가 동일한 결과값을 출력합니다.
(단, linear() 함수는 조각함수라서 데이터 범위 안쪽의 값만을 구할 수 있습니다.) - 1
- 2
- 3
- 4
-
3
세상의모든계산기
inter() 함수 결과에 생성된 함수를 출력하는 명령(Disp)을 추가했습니다.
한 줄 표기되어서 알아보기 어렵다고 느끼실 때는
- Menu - Action - Recall Definition
- 아니면 한 줄 표기된 결과를 선택해서 입력창에 붙여넣기 하신 다음 [enter] 하시면 입체적 표현으로 바뀝니다.

세상의모든계산기 님의 최근 댓글
링크가 깨졌다고 하시니 404 에러가 나는 아래 링크를 말씀하시는 것 같은데 https://digilander.libero.it/fpirozzi/fourier.zip 이것은 TI-89 / TI-92 용 파일이며 [TI-92][TI-89] Fourier Transform Library https://allcalc.org/52455 링크의 Attached files + 안에 있습니다. 2026 09.11 본문에 사용된 nspire 용 파일은 본문 하단에 Attached files + 안에 있습니다. 클릭하면 표시됩니다. 2026 09.11 이 사이트에 올라와 있는 첨부 파일은 본문 하단에 있는 [Attached files +] 버튼을 눌러야 리스트가 보입니다. 2026 09.07 이렇게 질문하시면 무슨 파일인지 알 수가 없습니다. 해당 글에 댓글을 쓰시는게 최선이며, 권한 문제로 그것이 불가능하면 해당 글의 주소를 붙여넣으시거나, 제목 전체를 복사해 넣으셔야 구분이 됩니다. 2026 09.07 - claude AI는 l-c*r^2 을 1-c*r^2 으로 잘못 읽고 표시하고 있습니다. - TI-nspire CAS 계산기에 l-c*r^2 ≥0 을 조건에 추가해 계산해 보아도 결과는 바뀌지 않습니다. 2026 07.20