How to change the previous result ?
1 回表示 (過去 30 日間)
古いコメントを表示
Yamina chbak
2021 年 6 月 12 日
回答済み: Sulaymon Eshkabilov
2021 年 6 月 13 日
Hi, I want to compute the solution :
for n=2,... where
. With the initial solution
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/650955/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/650960/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/650965/image.png)
For example :
if n=2,
then ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/650975/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/650970/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/650975/image.png)
if n=3,
, it's possible to rewrite S as :
where S is the previous result has stored but have to replace
with
, then compute ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/651000/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/650980/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/650985/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/650990/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/650995/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/651000/image.png)
if n=4,
, it's mean
where S is the previous result has to replace
with
and
with
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/651005/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/651010/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/650990/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/650995/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/650995/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/651030/image.png)
and continue .....
Here what i did :
S = 0;
U1 = 5;
k = 0;
for n=2:10
% Compute the sum term
k = k+1;
b = sqrt(n-k+1)-sqrt(n-k);
S = S+b*U1;
% Compute the new solution
U = S+10;
% Overwrite the solution to change the result of the sum S : S = b*U;
% without use the index U(i)
U1 = U;
% but it's not correct
end
What I do ?
0 件のコメント
採用された回答
Sulaymon Eshkabilov
2021 年 6 月 13 日
There was an err inside the loop. Here is the corrected complete and simplified code:
S = 0;
U = 5;
for n=2:10
b = sqrt(n)-sqrt(n-1);
S = S+b*U;
U = S+10;
end
fprintf('Final values: S = %f and U = %f \n', [S, U])
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!