필터 지우기
필터 지우기

t=a:h:b;

조회 수: 5 (최근 30일)
Mos_bad
Mos_bad 2017년 9월 8일
편집: James Tursa 2017년 9월 9일
I need to code an iteration for the below algorithm:
% a,h,b,s are constants.
t=a:h:b;y(0)=s;
f(k)(x,t)=t(k)+y(k);
y(k+1)=y(k)+h*f(k);
please help me how to use for loop for this iteration.
  댓글 수: 1
James Tursa
James Tursa 2017년 9월 8일
편집: James Tursa 2017년 9월 8일
I assume that the statement y(0)=s is meant to imply that the initial value of y at the initial value of t (which is "a" in this case) is "s"?
This is just numerical integration using the Euler method.

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

답변 (1개)

James Tursa
James Tursa 2017년 9월 8일
편집: James Tursa 2017년 9월 9일
An outline of the loop:
s = whatever
a = whatever
b = whatever
h = whatever
y = zeros(size(t));
y(1) = s;
for k=1:numel(t)-1
f = ________; % <-- you fill the blanks in based on your formula from above
y(k+1) = _______; % <-- you fill the blanks in based on your formula above
end
If you want to save each of the derivative values, then you can use f(k) in the loop instead of just f. (And also initialize f = zeros(size(t)) prior to the loop)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by