반응형

이것저것 배운것 88

falseposition - 가(假)위치법

function root=falseposition(func, x1, x2, threshold)% x1, x2 : 초기경계값% threshold: 반복여부를 결정하는 임계값% root: 가위치법에 의해 최종적으로 구해진 근의 근사값 if feval(func, x1)*feval(func, x2) > 0 % feval(func,x)는 함수값을 계산하는 함수 disp('해는 이 구간에 없습니다.') returnend %rel_error=100.0; % 상대오차 초기값%x3=x1;j=0;fprintf('| iteration | x | error |\n')while(1) j=j+1;% xold=x3; x3=x2-feval(func, x2)*(x1-x2)/(feval(func, x1) - feval(func, x2)..

Bisection - 이분법

function root = bisection(func, x1, x2, threshold)%func = 함수%x1, x2 = 범위%threshold = 오차율 if feval(func, x1)*feval(func, x2) > 0 % feval(func,x) disp('해는 이 구간에 없습니다..') returnend j = 0;fprintf('| iteration | x | error |\n') while(1) % begin of while j=j+1; %iteration번호 x3=(x1+x2)/2; % new x3 계산 if feval(func, x2)*feval(func, x3) < 0 xold=x1; x1=x3; else xold=x2; x2=x3; end if x3 ~= 0 rel_error=ab..

Gauss_Jordan 소거법

function x=gauss_jordan2(A)% A: 계수행렬% I: 단위행렬% x: inv(A)의 계산값 [m1,k1]=size(A);% [m2,k2]=size(b); x=zeros(m1,k2);I=eye(m1); % 상삼각 행력 형성for i=1:m1-1 m=-A(i+1:m1,i)/A(i,i); A(i+1:m1,:)=A(i+1:m1,:)+m*A(i,:); I(i+1:m1,:)=I(i+1:m1,:)+m*I(i,:);end%A%I % 하삼각 행렬 형성for i=1:m1-1 for j=i+1:k1 m=-A(i,j)/A(j,j); A(i,:)=A(i,:)+m*A(j,:); I(i,:)=I(i,:)+m*I(j,:); end %A %Iend%A%Ifor i=1:m1 x(i,:)=I(i,:)/A(i,i); A..