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 (한국어)