2016-03-27 28 views
2

Girişler: noktaOctave'de bir fonksiyonun türevini nasıl bulabilirim?

Yf x-değerleri tutan

Xf = ve dizi noktaları yöntem = 2-noktalı ileri fark, 2- y-değerleri içeren bir dizi = nokta geri fark, 3-noktalı merkezi fark, 5 puanlık bir merkezi fark

Çıkışlar:

X Ar = seçili yöntemin kullanılabildiği geçerli x değerlerini içeren ışını (örneğin Xf dizisinin üst sınırında ileriye doğru fark yöntemini kullanamazsınız çünkü bundan sonra değer yoktur)

DF = noktalarda türevleri

bir komut dosyası noktaları seti verin ve sonra kullanmadan 4 farklı yöntem kullanılarak noktalarda türevleri hesaplamak için gereken bir dahilidiff gibi türev fonksiyonu. Onlardan birini kodlamak için biraz yardım istiyorum ve sonra geri kalanını nasıl yapacağımı anlayabileceğimi düşünüyorum.

2-point forward difference

girişimim:

[a, minidx] = min(Xf); 
[b, maxidx] = max(Xf); 
n = 10; 
h = (b-a)/n; 
f = (x .^3) .* e.^(-x) .* cos(x); 

If method = "forward" #Input by user 

    X = [min(Xf), Xf(maxidx-1)]; 
    for k = min(Xf):n # not sure if this is the right iteration range... 

     f(1) = f(x-2*h) + 8*f(x +h); 
     f(2) = 8*f(x-h) + f(x+2*h); 
     DF = (f1-f2)/(12*h); 

    endfor 
endif 

cevap

-1

Bunu daha önce cevaplanmış olmalıdır eminim. İşte

diff Difference and approximate derivative. 
    diff(X), for a vector X, is [X(2)-X(1) X(3)-X(2) ... X(n)-X(n-1)]. 
    diff(X), for a matrix X, is the matrix of row differences, 
      [X(2:n,:) - X(1:n-1,:)]. 
    diff(X), for an N-D array X, is the difference along the first 
      non-singleton dimension of X. 
    diff(X,N) is the N-th order difference along the first non-singleton 
      dimension (denote it by DIM). If N >= size(X,DIM), diff takes 
      successive differences along the next non-singleton dimension. 
    diff(X,N,DIM) is the Nth difference function along dimension DIM. 
     If N >= size(X,DIM), diff returns an empty array. 

Examples: 
    h = .001; x = 0:h:pi; 
    diff(sin(x.^2))/h is an approximation to 2*cos(x.^2).*x 
    diff((1:10).^2) is 3:2:19 

    If X = [3 7 5 
      0 9 2] 
    then diff(X,1,1) is [-3 2 -3], diff(X,1,2) is [4 -2 
                9 -7], 
    diff(X,2,2) is the 2nd order difference along the dimension 2, and 
    diff(X,3,2) is the empty matrix. 

başka bir örnek olduğu:

xp= diff(xf); 
    yp= diff(yf); 

    % derivative: 
    dydx=yp./xp; 
    % also try: 
    dydx1=gradient(yf)./gradient(xf) 
0

https://wiki.octave.org/Symbolic_package

% this is just a formula to start with, 
% have fun and change it if you want to. 
f = @(x) x.^2 + 3*x - 1 + 5*x.*sin(x); 
% these next lines take the Anonymous function into a symbolic formula 
pkg load symbolic 
syms x; 
ff = f(x); 
% now calculate the derivative of the function 
ffd = diff(ff, x) 
% answer is ffd = (sym) 5*x*cos(x) + 2*x + 5*sin(x) + 3 
... 
Yine burada Matlab diocumentation bazı şeyler
İlgili konular