- 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] 하시면 입체적 표현으로 바뀝니다.

세상의모든계산기 님의 최근 댓글
2번 사진 3개 사진 공통적으로 구석(corner) 에 증상이 있다는 특징이 있네요. 영상 찾아보니 이 가능성이 가장 높은 듯 합니다. https://www.youtube.com/watch?v=zxRBohepzwc ㄴ Liquid Crystal Leakage (액정 누설). ㄴ 손으로 밀어내니 주변으로 밀려나네요. 그래서 점으로 보이기도 하구요. 2025 10.29 500! 의 십진수 근사값 확인 500! = 1.22013682599111006870123878542304692625357434280319284219241358838 × 10^(1134) (참값, 울프람 알파) 2025 10.29 관련 라이브러리 https://allcalc.org/56263 sgn(x) 내장된 부호 함수(signum function)와 달리, 이 함수의 sgn(0)은 0을 반환합니다. 2025 10.29 라이브러리로 사용할 수 있습니다. (제작자 추천) 1. mylib 폴더에 넣기 2. Actions ➡️ library ➡️ refresh libraries 실행 하기 2025 10.29 ChatGPT-5 기호(÷, /, :) 자체는 의미적으로 같은 “나눗셈”을 뜻하지만, 문맥(사람이 쓰는 수학 vs 컴퓨터/프로그래밍)에 따라 해석 우선순위가 달라질 수 있습니다. 🔹 1️⃣ 전통 수학 표기 — ÷, /, : 수학 교과서, 논문, 일반 문서 등에서는 셋 다 의미적으로 “나누기”로 간주됩니다. 즉, 48÷2(9+3), 48/2(9+3), 48:2(9+3) 은 같은 의미로 받아들여야 합니다. 모두 사람의 수학 관행적 해석이 적용되어 48 ÷ 2 × (9+3) = 288 로 처리되죠. 즉, 기호가 바뀌어도 결과는 바뀌지 않습니다. 🔹 2️⃣ 컴퓨터·프로그래밍 문맥에서 / 사용 시 컴퓨터는 “생략된 곱셈(implicit multiplication)”을 따로 구분하지 못합니다. 따라서 다음 두 식은 완전히 다르게 인식됩니다. 표현 파이썬 등에서 해석 결과 48 / 2*(9+3) ((48 / 2) * (9+3)) 288 48 / 2(9+3) ❌ 문법 오류 (생략된 곱셈 인식 불가) — 즉, 컴퓨터 언어에서는 생략된 곱셈이 허용되지 않기 때문에, /는 반드시 명시적 *와 함께 써야 합니다. 🔹 3️⃣ “:” 기호의 경우 현대 수학에서는 “비율”을 나타내는 기호로 쓰입니다. a:b = \frac{a}{b} 따라서 (27 : 3(1+2)3) 같은 표현은 모호하거나 비표준적으로 간주됩니다. 대부분의 경우 계산기로는 입력 자체가 불가능합니다. ✅ 정리 기호 의미 결과 변화 주로 쓰이는 문맥 ÷ 나누기 없음 초중등 수학, 일반 표기 / 나누기 없음 (단, 프로그래밍에서는 생략 곱 불허) 수학/컴퓨터 : 비율 (또는 나누기 의미로 혼용) 보통 계산식에서는 사용 안 함 비, 비율 표기 🔹 결론 48 ÷ 2(9+3), 48/2(9+3), 48:2(9+3) 는 “수학적 의미”로는 동일하게 81로 해석됩니다. 하지만 프로그래밍이나 수식 파서(context) 에서는 /만 유효하고, 생략된 곱은 허용되지 않으며, :는 아예 다른 의미(비율)로 인식됩니다. 2025 10.28