필터 지우기
필터 지우기

Help with a loop that computes at each step

조회 수: 4 (최근 30일)
Lavorizia Vaughn
Lavorizia Vaughn 2021년 11월 13일
댓글: Lavorizia Vaughn 2021년 11월 14일
hi im doing an assignmenr where i have 5 different stepsizes that compose a row vector hs. i have 100/hs steps for which id like to compute the value th2 at each stepsize.
th1=1;
th2=1;
w1=0;
w2=0;
hs(1)=[0.05];
hs(2)=[0.05/2];
hs(3)=[0.05/4];
hs(4)=[0.05/8];
hs(5)=[1/1000];
th2s=[];
????????????
for i=1:N
k1= h*fpend(y);
k2=h*fpend(y + k1/2);
k3=h*fpend(y + k2/2);
k4= h*fpend(y + k3);
y = y + (k1 + 2*k2 + 2*k3 + k4) / 6;
end
th2s=[th2s,y(2)]
  댓글 수: 6
Lavorizia Vaughn
Lavorizia Vaughn 2021년 11월 13일
the assignment says,"Run Case 1 in problem 2 with the five stepsizes h = 0.05/2(k1), k = 1, 2, 3, 4, and h = 0.001. Compute the value of θ2(t = 100) for each stepsize. '
Jan
Jan 2021년 11월 13일
The instruction is nonsense: For k=1, the value of h = 0.05/2(k-1) is Inf.

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

채택된 답변

Jan
Jan 2021년 11월 13일
hs = [0.05, 0.05/2, 0.05/4, 0.05/8, 1/1000];
for k = 1:numel(hs)
h = hs(k);
N = totalDuration / h; % ???
y = y0;
for i = 1:N
k1 = h * fpend(y);
k2 = h * fpend(y + k1/2);
k3 = h * fpend(y + k2/2);
k4 = h * fpend(y + k3);
y = y + (k1 + 2*k2 + 2*k3 + k4) / 6;
end
th2s(k) = y; % Why y(2)?
end
  댓글 수: 1
Lavorizia Vaughn
Lavorizia Vaughn 2021년 11월 14일
You helped me with the other but very similar thread. thanks a bunch. your help is much appreciated.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by