現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)