Series expansion: looping over different inputs

조회 수: 2 (최근 30일)
jacob Mitch
jacob Mitch 2019년 10월 7일
답변: David Hill 2019년 10월 7일
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