how to write a program to compute those

1.Write a Matlab program to compute the following:
1.1) B=1+2+3+5+8+13+-------------(stop the program when B>100)
1.2) B=1/1! + 1/2! + 1/3! + 1/5! + 1/8! +----------(stop the program when B>1.67)

댓글 수: 6

ANKUR KUMAR
ANKUR KUMAR 2017년 12월 29일
Come up with some trail codes. We will surely push you to get on the desired result.
Jan
Jan 2017년 12월 29일
There is an infinite number of different sequences starting with: 1,2,3,5,8,13, ... As usual for homework questions: Please post, what you have tried so far and ask a specific question.
Image Analyst
Image Analyst 2017년 12월 29일
And for 1.2, C does not depend on, or change B, so it will never stop.
Roger Stafford
Roger Stafford 2017년 12월 29일
편집: Roger Stafford 2017년 12월 29일
The person devising this homework almost certainly has the Fibonacci numbers in mind but starting with 1 and 2.
Image Analyst
Image Analyst 2017년 12월 29일
OK, I see you changed 1.2 to refer to B now instead of C so now it makes sense to say you want to "stop the program when B>1.67". So how far have you come using the hint I gave you below in the answers section? It should be trivial after that. That was 2 hours ago - you should be done by now.
Rena Berman
Rena Berman 2018년 1월 2일
(Answers Dev) Restored edit

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

답변 (2개)

Image Analyst
Image Analyst 2017년 12월 29일
편집: Image Analyst 2018년 1월 2일

0 개 추천

Regarding:
1.Write a Matlab program to compute the following:
1.1) B=1+2+3+5+8+13+-------------(stop the program when B>100)
1.2) B=1/1! + 1/2! + 1/3! + 1/5! + 1/8! +----------(stop the program when B>1.67)
Hint:
First make the series in an array vec = [1,2,3,4,.....]
vec = [1, 2]
for k = 3 : 10
vec(k) = vec(......
end
Then use cumsum() or a for loop to sum it up.
For 1.2 use factorial and the dot divide operator ./

댓글 수: 2

@Image Analyst: That's the wrong series! It should be the Fibonacci series except that it starts with 1 and 2. Try this for the second question:
F1 = 1; F2 = 2;
B = 1+1/2;
while true
T = F2+F1;
F1 = F2;
F2 = T;
B = B+1/factorial(F2);
if B > 1.67, break, end
end
Image Analyst
Image Analyst 2017년 12월 29일
편집: Image Analyst 2017년 12월 29일
I recognized that but when I was trying to generate the vector [1,2,3,5,8,13,...]
vec = [1, 2]
for k = 3 : 10
vec(k) = vec(k-1) + vec(k-2);
end
vec
We see
vec =
1 2 3 5 8 13 21 34 55 89
Which is exactly the vector I was going for. Now the student merely needs to sum up that vector in a for loop, a while loop, or by using cumsum() to get B.
Don't you agree that this is a reasonable first step? Maybe not the way someone else would approach it but it is one way.
And for the second step (generating factorial terms), don't you think this is a reasonable first step:
vec2 = 1 ./ factorial(vec)
vec2 =
Columns 1 through 8
1 0.5 0.16667 0.0083333 .....
Which is again summed using a for loop, a while loop, or cumsum() depending on how you want to do it. Anyway those were the approached I thought of and I think they will give the correct answer (with a little more code).

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

Nur
Nur 2024년 4월 18일

0 개 추천

댓글 수: 2

Nur
Nur 2024년 4월 18일
this is the [Answers: 1.0323, 1.0323, 0.1180]
Torsten
Torsten 2024년 4월 18일
We invite you to visit MATLAB Onramp to learn the basics of the software in an online course free of costs. It will take approximately 2 hours of your time:

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

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2017년 12월 29일

댓글:

2024년 4월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by