Hello everyone!I am trying to create a function that you can put a vector 'x' and a order 'N' to solve for the exp(x). It is close to being correct however i just can't seem to get it.
function [y] = nexp1(x,N)
U = length(x);
for k = 1:U
asum = 0;
for w = 1:length(x)
new = (x(k).^w / factorial(w))
asum = asum + new
end
y(k) = asum
end
end

3 commentaires

Cedric
Cedric le 20 Sep 2015
Were you told to use nested FOR loops?
Rob Mullins
Rob Mullins le 20 Sep 2015
Yes must use nested
Rob Mullins
Rob Mullins le 20 Sep 2015
Well it tells to write a function using nested and then it says do it without nested.

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 20 Sep 2015
Modifié(e) : Walter Roberson le 20 Sep 2015
Your
for w = 1:length(x)
Should be
for w = 0 : N

2 commentaires

Rob Mullins
Rob Mullins le 20 Sep 2015
Awesome thanks! Can you explain on how to do it with only 1 for loop? I assume you would need to vectorize the inside FOR loop?
Walter Roberson
Walter Roberson le 20 Sep 2015
Yes you would vectorize the inside for loop.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by