이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
how can i calculate the series using the first 10 terms of the sequence
조회 수: 14 (최근 30일)
이전 댓글 표시
how can i calculate the series using the first 10 terms of the sequence
댓글 수: 3
답변 (2개)
Ameer Hamza
2020년 4월 8일
편집: Ameer Hamza
2020년 4월 8일
try this
term = 0; % initialize variable
% loop 10 times
for n = 0:9
% calculate term
term(n+2) = term(n+1) + (1 / factorial(n));
% display term
fprintf('Term %d = %f\n', n+1, term(n+2));
end
Output
Term 1 = 1.000000
Term 2 = 2.000000
Term 3 = 2.500000
Term 4 = 2.666667
Term 5 = 2.708333
Term 6 = 2.716667
Term 7 = 2.718056
Term 8 = 2.718254
Term 9 = 2.718279
Term 10 = 2.718282
댓글 수: 32
Ameer Hamza
2020년 4월 8일
Your code is correct, but it didn't add the previous terms of the series. I just changed one line
term = term + (1 / factorial(n));
Rest is same as your code.
R.D
2020년 4월 8일
Yes but I have different terms from you
Term 1 = 1.000000
Term 2 = 1.000000
Term 3 = 0.500000
Term 4 = 0.166667
Term 5 = 0.041667
Term 6 = 0.008333
Term 7 = 0.001389
Term 8 = 0.000198
Term 9 = 0.000025
Term 10 = 0.000003
Ameer Hamza
2020년 4월 8일
Yes, I in your code, you only had
term = (1 / factorial(n));
which does not sum the previous terms.
My code have
term = term + (1 / factorial(n));
which sums all previous terms.
Ameer Hamza
2020년 4월 8일
"Better" depends on what you are trying to do. If you are trying to estimate Euler number than my code is better, and if you are just trying to see the term of Taylor series of for x = 0, then your code is better.
Ameer Hamza
2020년 4월 8일
Can you post it here so that anyone else can also give their input if they want?
R.D
2020년 4월 8일
The Euler's number (?) is an important mathematical constant that forms the base of the natural logarithms. This number can be obtained in MATLAB by typing: exp(1), in other words, ? to the power of 1. The exact value of ? can be defined by the infinite series:
? = ∑
1 ?!
∞
?=0
where ?! is the factorial of ?.
You are asked to create a MATLAB M-file named “problem1_XXX.m” (exactly like this, without capital letters or spaces, and substituting XXX by your full student number) that
1. uses a FOR loop to display in the Command Window the first 10 terms in the sequence. Hint: the factorial of ? (or ?!) in MATLAB is obtained by typing factorial(n).
2. calculates the series using the first 10 terms of the sequence.
3. obtains the error of the previous series (in %) with respect to the value of ? that is stored in the memory of MATLAB.
4. creates a plot in which the number of terms that are included in the series appears in the abscissa (?) and the result of the series for the corresponding number of terms appears in the ordinate (?). The line should contain ‘x’ markers to indicate each value of the series.
5. includes in the plot useful labels and a line at ? = ? to represent the value to which the series should converge.
Ameer Hamza
2020년 4월 8일
Romario, since this is a homework question, so I cannot give you a complete solution. The code in your question is for task 1 of your assignment, and code in my answer corresponds to task 2 (I have modified it to save all values inside for-loop). Based on these results, you can try to solve the next task of your assignment.
R.D
2020년 4월 8일
편집: Walter Roberson
2024년 3월 12일
disp('the sum of the first 10 terms is')
disp(term)
%error calculation
ea=abs(term-exp(1))/exp(1)*100;
fprintf(' The error is: %f \n', ea)
THOSE ARE CORRECT ARE THE Q2 AND Q3??
Ameer Hamza
2020년 4월 8일
It is something like this
term = 0; % initialize variable
% loop 10 times
for n = 0:9
% calculate term
term(n+2) = term(n+1) + (1 / factorial(n));
% display term
fprintf('Term %d = %f\n', n+1, term(n+2));
end
plot(0:10, term, '+-')
R.D
2020년 4월 8일
creates a plot in which the number of terms that are included in the series appears in the abscissa (?) and the result of the series for the corresponding number of terms appears in the ordinate (?). The line should contain ‘x’ markers to indicate each value of the series
I think we have to put also the abscissa x ,ordinate y
Ameer Hamza
2020년 4월 8일
In graphs, the term abscissa and ordinate are just other names for the x-axis and y-axis. It says, plot number of terms on the x-axis and the value of term on the y-axis. According to this, it is correct.
R.D
2020년 4월 8일
includes in the plot useful labels and a line at ? = ? to represent the value to which the series should converge.
HOW YOU GONNA SOLVE THE Q5??
Ameer Hamza
2020년 4월 8일
You can use yline: https://www.mathworks.com/help/matlab/ref/yline.html to draw a line at y=e. You can also add xlabel(), ylabel() and title() to your plot.
Ameer Hamza
2020년 4월 8일
편집: Ameer Hamza
2020년 4월 8일
xlabel(), ylabel(), and title() are MATLAB's functions. After running plot() add the line
xlabel('iterations')
ylabel('terms')
title('enter label')
R.D
2020년 4월 8일
Undefined function 'label' for input arguments of type 'char'.
Error in testing (line 35)
label('enter label')
THIS IS WHAT MATLAB APPER ON COMMAND WINDOW
R.D
2020년 4월 8일
Undefined function 'label' for input arguments of type 'char'.
Error in testing (line 35)
label('enter label')
R.D
2020년 4월 10일
Plot all the rain drops on the window when the time is 0 s (i.e. at the start of the journey) using a FOR loop. The plot should be contained exactly in the perimeter of the window and the rain drops should be represented as solid blue lines that connect the corresponding start and end nodes
ANY IDEA HOW TO SOLVE THIS ONE???
Ameer Hamza
2020년 4월 10일
Romario, please start a new question, since it is entirely different from your original question. Also, for such a homework question. It is a better idea to show us some code that you have tried and ask a specific question related to MATLAB.
Clara
2024년 3월 12일
Let x0 be any integer. Suppose that the following rule is used to define a sequence of numbers based on x0.
xk+1 =0.5xk (if xk is even)
or xk+1=3xk+1 (if xk is odd)
Write a MATLAB script to generate the first 10 terms of the sequence.
참고 항목
태그
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)