Simple Recurrence in Matlab

조회 수: 19 (최근 30일)
Bryce Standkey
Bryce Standkey 2017년 3월 30일
답변: bhavuk seth 2020년 5월 7일
i have a question:
"Write a MATLAB program to compute wn for n = 1, 2, . . . , num where num is entered by the user, and display the values in two columns: n, wn (with appropriate headings)."
The recurrence for this question is W(0) = 25, Wn = W(n-1) +7 -(7*(n+1)/n) n ≥ 2
for the life of me i cant work out how to take this equation on matlab and take a "num" inputed by the user for the value of n
ie) n=1 W(1) = 25 + 7 - 14 = 18
n=2 W(2) = 18 + 7 - 10.5 = 14.5 and so on

채택된 답변

KSSV
KSSV 2017년 3월 30일
N = 100 ;
W = zeros(N,1) ;
W(1) = 25 ;
for n = 2:N
W(n) = W(n-1) +7 -(7*(n+1)/n) ;
end

추가 답변 (2개)

Avag Poghosyan
Avag Poghosyan 2019년 1월 9일
N = 100 ;
W = zeros(N,1) ;
W(1) = 25 ;
for n = 2:N
W(n) = W(n-1) +7 -(7*(n+1)/n) ;
end

bhavuk seth
bhavuk seth 2020년 5월 7일
N = 100 ;
W = zeros(N,1) ;
W(1) = 25 ;
for n = 2:N
W(n) = W(n-1) +7 -(7*(n+1)/n) ;
end

카테고리

Help CenterFile Exchange에서 Programming Utilities에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by