Series expansion: looping over different inputs

2 次查看(过去 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.
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

采纳的回答

David Hill
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 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by