필터 지우기
필터 지우기

unknown code- understand it up to the for loop but am lost from there. Can anyone lend a hand? thanks.

조회 수: 1 (최근 30일)
dat=load('data.dat')
a=dat(:,1)
b=dat(:,2)
s=size(a)
s=s(1)
out=zeros(s,1)
for n=1:s
out(n)=(b(n+1)-b(n-1))/(a(n+1)-a(n-1))
end
c=[a out]

채택된 답변

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020년 3월 15일
What the code was supposed to be? it looks like the variable out is suppose to be the numerical derivative of b with respect to a. If the distance between each "a" is uniform and increasing, than this is the central scheme for 1st order differentiation with 2nd order accuracy and the line describe basically .
  댓글 수: 2
Josh Williams
Josh Williams 2020년 3월 15일
not too sure what the code is supposed to be, thats what i have been tasked to find out. I can see now where your coming from with the derivations though. what does the line s=s(1) do?
Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020년 3월 15일
Size returns two values, so s(1) saves the first dimension in order to perform the loop and size assignment. It would be the same if you did:
s=size(a,1);
out=zeros(s,1);
...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by