Series expansion: looping over different inputs

3 views (last 30 days)
jacob Mitch
jacob Mitch on 7 Oct 2019
Answered: David Hill on 7 Oct 2019
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.
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

Accepted Answer

David Hill
David Hill on 7 Oct 2019
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.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by