Series expansion: looping over different inputs
1 回表示 (過去 30 日間)
古いコメントを表示
Say I have the approximation
My question asks that I create two functions to calculate this approximation for an interval of x-values and a given N, using only 1 for loop for one function and 1 while loop for the other The first should loop over the values n = 0, . . . , N whilst the second should loop over the input x-values.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/241539/image.png)
I dont understand the difference in what the question is asking for. Should the first loop be something like
function [x,N]=T(x,N)
....
for i=1:N
....
end
end
Whilst the second as something like
function [x,N]=T(x,N)
....
while x>'something'
....
end
end
or am I meant to seperate the x and N to something like
function x=T(x) N=T(N)
Any help would be really appreciated
0 件のコメント
採用された回答
David Hill
2019 年 10 月 7 日
I think it is asking
T=zeros(1,length(x));
for n=0:N
T=T+(-1)^n*(x.^(2*n+1))/factorial(n);
end
for one of the loops and
t=zeros(1,length(x));
count=1;
n=1:N;
while count<=length(x)
t(count)=sum((-1).^n.*(x(count).^(2*n+1))./factorial(n));
count=count+1;
end
for the other while loop. It tests your understanding of array math manipulations.
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!