게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
[질문] 매트랩에서 미분 어떻게 하나요?
게시물ID : programmer_5753짧은주소 복사하기
작성자 : 섹시스님
추천 : 0
조회수 : 3268회
댓글수 : 2개
등록시간 : 2014/10/03 07:17:48
옵션
  • 본인삭제금지
function methods = prj2() 
a = input('enter the function', 's'); 
f = inline(a); 
itr = 0; 
lim = 0.00001; 
c = input('enter the method number, 1 for secant, 2 for newton, 3 for QII'); 
error = 1; 
while (error>lim) 
    i = 1; 
    if (c == 1) 
        x(1) = input('enter the first guess'); 
        x(2) = input('enter the second guess'); 
        while (error>lim) 
            x(i+2)=x(i+1)-(f(x(i+1))*(x(i+1)-x(i))/(f(x(i+1))-f(x(i)))); 
            i = i + 1; 
            error = x(i+1)-x(i); 
            itr = itr + 1 
            root = x(i+1) 
        end 
    elseif (c == 2) 
        x(1) = input('enter the initial x'); 
        while (error > lim) 
            x(i+1)=x(i)-((f(x(i)))/diff(f(x(i)))); 
            error = abs(x(i+1)-x(i)); 
            itr = itr + 1; 
            i = i + 1; 
            root = x(i); 
        end 
    elseif (c == 3) 
        x(1) = input('enter the first x'); 
        x(2) = input('enter the second x'); 
        x(3) = input('enter the third x'); 
        while (error > lim) 
            a = ((f(x(i+1))*f(x(i)))/((f(x(i+2))-(f(x(i+1))))*(f(x(i+2))-f(x(i)))))*(x(i+2)); 
            b = ((f(x(i+2))*f(x(i)))/((f(x(i+1))-(f(x(i+2))))*(f(x(i+1))-f(x(i)))))*(x(i+1)); 
            c = ((f(x(i+1))*f(x(i+2)))/((f(x(i))-(f(x(i+1))))*(f(x(i))-f(x(i+2)))))*(x(i)); 
            x(i+3) = a + b + c; i = i + 1; 
            error = abs(x(i+1)-x(i)); 
            itr = itr + 1 
            root = x(i) 
        end 
    else 
        disp(sprintf('no')); 
    end 
 end

거의 처음 매트랩으로 숙제하는데요 (미분 과목이에요)
매트랩으로 과제를 받아서요...
line 20에 보시면 else if (c==2)가 있는데요
그 문장에 들어가는 공식의 분모부분을 보시면
diff(f(x(i)))) 부분이 있는데요
유저가 입력하는 f 함수의 미분식을 계산하게 해야하는데
알고리듬이나 기본 메소드를 사용해서 자동적으로 계산을 못할까요? 
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호