You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
how can i calculate the series using the first 10 terms of the sequence
12 views (last 30 days)
Show older comments
how can i calculate the series using the first 10 terms of the sequence
3 Comments
Answers (2)
Ameer Hamza
on 8 Apr 2020
Edited: Ameer Hamza
on 8 Apr 2020
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 Comments
Ameer Hamza
on 8 Apr 2020
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
on 8 Apr 2020
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
on 8 Apr 2020
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
on 8 Apr 2020
"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
on 8 Apr 2020
Can you post it here so that anyone else can also give their input if they want?
R.D
on 8 Apr 2020
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
on 8 Apr 2020
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
on 8 Apr 2020
Edited: Walter Roberson
on 12 Mar 2024
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
on 8 Apr 2020
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
on 8 Apr 2020
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
on 8 Apr 2020
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
on 8 Apr 2020
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
on 8 Apr 2020
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
on 8 Apr 2020
Edited: Ameer Hamza
on 8 Apr 2020
xlabel(), ylabel(), and title() are MATLAB's functions. After running plot() add the line
xlabel('iterations')
ylabel('terms')
title('enter label')
R.D
on 8 Apr 2020
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
on 8 Apr 2020
Undefined function 'label' for input arguments of type 'char'.
Error in testing (line 35)
label('enter label')
R.D
on 10 Apr 2020
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
on 10 Apr 2020
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
on 12 Mar 2024
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.
See Also
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)