Series expansion: looping over different inputs
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
jacob Mitch
le 7 Oct 2019
Réponse apportée : David Hill
le 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
0 commentaires
Réponse acceptée
David Hill
le 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.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!