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 についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by