목차
일반적인 예제에 관해
* 할선법(Secant Method)적용과 그 프로그래밍(m-file)
* 최소제곱회귀분석을 통한 해의 근사값 해법(m-file)
* 멱방정식에 관한 해법과 고찰(m-file)
* 다중선형회귀분석,
* gauss 소거법,
* Newton보간법,
* Lagrange방정식과 그 Solution.
<추가>
각각에 대한 m-file 을 그대로 표시하여 MATLAB에 바로 적용가능.
* 할선법(Secant Method)적용과 그 프로그래밍(m-file)
* 최소제곱회귀분석을 통한 해의 근사값 해법(m-file)
* 멱방정식에 관한 해법과 고찰(m-file)
* 다중선형회귀분석,
* gauss 소거법,
* Newton보간법,
* Lagrange방정식과 그 Solution.
<추가>
각각에 대한 m-file 을 그대로 표시하여 MATLAB에 바로 적용가능.
본문내용
Solution : 10.000
>>
→ 구하고자 하는 결과 값은 X=4에 해당하는 f(x)=10.00 이다.
17.13번
문제가 요구하는 답을 정확하게 알 수 없어서 일단 문제에서 요구하는 방식으로 프로그램을 구성한 후 예제17.3번에 주어진 데이터를 활용하여 Lagrange방정식을 이용하여 계산한 결과값을 표시하였다. 하지만 아래의 프로그램은 주어진 값에 대해 몇차수의 Lagrange방정식을 이용할것인지, 그리고 그에 따른 x값과 y값을 읽어서 계산해주며, 입력한 x값들의 정확도를 판별까지 해주는 프로그램이므로 어떠한 Lagrange방정식 계산이라도 가능하다.
아래에는 위에서 설명한 Lagrange방정식 matlab 프로그램의 m-file이다.
→matlab m-file...
function lagrng(xx)
% Ex 17_13 Programming~~
%
disp('------------------------Ex 17_13--------------------');
disp('--------This Program is the "Lagrange Equation".----------');
%
% Espescially, This program request that input the "variables x,y"
% in this question 'Ex17_13'.
% Therefore, Input the X,Y value & Nth Equation~
n=input(' Enter number of "N"th Equation : ');
x=zeros(1,n+1);
y=zeros(1,n+1);
for ii=1:n+1
string=['Input X value ' int2str(ii) ': '];
x(ii)=input(string);
end
for jj=1:n+1
string=['Input Y value ' int2str(jj) ': '];
y(jj)=input(string);
end
% Display the Warning Massage~!
for kk=1:n;
if x(kk) <= x(kk+1)-10
msage= 'Entered value X is too far near x value to calculate !';
warning(msage);
end
end
% Calculating the Solution~!
sumx=0;
for i=1:n+1
product=y(i);
for j=1:n+1;
if i~=j;
product=product*(xx-x(j))/(x(i)-x(j));
end %if
end %for
sumx=sumx+product;
end %for
lag=sumx;
fprintf('\n\nThis is the "Lagrange Solution" : %10.6f\n', lag);
end
%
% Input form as below in the command windows.--> lagrng(2)
→Matlab Command Window에 입력한 후 출력되는 결과~
----------------------Ex 17_13----------------------
--------This Program is the "Lagrange Equation".-----------
Enter number of "N"th Equation : 3
Input X value 1: 1
Input X value 2: 4
Input X value 3: 6
Input X value 4: 5
Input Y value 1: 0
Input Y value 2: 1.386294
Input Y value 3: 1.791759
Input Y value 4: 1.609438
This is the "Lagrange Solution" : 0.628767
→ 구하고자 하는 결과 값은 X=2에 해당하는 f(x)=0.628767 이다.
<참고> 이때 x값의 정확성을 높이기 위해 x값들의 범위가 너무 넓으면 ‘주의’하라는 Warning문구가 나오게 된다.
------------------------Ex 17_13----------------------
-------This Program is the "Lagrange Equation".-------
Enter number of "N"th Equation : 3
Input X value 1: 1
Input X value 2: 11
Input X value 3: 20
Input X value 4: 33
Input Y value 1: 0
Input Y value 2: 2.397895
Input Y value 3: 2.995732
Input Y value 4: 3.496507
Warning: Entered value X is too far near x value to calculate !
> In lagrng at 25
Warning: Entered value X is too far near x value to calculate !
> In lagrng at 25
This is the "Lagrange Solution" : 0.361680
또한 같은 ln(2)에 대해 서로 다른 결과값이 출력된다.
>>
→ 구하고자 하는 결과 값은 X=4에 해당하는 f(x)=10.00 이다.
17.13번
문제가 요구하는 답을 정확하게 알 수 없어서 일단 문제에서 요구하는 방식으로 프로그램을 구성한 후 예제17.3번에 주어진 데이터를 활용하여 Lagrange방정식을 이용하여 계산한 결과값을 표시하였다. 하지만 아래의 프로그램은 주어진 값에 대해 몇차수의 Lagrange방정식을 이용할것인지, 그리고 그에 따른 x값과 y값을 읽어서 계산해주며, 입력한 x값들의 정확도를 판별까지 해주는 프로그램이므로 어떠한 Lagrange방정식 계산이라도 가능하다.
아래에는 위에서 설명한 Lagrange방정식 matlab 프로그램의 m-file이다.
→matlab m-file...
function lagrng(xx)
% Ex 17_13 Programming~~
%
disp('------------------------Ex 17_13--------------------');
disp('--------This Program is the "Lagrange Equation".----------');
%
% Espescially, This program request that input the "variables x,y"
% in this question 'Ex17_13'.
% Therefore, Input the X,Y value & Nth Equation~
n=input(' Enter number of "N"th Equation : ');
x=zeros(1,n+1);
y=zeros(1,n+1);
for ii=1:n+1
string=['Input X value ' int2str(ii) ': '];
x(ii)=input(string);
end
for jj=1:n+1
string=['Input Y value ' int2str(jj) ': '];
y(jj)=input(string);
end
% Display the Warning Massage~!
for kk=1:n;
if x(kk) <= x(kk+1)-10
msage= 'Entered value X is too far near x value to calculate !';
warning(msage);
end
end
% Calculating the Solution~!
sumx=0;
for i=1:n+1
product=y(i);
for j=1:n+1;
if i~=j;
product=product*(xx-x(j))/(x(i)-x(j));
end %if
end %for
sumx=sumx+product;
end %for
lag=sumx;
fprintf('\n\nThis is the "Lagrange Solution" : %10.6f\n', lag);
end
%
% Input form as below in the command windows.--> lagrng(2)
→Matlab Command Window에 입력한 후 출력되는 결과~
----------------------Ex 17_13----------------------
--------This Program is the "Lagrange Equation".-----------
Enter number of "N"th Equation : 3
Input X value 1: 1
Input X value 2: 4
Input X value 3: 6
Input X value 4: 5
Input Y value 1: 0
Input Y value 2: 1.386294
Input Y value 3: 1.791759
Input Y value 4: 1.609438
This is the "Lagrange Solution" : 0.628767
→ 구하고자 하는 결과 값은 X=2에 해당하는 f(x)=0.628767 이다.
<참고> 이때 x값의 정확성을 높이기 위해 x값들의 범위가 너무 넓으면 ‘주의’하라는 Warning문구가 나오게 된다.
------------------------Ex 17_13----------------------
-------This Program is the "Lagrange Equation".-------
Enter number of "N"th Equation : 3
Input X value 1: 1
Input X value 2: 11
Input X value 3: 20
Input X value 4: 33
Input Y value 1: 0
Input Y value 2: 2.397895
Input Y value 3: 2.995732
Input Y value 4: 3.496507
Warning: Entered value X is too far near x value to calculate !
> In lagrng at 25
Warning: Entered value X is too far near x value to calculate !
> In lagrng at 25
This is the "Lagrange Solution" : 0.361680
또한 같은 ln(2)에 대해 서로 다른 결과값이 출력된다.
소개글