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

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

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2015년 9월 20일
편집: Walter Roberson 2015년 9월 20일

0 개 추천

Your
for w = 1:length(x)
Should be
for w = 0 : N

댓글 수: 2

Rob Mullins
Rob Mullins 2015년 9월 20일
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 2015년 9월 20일
Yes you would vectorize the inside for loop.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2015년 9월 20일

댓글:

2015년 9월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by